internals.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. package dockerfile
  2. // internals for handling commands. Covers many areas and a lot of
  3. // non-contiguous functionality. Please read the comments.
  4. import (
  5. "crypto/sha256"
  6. "encoding/hex"
  7. "errors"
  8. "fmt"
  9. "io"
  10. "io/ioutil"
  11. "net/http"
  12. "net/url"
  13. "os"
  14. "path/filepath"
  15. "sort"
  16. "strings"
  17. "sync"
  18. "time"
  19. "github.com/Sirupsen/logrus"
  20. "github.com/docker/docker/api/types/backend"
  21. "github.com/docker/docker/builder"
  22. "github.com/docker/docker/builder/dockerfile/parser"
  23. "github.com/docker/docker/pkg/archive"
  24. "github.com/docker/docker/pkg/httputils"
  25. "github.com/docker/docker/pkg/ioutils"
  26. "github.com/docker/docker/pkg/jsonmessage"
  27. "github.com/docker/docker/pkg/progress"
  28. "github.com/docker/docker/pkg/streamformatter"
  29. "github.com/docker/docker/pkg/stringid"
  30. "github.com/docker/docker/pkg/system"
  31. "github.com/docker/docker/pkg/tarsum"
  32. "github.com/docker/docker/pkg/urlutil"
  33. "github.com/docker/docker/runconfig/opts"
  34. "github.com/docker/engine-api/types"
  35. "github.com/docker/engine-api/types/container"
  36. "github.com/docker/engine-api/types/strslice"
  37. )
  38. func (b *Builder) commit(id string, autoCmd strslice.StrSlice, comment string) error {
  39. if b.disableCommit {
  40. return nil
  41. }
  42. if b.image == "" && !b.noBaseImage {
  43. return fmt.Errorf("Please provide a source image with `from` prior to commit")
  44. }
  45. b.runConfig.Image = b.image
  46. if id == "" {
  47. cmd := b.runConfig.Cmd
  48. b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), "#(nop) ", comment))
  49. defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
  50. hit, err := b.probeCache()
  51. if err != nil {
  52. return err
  53. } else if hit {
  54. return nil
  55. }
  56. id, err = b.create()
  57. if err != nil {
  58. return err
  59. }
  60. }
  61. // Note: Actually copy the struct
  62. autoConfig := *b.runConfig
  63. autoConfig.Cmd = autoCmd
  64. commitCfg := &backend.ContainerCommitConfig{
  65. ContainerCommitConfig: types.ContainerCommitConfig{
  66. Author: b.maintainer,
  67. Pause: true,
  68. Config: &autoConfig,
  69. },
  70. }
  71. // Commit the container
  72. imageID, err := b.docker.Commit(id, commitCfg)
  73. if err != nil {
  74. return err
  75. }
  76. b.image = imageID
  77. return nil
  78. }
  79. type copyInfo struct {
  80. builder.FileInfo
  81. decompress bool
  82. }
  83. func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalDecompression bool, cmdName string) error {
  84. if b.context == nil {
  85. return fmt.Errorf("No context given. Impossible to use %s", cmdName)
  86. }
  87. if len(args) < 2 {
  88. return fmt.Errorf("Invalid %s format - at least two arguments required", cmdName)
  89. }
  90. // Work in daemon-specific filepath semantics
  91. dest := filepath.FromSlash(args[len(args)-1]) // last one is always the dest
  92. b.runConfig.Image = b.image
  93. var infos []copyInfo
  94. // Loop through each src file and calculate the info we need to
  95. // do the copy (e.g. hash value if cached). Don't actually do
  96. // the copy until we've looked at all src files
  97. var err error
  98. for _, orig := range args[0 : len(args)-1] {
  99. var fi builder.FileInfo
  100. decompress := allowLocalDecompression
  101. if urlutil.IsURL(orig) {
  102. if !allowRemote {
  103. return fmt.Errorf("Source can't be a URL for %s", cmdName)
  104. }
  105. fi, err = b.download(orig)
  106. if err != nil {
  107. return err
  108. }
  109. defer os.RemoveAll(filepath.Dir(fi.Path()))
  110. decompress = false
  111. infos = append(infos, copyInfo{fi, decompress})
  112. continue
  113. }
  114. // not a URL
  115. subInfos, err := b.calcCopyInfo(cmdName, orig, allowLocalDecompression, true)
  116. if err != nil {
  117. return err
  118. }
  119. infos = append(infos, subInfos...)
  120. }
  121. if len(infos) == 0 {
  122. return fmt.Errorf("No source files were specified")
  123. }
  124. if len(infos) > 1 && !strings.HasSuffix(dest, string(os.PathSeparator)) {
  125. return fmt.Errorf("When using %s with more than one source file, the destination must be a directory and end with a /", cmdName)
  126. }
  127. // For backwards compat, if there's just one info then use it as the
  128. // cache look-up string, otherwise hash 'em all into one
  129. var srcHash string
  130. var origPaths string
  131. if len(infos) == 1 {
  132. fi := infos[0].FileInfo
  133. origPaths = fi.Name()
  134. if hfi, ok := fi.(builder.Hashed); ok {
  135. srcHash = hfi.Hash()
  136. }
  137. } else {
  138. var hashs []string
  139. var origs []string
  140. for _, info := range infos {
  141. fi := info.FileInfo
  142. origs = append(origs, fi.Name())
  143. if hfi, ok := fi.(builder.Hashed); ok {
  144. hashs = append(hashs, hfi.Hash())
  145. }
  146. }
  147. hasher := sha256.New()
  148. hasher.Write([]byte(strings.Join(hashs, ",")))
  149. srcHash = "multi:" + hex.EncodeToString(hasher.Sum(nil))
  150. origPaths = strings.Join(origs, " ")
  151. }
  152. cmd := b.runConfig.Cmd
  153. b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), fmt.Sprintf("#(nop) %s %s in %s ", cmdName, srcHash, dest)))
  154. defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
  155. if hit, err := b.probeCache(); err != nil {
  156. return err
  157. } else if hit {
  158. return nil
  159. }
  160. container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}, true)
  161. if err != nil {
  162. return err
  163. }
  164. b.tmpContainers[container.ID] = struct{}{}
  165. comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest)
  166. // Twiddle the destination when its a relative path - meaning, make it
  167. // relative to the WORKINGDIR
  168. if dest, err = normaliseDest(cmdName, b.runConfig.WorkingDir, dest); err != nil {
  169. return err
  170. }
  171. for _, info := range infos {
  172. if err := b.docker.CopyOnBuild(container.ID, dest, info.FileInfo, info.decompress); err != nil {
  173. return err
  174. }
  175. }
  176. return b.commit(container.ID, cmd, comment)
  177. }
  178. func (b *Builder) download(srcURL string) (fi builder.FileInfo, err error) {
  179. // get filename from URL
  180. u, err := url.Parse(srcURL)
  181. if err != nil {
  182. return
  183. }
  184. path := filepath.FromSlash(u.Path) // Ensure in platform semantics
  185. if strings.HasSuffix(path, string(os.PathSeparator)) {
  186. path = path[:len(path)-1]
  187. }
  188. parts := strings.Split(path, string(os.PathSeparator))
  189. filename := parts[len(parts)-1]
  190. if filename == "" {
  191. err = fmt.Errorf("cannot determine filename from url: %s", u)
  192. return
  193. }
  194. // Initiate the download
  195. resp, err := httputils.Download(srcURL)
  196. if err != nil {
  197. return
  198. }
  199. // Prepare file in a tmp dir
  200. tmpDir, err := ioutils.TempDir("", "docker-remote")
  201. if err != nil {
  202. return
  203. }
  204. defer func() {
  205. if err != nil {
  206. os.RemoveAll(tmpDir)
  207. }
  208. }()
  209. tmpFileName := filepath.Join(tmpDir, filename)
  210. tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
  211. if err != nil {
  212. return
  213. }
  214. stdoutFormatter := b.Stdout.(*streamformatter.StdoutFormatter)
  215. progressOutput := stdoutFormatter.StreamFormatter.NewProgressOutput(stdoutFormatter.Writer, true)
  216. progressReader := progress.NewProgressReader(resp.Body, progressOutput, resp.ContentLength, "", "Downloading")
  217. // Download and dump result to tmp file
  218. if _, err = io.Copy(tmpFile, progressReader); err != nil {
  219. tmpFile.Close()
  220. return
  221. }
  222. fmt.Fprintln(b.Stdout)
  223. // ignoring error because the file was already opened successfully
  224. tmpFileSt, err := tmpFile.Stat()
  225. if err != nil {
  226. tmpFile.Close()
  227. return
  228. }
  229. // Set the mtime to the Last-Modified header value if present
  230. // Otherwise just remove atime and mtime
  231. mTime := time.Time{}
  232. lastMod := resp.Header.Get("Last-Modified")
  233. if lastMod != "" {
  234. // If we can't parse it then just let it default to 'zero'
  235. // otherwise use the parsed time value
  236. if parsedMTime, err := http.ParseTime(lastMod); err == nil {
  237. mTime = parsedMTime
  238. }
  239. }
  240. tmpFile.Close()
  241. if err = system.Chtimes(tmpFileName, mTime, mTime); err != nil {
  242. return
  243. }
  244. // Calc the checksum, even if we're using the cache
  245. r, err := archive.Tar(tmpFileName, archive.Uncompressed)
  246. if err != nil {
  247. return
  248. }
  249. tarSum, err := tarsum.NewTarSum(r, true, tarsum.Version1)
  250. if err != nil {
  251. return
  252. }
  253. if _, err = io.Copy(ioutil.Discard, tarSum); err != nil {
  254. return
  255. }
  256. hash := tarSum.Sum(nil)
  257. r.Close()
  258. return &builder.HashedFileInfo{FileInfo: builder.PathFileInfo{FileInfo: tmpFileSt, FilePath: tmpFileName}, FileHash: hash}, nil
  259. }
  260. func (b *Builder) calcCopyInfo(cmdName, origPath string, allowLocalDecompression, allowWildcards bool) ([]copyInfo, error) {
  261. // Work in daemon-specific OS filepath semantics
  262. origPath = filepath.FromSlash(origPath)
  263. if origPath != "" && origPath[0] == os.PathSeparator && len(origPath) > 1 {
  264. origPath = origPath[1:]
  265. }
  266. origPath = strings.TrimPrefix(origPath, "."+string(os.PathSeparator))
  267. // Deal with wildcards
  268. if allowWildcards && containsWildcards(origPath) {
  269. var copyInfos []copyInfo
  270. if err := b.context.Walk("", func(path string, info builder.FileInfo, err error) error {
  271. if err != nil {
  272. return err
  273. }
  274. if info.Name() == "" {
  275. // Why are we doing this check?
  276. return nil
  277. }
  278. if match, _ := filepath.Match(origPath, path); !match {
  279. return nil
  280. }
  281. // Note we set allowWildcards to false in case the name has
  282. // a * in it
  283. subInfos, err := b.calcCopyInfo(cmdName, path, allowLocalDecompression, false)
  284. if err != nil {
  285. return err
  286. }
  287. copyInfos = append(copyInfos, subInfos...)
  288. return nil
  289. }); err != nil {
  290. return nil, err
  291. }
  292. return copyInfos, nil
  293. }
  294. // Must be a dir or a file
  295. statPath, fi, err := b.context.Stat(origPath)
  296. if err != nil {
  297. return nil, err
  298. }
  299. copyInfos := []copyInfo{{FileInfo: fi, decompress: allowLocalDecompression}}
  300. hfi, handleHash := fi.(builder.Hashed)
  301. if !handleHash {
  302. return copyInfos, nil
  303. }
  304. // Deal with the single file case
  305. if !fi.IsDir() {
  306. hfi.SetHash("file:" + hfi.Hash())
  307. return copyInfos, nil
  308. }
  309. // Must be a dir
  310. var subfiles []string
  311. err = b.context.Walk(statPath, func(path string, info builder.FileInfo, err error) error {
  312. if err != nil {
  313. return err
  314. }
  315. // we already checked handleHash above
  316. subfiles = append(subfiles, info.(builder.Hashed).Hash())
  317. return nil
  318. })
  319. if err != nil {
  320. return nil, err
  321. }
  322. sort.Strings(subfiles)
  323. hasher := sha256.New()
  324. hasher.Write([]byte(strings.Join(subfiles, ",")))
  325. hfi.SetHash("dir:" + hex.EncodeToString(hasher.Sum(nil)))
  326. return copyInfos, nil
  327. }
  328. func containsWildcards(name string) bool {
  329. for i := 0; i < len(name); i++ {
  330. ch := name[i]
  331. if ch == '\\' {
  332. i++
  333. } else if ch == '*' || ch == '?' || ch == '[' {
  334. return true
  335. }
  336. }
  337. return false
  338. }
  339. func (b *Builder) processImageFrom(img builder.Image) error {
  340. if img != nil {
  341. b.image = img.ImageID()
  342. if img.RunConfig() != nil {
  343. b.runConfig = img.RunConfig()
  344. }
  345. }
  346. // Check to see if we have a default PATH, note that windows won't
  347. // have one as its set by HCS
  348. if system.DefaultPathEnv != "" {
  349. // Convert the slice of strings that represent the current list
  350. // of env vars into a map so we can see if PATH is already set.
  351. // If its not set then go ahead and give it our default value
  352. configEnv := opts.ConvertKVStringsToMap(b.runConfig.Env)
  353. if _, ok := configEnv["PATH"]; !ok {
  354. b.runConfig.Env = append(b.runConfig.Env,
  355. "PATH="+system.DefaultPathEnv)
  356. }
  357. }
  358. if img == nil {
  359. // Typically this means they used "FROM scratch"
  360. return nil
  361. }
  362. // Process ONBUILD triggers if they exist
  363. if nTriggers := len(b.runConfig.OnBuild); nTriggers != 0 {
  364. word := "trigger"
  365. if nTriggers > 1 {
  366. word = "triggers"
  367. }
  368. fmt.Fprintf(b.Stderr, "# Executing %d build %s...\n", nTriggers, word)
  369. }
  370. // Copy the ONBUILD triggers, and remove them from the config, since the config will be comitted.
  371. onBuildTriggers := b.runConfig.OnBuild
  372. b.runConfig.OnBuild = []string{}
  373. // parse the ONBUILD triggers by invoking the parser
  374. for _, step := range onBuildTriggers {
  375. ast, err := parser.Parse(strings.NewReader(step), &b.directive)
  376. if err != nil {
  377. return err
  378. }
  379. for i, n := range ast.Children {
  380. switch strings.ToUpper(n.Value) {
  381. case "ONBUILD":
  382. return fmt.Errorf("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
  383. case "MAINTAINER", "FROM":
  384. return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", n.Value)
  385. }
  386. if err := b.dispatch(i, n); err != nil {
  387. return err
  388. }
  389. }
  390. }
  391. return nil
  392. }
  393. // probeCache checks if `b.docker` implements builder.ImageCache and image-caching
  394. // is enabled (`b.UseCache`).
  395. // If so attempts to look up the current `b.image` and `b.runConfig` pair with `b.docker`.
  396. // If an image is found, probeCache returns `(true, nil)`.
  397. // If no image is found, it returns `(false, nil)`.
  398. // If there is any error, it returns `(false, err)`.
  399. func (b *Builder) probeCache() (bool, error) {
  400. c, ok := b.docker.(builder.ImageCache)
  401. if !ok || b.options.NoCache || b.cacheBusted {
  402. return false, nil
  403. }
  404. cache, err := c.GetCachedImageOnBuild(b.image, b.runConfig)
  405. if err != nil {
  406. return false, err
  407. }
  408. if len(cache) == 0 {
  409. logrus.Debugf("[BUILDER] Cache miss: %s", b.runConfig.Cmd)
  410. b.cacheBusted = true
  411. return false, nil
  412. }
  413. fmt.Fprintf(b.Stdout, " ---> Using cache\n")
  414. logrus.Debugf("[BUILDER] Use cached version: %s", b.runConfig.Cmd)
  415. b.image = string(cache)
  416. return true, nil
  417. }
  418. func (b *Builder) create() (string, error) {
  419. if b.image == "" && !b.noBaseImage {
  420. return "", fmt.Errorf("Please provide a source image with `from` prior to run")
  421. }
  422. b.runConfig.Image = b.image
  423. resources := container.Resources{
  424. CgroupParent: b.options.CgroupParent,
  425. CPUShares: b.options.CPUShares,
  426. CPUPeriod: b.options.CPUPeriod,
  427. CPUQuota: b.options.CPUQuota,
  428. CpusetCpus: b.options.CPUSetCPUs,
  429. CpusetMems: b.options.CPUSetMems,
  430. Memory: b.options.Memory,
  431. MemorySwap: b.options.MemorySwap,
  432. Ulimits: b.options.Ulimits,
  433. }
  434. // TODO: why not embed a hostconfig in builder?
  435. hostConfig := &container.HostConfig{
  436. Isolation: b.options.Isolation,
  437. ShmSize: b.options.ShmSize,
  438. Resources: resources,
  439. }
  440. config := *b.runConfig
  441. // Create the container
  442. c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
  443. Config: b.runConfig,
  444. HostConfig: hostConfig,
  445. }, true)
  446. if err != nil {
  447. return "", err
  448. }
  449. for _, warning := range c.Warnings {
  450. fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning)
  451. }
  452. b.tmpContainers[c.ID] = struct{}{}
  453. fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID))
  454. // override the entry point that may have been picked up from the base image
  455. if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, config.Cmd); err != nil {
  456. return "", err
  457. }
  458. return c.ID, nil
  459. }
  460. var errCancelled = errors.New("build cancelled")
  461. func (b *Builder) run(cID string) (err error) {
  462. errCh := make(chan error)
  463. go func() {
  464. errCh <- b.docker.ContainerAttachRaw(cID, nil, b.Stdout, b.Stderr, true)
  465. }()
  466. finished := make(chan struct{})
  467. var once sync.Once
  468. finish := func() { close(finished) }
  469. cancelErrCh := make(chan error, 1)
  470. defer once.Do(finish)
  471. go func() {
  472. select {
  473. case <-b.clientCtx.Done():
  474. logrus.Debugln("Build cancelled, killing and removing container:", cID)
  475. b.docker.ContainerKill(cID, 0)
  476. b.removeContainer(cID)
  477. cancelErrCh <- errCancelled
  478. case <-finished:
  479. cancelErrCh <- nil
  480. }
  481. }()
  482. if err := b.docker.ContainerStart(cID, nil, true); err != nil {
  483. return err
  484. }
  485. // Block on reading output from container, stop on err or chan closed
  486. if err := <-errCh; err != nil {
  487. return err
  488. }
  489. if ret, _ := b.docker.ContainerWait(cID, -1); ret != 0 {
  490. // TODO: change error type, because jsonmessage.JSONError assumes HTTP
  491. return &jsonmessage.JSONError{
  492. Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", strings.Join(b.runConfig.Cmd, " "), ret),
  493. Code: ret,
  494. }
  495. }
  496. once.Do(finish)
  497. return <-cancelErrCh
  498. }
  499. func (b *Builder) removeContainer(c string) error {
  500. rmConfig := &types.ContainerRmConfig{
  501. ForceRemove: true,
  502. RemoveVolume: true,
  503. }
  504. if err := b.docker.ContainerRm(c, rmConfig); err != nil {
  505. fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err)
  506. return err
  507. }
  508. return nil
  509. }
  510. func (b *Builder) clearTmp() {
  511. for c := range b.tmpContainers {
  512. if err := b.removeContainer(c); err != nil {
  513. return
  514. }
  515. delete(b.tmpContainers, c)
  516. fmt.Fprintf(b.Stdout, "Removing intermediate container %s\n", stringid.TruncateID(c))
  517. }
  518. }
  519. // readDockerfile reads a Dockerfile from the current context.
  520. func (b *Builder) readDockerfile() error {
  521. // If no -f was specified then look for 'Dockerfile'. If we can't find
  522. // that then look for 'dockerfile'. If neither are found then default
  523. // back to 'Dockerfile' and use that in the error message.
  524. if b.options.Dockerfile == "" {
  525. b.options.Dockerfile = builder.DefaultDockerfileName
  526. if _, _, err := b.context.Stat(b.options.Dockerfile); os.IsNotExist(err) {
  527. lowercase := strings.ToLower(b.options.Dockerfile)
  528. if _, _, err := b.context.Stat(lowercase); err == nil {
  529. b.options.Dockerfile = lowercase
  530. }
  531. }
  532. }
  533. err := b.parseDockerfile()
  534. if err != nil {
  535. return err
  536. }
  537. // After the Dockerfile has been parsed, we need to check the .dockerignore
  538. // file for either "Dockerfile" or ".dockerignore", and if either are
  539. // present then erase them from the build context. These files should never
  540. // have been sent from the client but we did send them to make sure that
  541. // we had the Dockerfile to actually parse, and then we also need the
  542. // .dockerignore file to know whether either file should be removed.
  543. // Note that this assumes the Dockerfile has been read into memory and
  544. // is now safe to be removed.
  545. if dockerIgnore, ok := b.context.(builder.DockerIgnoreContext); ok {
  546. dockerIgnore.Process([]string{b.options.Dockerfile})
  547. }
  548. return nil
  549. }
  550. func (b *Builder) parseDockerfile() error {
  551. f, err := b.context.Open(b.options.Dockerfile)
  552. if err != nil {
  553. if os.IsNotExist(err) {
  554. return fmt.Errorf("Cannot locate specified Dockerfile: %s", b.options.Dockerfile)
  555. }
  556. return err
  557. }
  558. defer f.Close()
  559. if f, ok := f.(*os.File); ok {
  560. // ignoring error because Open already succeeded
  561. fi, err := f.Stat()
  562. if err != nil {
  563. return fmt.Errorf("Unexpected error reading Dockerfile: %v", err)
  564. }
  565. if fi.Size() == 0 {
  566. return fmt.Errorf("The Dockerfile (%s) cannot be empty", b.options.Dockerfile)
  567. }
  568. }
  569. b.dockerfile, err = parser.Parse(f, &b.directive)
  570. if err != nil {
  571. return err
  572. }
  573. return nil
  574. }
  575. // determine if build arg is part of built-in args or user
  576. // defined args in Dockerfile at any point in time.
  577. func (b *Builder) isBuildArgAllowed(arg string) bool {
  578. if _, ok := BuiltinAllowedBuildArgs[arg]; ok {
  579. return true
  580. }
  581. if _, ok := b.allowedBuildArgs[arg]; ok {
  582. return true
  583. }
  584. return false
  585. }