internals.go 18 KB

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