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