build: add pull flag to force image pulling

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
This commit is contained in:
unclejack 2014-11-21 19:51:32 +02:00
Родитель ce8ebaf0e0
Коммит 054e57a622
7 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -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") 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") 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") 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 { if err := cmd.Parse(args); err != nil {
return nil return nil
} }
@ -213,6 +214,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
v.Set("forcerm", "1") v.Set("forcerm", "1")
} }
if *pull {
v.Set("pull", "1")
}
cli.LoadConfigFile() cli.LoadConfigFile()
headers := http.Header(make(map[string][]string)) headers := http.Header(make(map[string][]string))

Просмотреть файл

@ -1016,6 +1016,9 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
} else { } else {
job.Setenv("rm", r.FormValue("rm")) 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.Stdin.Add(r.Body)
job.Setenv("remote", r.FormValue("remote")) job.Setenv("remote", r.FormValue("remote"))
job.Setenv("t", r.FormValue("t")) job.Setenv("t", r.FormValue("t"))

Просмотреть файл

@ -115,6 +115,12 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
name := args[0] name := args[0]
image, err := b.Daemon.Repositories().LookupImage(name) image, err := b.Daemon.Repositories().LookupImage(name)
if b.Pull {
image, err = b.pullImage(name)
if err != nil {
return err
}
}
if err != nil { if err != nil {
if b.Daemon.Graph().IsNotExist(err) { if b.Daemon.Graph().IsNotExist(err) {
image, err = b.pullImage(name) image, err = b.pullImage(name)

Просмотреть файл

@ -90,6 +90,7 @@ type Builder struct {
// controls how images and containers are handled between steps. // controls how images and containers are handled between steps.
Remove bool Remove bool
ForceRemove bool ForceRemove bool
Pull bool
AuthConfig *registry.AuthConfig AuthConfig *registry.AuthConfig
AuthConfigFile *registry.ConfigFile AuthConfigFile *registry.ConfigFile

Просмотреть файл

@ -35,6 +35,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
noCache = job.GetenvBool("nocache") noCache = job.GetenvBool("nocache")
rm = job.GetenvBool("rm") rm = job.GetenvBool("rm")
forceRm = job.GetenvBool("forcerm") forceRm = job.GetenvBool("forcerm")
pull = job.GetenvBool("pull")
authConfig = &registry.AuthConfig{} authConfig = &registry.AuthConfig{}
configFile = &registry.ConfigFile{} configFile = &registry.ConfigFile{}
tag string tag string
@ -111,6 +112,7 @@ func (b *BuilderJob) CmdBuild(job *engine.Job) engine.Status {
UtilizeCache: !noCache, UtilizeCache: !noCache,
Remove: rm, Remove: rm,
ForceRemove: forceRm, ForceRemove: forceRm,
Pull: pull,
OutOld: job.Stdout, OutOld: job.Stdout,
StreamFormatter: sf, StreamFormatter: sf,
AuthConfig: authConfig, AuthConfig: authConfig,

Просмотреть файл

@ -1156,6 +1156,7 @@ Query Parameters:
the resulting image in case of success the resulting image in case of success
- **q** – suppress verbose build output - **q** – suppress verbose build output
- **nocache** – do not use the cache when building the image - **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) - **rm** - remove intermediate containers after a successful build (default behavior)
- **forcerm - always remove intermediate containers (includes rm) - **forcerm - always remove intermediate containers (includes rm)

Просмотреть файл

@ -312,6 +312,7 @@ To kill the container, use `docker kill`.
--force-rm=false Always remove intermediate containers, even after unsuccessful builds --force-rm=false Always remove intermediate containers, even after unsuccessful builds
--no-cache=false Do not use cache when building the image --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 -q, --quiet=false Suppress the verbose output generated by the containers
--rm=true Remove intermediate containers after a successful build --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 -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success