internals.go 18 KB

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