Skip to content

Commit 054e57a

Browse files
committed
build: add pull flag to force image pulling
Signed-off-by: Cristian Staretu <[email protected]>
1 parent ce8ebaf commit 054e57a

7 files changed

Lines changed: 18 additions & 0 deletions

File tree

api/client/commands.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
7777
noCache := cmd.Bool([]string{"#no-cache", "-no-cache"}, false, "Do not use cache when building the image")
7878
rm := cmd.Bool([]string{"#rm", "-rm"}, true, "Remove intermediate containers after a successful build")
7979
forceRm := cmd.Bool([]string{"-force-rm"}, false, "Always remove intermediate containers, even after unsuccessful builds")
80+
pull := cmd.Bool([]string{"-pull"}, false, "Always attempt to pull a newer version of the image")
8081
if err := cmd.Parse(args); err != nil {
8182
return nil
8283
}
@@ -213,6 +214,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
213214
v.Set("forcerm", "1")
214215
}
215216

217+
if *pull {
218+
v.Set("pull", "1")
219+
}
216220
cli.LoadConfigFile()
217221

218222
headers := http.Header(make(map[string][]string))

api/server/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,9 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
10161016
} else {
10171017
job.Setenv("rm", r.FormValue("rm"))
10181018
}
1019+
if r.FormValue("pull") == "1" && version.GreaterThanOrEqualTo("1.16") {
1020+
job.Setenv("pull", "1")
1021+
}
10191022
job.Stdin.Add(r.Body)
10201023
job.Setenv("remote", r.FormValue("remote"))
10211024
job.Setenv("t", r.FormValue("t"))

builder/dispatchers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
115115
name := args[0]
116116

117117
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+
}
118124
if err != nil {
119125
if b.Daemon.Graph().IsNotExist(err) {
120126
image, err = b.pullImage(name)

builder/evaluator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type Builder struct {
9090
// controls how images and containers are handled between steps.
9191
Remove bool
9292
ForceRemove bool
93+
Pull bool
9394

9495
AuthConfig *registry.AuthConfig
9596
AuthConfigFile *registry.ConfigFile

builder/job.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
3535
noCache = job.GetenvBool("nocache")
3636
rm = job.GetenvBool("rm")
3737
forceRm = job.GetenvBool("forcerm")
38+
pull = job.GetenvBool("pull")
3839
authConfig = &registry.AuthConfig{}
3940
configFile = &registry.ConfigFile{}
4041
tag string
@@ -111,6 +112,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
111112
UtilizeCache: !noCache,
112113
Remove: rm,
113114
ForceRemove: forceRm,
115+
Pull: pull,
114116
OutOld: job.Stdout,
115117
StreamFormatter: sf,
116118
AuthConfig: authConfig,

docs/sources/reference/api/docker_remote_api_v1.16.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ Query Parameters:
11561156
the resulting image in case of success
11571157
- **q** – suppress verbose build output
11581158
- **nocache** – do not use the cache when building the image
1159+
- **pull** - attempt to pull the image even if an older image exists locally
11591160
- **rm** - remove intermediate containers after a successful build (default behavior)
11601161
- **forcerm - always remove intermediate containers (includes rm)
11611162

docs/sources/reference/commandline/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ To kill the container, use `docker kill`.
312312

313313
--force-rm=false Always remove intermediate containers, even after unsuccessful builds
314314
--no-cache=false Do not use cache when building the image
315+
--pull=false Always attempt to pull a newer version of the image
315316
-q, --quiet=false Suppress the verbose output generated by the containers
316317
--rm=true Remove intermediate containers after a successful build
317318
-t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success

0 commit comments

Comments
 (0)