Skip to content

Commit b929810

Browse files
gloursndeloof
authored andcommitted
check that the pull policy provided is a valid one
or is not missing when --pull is used Signed-off-by: Guillaume Lours <[email protected]>
1 parent af87f10 commit b929810

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cmd/compose/create.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"slices"
2223
"strconv"
2324
"strings"
2425
"time"
@@ -138,6 +139,9 @@ func (opts createOptions) GetTimeout() *time.Duration {
138139

139140
func (opts createOptions) Apply(project *types.Project) error {
140141
if opts.pullChanged {
142+
if !opts.isPullPolicyValid() {
143+
return fmt.Errorf("invalid --pull option %q", opts.Pull)
144+
}
141145
for i, service := range project.Services {
142146
service.PullPolicy = opts.Pull
143147
project.Services[i] = service
@@ -187,3 +191,9 @@ func (opts createOptions) Apply(project *types.Project) error {
187191
}
188192
return nil
189193
}
194+
195+
func (opts createOptions) isPullPolicyValid() bool {
196+
pullPolicies := []string{types.PullPolicyAlways, types.PullPolicyNever, types.PullPolicyBuild,
197+
types.PullPolicyMissing, types.PullPolicyIfNotPresent}
198+
return slices.Contains(pullPolicies, opts.Pull)
199+
}

0 commit comments

Comments
 (0)