Browse code

Merge pull request #9281 from unclejack/build_pull_flag

build: add pull flag to force image pulling

Michael Crosby authored on 2014/11/25 05:10:45
Showing 7 changed files
... ...
@@ -81,6 +81,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
81 81
 	noCache := cmd.Bool([]string{"#no-cache", "-no-cache"}, false, "Do not use cache when building the image")
82 82
 	rm := cmd.Bool([]string{"#rm", "-rm"}, true, "Remove intermediate containers after a successful build")
83 83
 	forceRm := cmd.Bool([]string{"-force-rm"}, false, "Always remove intermediate containers, even after unsuccessful builds")
84
+	pull := cmd.Bool([]string{"-pull"}, false, "Always attempt to pull a newer version of the image")
84 85
 	if err := cmd.Parse(args); err != nil {
85 86
 		return nil
86 87
 	}
... ...
@@ -217,6 +218,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
217 217
 		v.Set("forcerm", "1")
218 218
 	}
219 219
 
220
+	if *pull {
221
+		v.Set("pull", "1")
222
+	}
220 223
 	cli.LoadConfigFile()
221 224
 
222 225
 	headers := http.Header(make(map[string][]string))
... ...
@@ -1016,6 +1016,9 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
1016 1016
 	} else {
1017 1017
 		job.Setenv("rm", r.FormValue("rm"))
1018 1018
 	}
1019
+	if r.FormValue("pull") == "1" && version.GreaterThanOrEqualTo("1.16") {
1020
+		job.Setenv("pull", "1")
1021
+	}
1019 1022
 	job.Stdin.Add(r.Body)
1020 1023
 	job.Setenv("remote", r.FormValue("remote"))
1021 1024
 	job.Setenv("t", r.FormValue("t"))
... ...
@@ -115,6 +115,12 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
115 115
 	name := args[0]
116 116
 
117 117
 	image, err := b.Daemon.Repositories().LookupImage(name)
118
+	if b.Pull {
119
+		image, err = b.pullImage(name)
120
+		if err != nil {
121
+			return err
122
+		}
123
+	}
118 124
 	if err != nil {
119 125
 		if b.Daemon.Graph().IsNotExist(err) {
120 126
 			image, err = b.pullImage(name)
... ...
@@ -90,6 +90,7 @@ type Builder struct {
90 90
 	// controls how images and containers are handled between steps.
91 91
 	Remove      bool
92 92
 	ForceRemove bool
93
+	Pull        bool
93 94
 
94 95
 	AuthConfig     *registry.AuthConfig
95 96
 	AuthConfigFile *registry.ConfigFile
... ...
@@ -35,6 +35,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
35 35
 		noCache        = job.GetenvBool("nocache")
36 36
 		rm             = job.GetenvBool("rm")
37 37
 		forceRm        = job.GetenvBool("forcerm")
38
+		pull           = job.GetenvBool("pull")
38 39
 		authConfig     = &registry.AuthConfig{}
39 40
 		configFile     = &registry.ConfigFile{}
40 41
 		tag            string
... ...
@@ -111,6 +112,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
111 111
 		UtilizeCache:    !noCache,
112 112
 		Remove:          rm,
113 113
 		ForceRemove:     forceRm,
114
+		Pull:            pull,
114 115
 		OutOld:          job.Stdout,
115 116
 		StreamFormatter: sf,
116 117
 		AuthConfig:      authConfig,
... ...
@@ -1156,6 +1156,7 @@ Query Parameters:
1156 1156
         the resulting image in case of success
1157 1157
 -   **q** – suppress verbose build output
1158 1158
 -   **nocache** – do not use the cache when building the image
1159
+-   **pull** - attempt to pull the image even if an older image exists locally
1159 1160
 -   **rm** - remove intermediate containers after a successful build (default behavior)
1160 1161
 -   **forcerm - always remove intermediate containers (includes rm)
1161 1162
 
... ...
@@ -315,6 +315,7 @@ To kill the container, use `docker kill`.
315 315
 
316 316
       --force-rm=false     Always remove intermediate containers, even after unsuccessful builds
317 317
       --no-cache=false     Do not use cache when building the image
318
+      --pull=false         Always attempt to pull a newer version of the image
318 319
       -q, --quiet=false    Suppress the verbose output generated by the containers
319 320
       --rm=true            Remove intermediate containers after a successful build
320 321
       -t, --tag=""         Repository name (and optionally a tag) to be applied to the resulting image in case of success