瀏覽代碼

fix regression running pull --ignore-pull-failures

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 2 年之前
父節點
當前提交
c1ce53c972

+ 11 - 9
pkg/compose/pull.go

@@ -47,7 +47,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, optio
 	})
 	})
 }
 }
 
 
-func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error {
+func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { //nolint:gocyclo
 	info, err := s.apiClient().Info(ctx)
 	info, err := s.apiClient().Info(ctx)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
@@ -117,12 +117,12 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
 			_, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false, project.Environment["DOCKER_DEFAULT_PLATFORM"])
 			_, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false, project.Environment["DOCKER_DEFAULT_PLATFORM"])
 			if err != nil {
 			if err != nil {
 				pullErrors[i] = err
 				pullErrors[i] = err
-				if !opts.IgnoreFailures {
-					if service.Build != nil {
-						mustBuild = append(mustBuild, service.Name)
-					} else {
-						return err // fail fast if image can't be pulled nor built
-					}
+				if service.Build != nil {
+					mustBuild = append(mustBuild, service.Name)
+				}
+				if !opts.IgnoreFailures && service.Build == nil {
+					// fail fast if image can't be pulled nor built
+					return err
 				}
 				}
 			}
 			}
 			return nil
 			return nil
@@ -131,14 +131,16 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
 
 
 	err = eg.Wait()
 	err = eg.Wait()
 
 
-	if !opts.IgnoreFailures && len(mustBuild) > 0 {
+	if len(mustBuild) > 0 {
 		w.TailMsgf("WARNING: Some service image(s) must be built from source by running:\n    docker compose build %s", strings.Join(mustBuild, " "))
 		w.TailMsgf("WARNING: Some service image(s) must be built from source by running:\n    docker compose build %s", strings.Join(mustBuild, " "))
 	}
 	}
 
 
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-
+	if opts.IgnoreFailures {
+		return nil
+	}
 	return multierror.Append(nil, pullErrors...).ErrorOrNil()
 	return multierror.Append(nil, pullErrors...).ErrorOrNil()
 }
 }
 
 

+ 0 - 0
pkg/e2e/fixtures/compose-pull/duplicate-images/docker-compose.yaml → pkg/e2e/fixtures/compose-pull/duplicate-images/compose.yaml


+ 0 - 0
pkg/e2e/fixtures/compose-pull/image-present-locally/docker-compose.yaml → pkg/e2e/fixtures/compose-pull/image-present-locally/compose.yaml


+ 0 - 0
pkg/e2e/fixtures/compose-pull/no-image-name-given/docker-compose.yaml → pkg/e2e/fixtures/compose-pull/no-image-name-given/compose.yaml


+ 0 - 0
pkg/e2e/fixtures/compose-pull/simple/docker-compose.yaml → pkg/e2e/fixtures/compose-pull/simple/compose.yaml


+ 16 - 0
pkg/e2e/fixtures/compose-pull/unknown-image/Dockerfile

@@ -0,0 +1,16 @@
+#   Copyright 2020 Docker Compose CLI authors
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+
+#       http://www.apache.org/licenses/LICENSE-2.0
+
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+FROM alpine:3.15
+

+ 9 - 0
pkg/e2e/fixtures/compose-pull/unknown-image/compose.yaml

@@ -0,0 +1,9 @@
+services:
+  fail:
+    image: does_not_exists
+  can_build:
+    image: doesn_t_exists_either
+    build: .
+  valid:
+    image: alpine:3.15
+

+ 12 - 0
pkg/e2e/pull_test.go

@@ -21,6 +21,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/assert"
+	"gotest.tools/v3/icmd"
 )
 )
 
 
 func TestComposePull(t *testing.T) {
 func TestComposePull(t *testing.T) {
@@ -78,4 +79,15 @@ func TestComposePull(t *testing.T) {
 
 
 		assert.Assert(t, strings.Contains(output, "Skipped - No image to be pulled"))
 		assert.Assert(t, strings.Contains(output, "Skipped - No image to be pulled"))
 	})
 	})
+
+	t.Run("Verify pull failure", func(t *testing.T) {
+		res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull")
+		res.Assert(t, icmd.Expected{ExitCode: 18, Err: "pull access denied for does_not_exists"})
+	})
+
+	t.Run("Verify ignore pull failure", func(t *testing.T) {
+		res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull", "--ignore-pull-failures")
+		res.Assert(t, icmd.Expected{Err: "Some service image(s) must be built from source by running:"})
+	})
+
 }
 }