From 9976077e24fa9eb952e54d31b8738f8839bc8686 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 17 May 2022 16:19:40 +0200 Subject: [PATCH] introduce --pull Signed-off-by: Nicolas De Loof --- cmd/compose/create.go | 8 ++++++++ cmd/compose/up.go | 1 + 2 files changed, 9 insertions(+) diff --git a/cmd/compose/create.go b/cmd/compose/create.go index 7ce8a1853..f697f91f4 100644 --- a/cmd/compose/create.go +++ b/cmd/compose/create.go @@ -30,6 +30,7 @@ import ( type createOptions struct { Build bool noBuild bool + Pull string removeOrphans bool ignoreOrphans bool forceRecreate bool @@ -71,6 +72,7 @@ func createCommand(p *projectOptions, backend api.Service) *cobra.Command { flags := cmd.Flags() flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.") flags.BoolVar(&opts.noBuild, "no-build", false, "Don't build an image, even if it's missing.") + flags.StringVar(&opts.Pull, "pull", "missing", `Pull image before running ("always"|"missing"|"never")`) flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.") flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.") return cmd @@ -105,6 +107,12 @@ func (opts createOptions) GetTimeout() *time.Duration { } func (opts createOptions) Apply(project *types.Project) { + if opts.Pull != "" { + for i, service := range project.Services { + service.PullPolicy = opts.Pull + project.Services[i] = service + } + } if opts.Build { for i, service := range project.Services { if service.Build == nil { diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 145bb7cea..1cdbff924 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -115,6 +115,7 @@ func upCommand(p *projectOptions, backend api.Service) *cobra.Command { flags.BoolVarP(&up.Detach, "detach", "d", false, "Detached mode: Run containers in the background") flags.BoolVar(&create.Build, "build", false, "Build images before starting containers.") flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's missing.") + flags.StringVar(&create.Pull, "pull", "missing", `Pull image before running ("always"|"missing"|"never")`) flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.") flags.StringArrayVar(&up.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.") flags.BoolVar(&up.noColor, "no-color", false, "Produce monochrome output.")