Skip to content

Commit

Permalink
don't apply default pull policy from command line if one is define in…
Browse files Browse the repository at this point in the history
… service configuration

Signed-off-by: Guillaume Lours <[email protected]>
  • Loading branch information
glours committed Aug 4, 2022
1 parent bb04677 commit cd63858
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"time"

"github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra"

"github.com/docker/compose/v2/pkg/api"
"github.com/spf13/cobra"
)

type createOptions struct {
Build bool
noBuild bool
Pull string
pullChanged bool
removeOrphans bool
ignoreOrphans bool
forceRecreate bool
Expand All @@ -47,7 +47,8 @@ func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
cmd := &cobra.Command{
Use: "create [OPTIONS] [SERVICE...]",
Short: "Creates containers for a service.",
PreRunE: Adapt(func(ctx context.Context, args []string) error {
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
opts.pullChanged = cmd.Flags().Changed("pull")
if opts.Build && opts.noBuild {
return fmt.Errorf("--build and --no-build are incompatible")
}
Expand All @@ -57,7 +58,6 @@ func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
return nil
}),
RunE: p.WithProject(func(ctx context.Context, project *types.Project) error {
opts.Apply(project)
return backend.Create(ctx, project, api.CreateOptions{
RemoveOrphans: opts.removeOrphans,
IgnoreOrphans: opts.ignoreOrphans,
Expand Down Expand Up @@ -110,8 +110,10 @@ 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.pullChanged {
service.PullPolicy = opts.Pull
project.Services[i] = service
}
}
}
if opts.Build {
Expand Down

0 comments on commit cd63858

Please sign in to comment.