From 054e57a622e6a065c343806e7334920d17a03c5b Mon Sep 17 00:00:00 2001 From: unclejack Date: Fri, 21 Nov 2014 19:51:32 +0200 Subject: [PATCH] build: add pull flag to force image pulling Signed-off-by: Cristian Staretu --- api/client/commands.go | 4 ++++ api/server/server.go | 3 +++ builder/dispatchers.go | 6 ++++++ builder/evaluator.go | 1 + builder/job.go | 2 ++ docs/sources/reference/api/docker_remote_api_v1.16.md | 1 + docs/sources/reference/commandline/cli.md | 1 + 7 files changed, 18 insertions(+) diff --git a/api/client/commands.go b/api/client/commands.go index d0a0792399..f0e8d834a6 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -77,6 +77,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { noCache := cmd.Bool([]string{"#no-cache", "-no-cache"}, false, "Do not use cache when building the image") rm := cmd.Bool([]string{"#rm", "-rm"}, true, "Remove intermediate containers after a successful build") forceRm := cmd.Bool([]string{"-force-rm"}, false, "Always remove intermediate containers, even after unsuccessful builds") + pull := cmd.Bool([]string{"-pull"}, false, "Always attempt to pull a newer version of the image") if err := cmd.Parse(args); err != nil { return nil } @@ -213,6 +214,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error { v.Set("forcerm", "1") } + if *pull { + v.Set("pull", "1") + } cli.LoadConfigFile() headers := http.Header(make(map[string][]string)) diff --git a/api/server/server.go b/api/server/server.go index d9b73e6798..b3cf0603bb 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -1016,6 +1016,9 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite } else { job.Setenv("rm", r.FormValue("rm")) } + if r.FormValue("pull") == "1" && version.GreaterThanOrEqualTo("1.16") { + job.Setenv("pull", "1") + } job.Stdin.Add(r.Body) job.Setenv("remote", r.FormValue("remote")) job.Setenv("t", r.FormValue("t")) diff --git a/builder/dispatchers.go b/builder/dispatchers.go index 99be480f73..db7476c5ed 100644 --- a/builder/dispatchers.go +++ b/builder/dispatchers.go @@ -115,6 +115,12 @@ func from(b *Builder, args []string, attributes map[string]bool, original string name := args[0] image, err := b.Daemon.Repositories().LookupImage(name) + if b.Pull { + image, err = b.pullImage(name) + if err != nil { + return err + } + } if err != nil { if b.Daemon.Graph().IsNotExist(err) { image, err = b.pullImage(name) diff --git a/builder/evaluator.go b/builder/evaluator.go index 645038bb1d..3d9ebb162c 100644 --- a/builder/evaluator.go +++ b/builder/evaluator.go @@ -90,6 +90,7 @@ type Builder struct { // controls how images and containers are handled between steps. Remove bool ForceRemove bool + Pull bool AuthConfig *registry.AuthConfig AuthConfigFile *registry.ConfigFile diff --git a/builder/job.go b/builder/job.go index c86ccb0e3c..1d10e8eb34 100644 --- a/builder/job.go +++ b/builder/job.go @@ -35,6 +35,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status { noCache = job.GetenvBool("nocache") rm = job.GetenvBool("rm") forceRm = job.GetenvBool("forcerm") + pull = job.GetenvBool("pull") authConfig = ®istry.AuthConfig{} configFile = ®istry.ConfigFile{} tag string @@ -111,6 +112,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status { UtilizeCache: !noCache, Remove: rm, ForceRemove: forceRm, + Pull: pull, OutOld: job.Stdout, StreamFormatter: sf, AuthConfig: authConfig, diff --git a/docs/sources/reference/api/docker_remote_api_v1.16.md b/docs/sources/reference/api/docker_remote_api_v1.16.md index e643d1a5c7..a1d3fa5dfe 100644 --- a/docs/sources/reference/api/docker_remote_api_v1.16.md +++ b/docs/sources/reference/api/docker_remote_api_v1.16.md @@ -1156,6 +1156,7 @@ Query Parameters: the resulting image in case of success - **q** – suppress verbose build output - **nocache** – do not use the cache when building the image +- **pull** - attempt to pull the image even if an older image exists locally - **rm** - remove intermediate containers after a successful build (default behavior) - **forcerm - always remove intermediate containers (includes rm) diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index ff13d6222c..504fc0fbac 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -312,6 +312,7 @@ To kill the container, use `docker kill`. --force-rm=false Always remove intermediate containers, even after unsuccessful builds --no-cache=false Do not use cache when building the image + --pull=false Always attempt to pull a newer version of the image -q, --quiet=false Suppress the verbose output generated by the containers --rm=true Remove intermediate containers after a successful build -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success