Skip to content

Commit

Permalink
check that the pull policy provided is a valid one
Browse files Browse the repository at this point in the history
or is not missing when --pull is used

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
  • Loading branch information
glours authored and ndeloof committed Oct 18, 2023
1 parent af87f10 commit b929810
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/compose/create.go
Expand Up @@ -19,6 +19,7 @@ package compose
import (
"context"
"fmt"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -138,6 +139,9 @@ func (opts createOptions) GetTimeout() *time.Duration {

func (opts createOptions) Apply(project *types.Project) error {
if opts.pullChanged {
if !opts.isPullPolicyValid() {
return fmt.Errorf("invalid --pull option %q", opts.Pull)
}
for i, service := range project.Services {
service.PullPolicy = opts.Pull
project.Services[i] = service
Expand Down Expand Up @@ -187,3 +191,9 @@ func (opts createOptions) Apply(project *types.Project) error {
}
return nil
}

func (opts createOptions) isPullPolicyValid() bool {
pullPolicies := []string{types.PullPolicyAlways, types.PullPolicyNever, types.PullPolicyBuild,
types.PullPolicyMissing, types.PullPolicyIfNotPresent}
return slices.Contains(pullPolicies, opts.Pull)
}

0 comments on commit b929810

Please sign in to comment.