internals.go 18 KB

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