From c1ce53c9724fbb27c3d64348e56b0d9c0dbecd93 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 19 Dec 2022 10:17:38 +0100 Subject: [PATCH] fix regression running pull --ignore-pull-failures Signed-off-by: Nicolas De Loof --- pkg/compose/pull.go | 20 ++++++++++--------- .../{docker-compose.yaml => compose.yaml} | 0 .../{docker-compose.yaml => compose.yaml} | 0 .../{docker-compose.yaml => compose.yaml} | 0 .../{docker-compose.yaml => compose.yaml} | 0 .../compose-pull/unknown-image/Dockerfile | 16 +++++++++++++++ .../compose-pull/unknown-image/compose.yaml | 9 +++++++++ pkg/e2e/pull_test.go | 12 +++++++++++ 8 files changed, 48 insertions(+), 9 deletions(-) rename pkg/e2e/fixtures/compose-pull/duplicate-images/{docker-compose.yaml => compose.yaml} (100%) rename pkg/e2e/fixtures/compose-pull/image-present-locally/{docker-compose.yaml => compose.yaml} (100%) rename pkg/e2e/fixtures/compose-pull/no-image-name-given/{docker-compose.yaml => compose.yaml} (100%) rename pkg/e2e/fixtures/compose-pull/simple/{docker-compose.yaml => compose.yaml} (100%) create mode 100644 pkg/e2e/fixtures/compose-pull/unknown-image/Dockerfile create mode 100644 pkg/e2e/fixtures/compose-pull/unknown-image/compose.yaml diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index 6a32a5468..be2747966 100644 --- a/pkg/compose/pull.go +++ b/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) if err != nil { 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"]) if err != nil { 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 @@ -131,14 +131,16 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts 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, " ")) } if err != nil { return err } - + if opts.IgnoreFailures { + return nil + } return multierror.Append(nil, pullErrors...).ErrorOrNil() } diff --git a/pkg/e2e/fixtures/compose-pull/duplicate-images/docker-compose.yaml b/pkg/e2e/fixtures/compose-pull/duplicate-images/compose.yaml similarity index 100% rename from pkg/e2e/fixtures/compose-pull/duplicate-images/docker-compose.yaml rename to pkg/e2e/fixtures/compose-pull/duplicate-images/compose.yaml diff --git a/pkg/e2e/fixtures/compose-pull/image-present-locally/docker-compose.yaml b/pkg/e2e/fixtures/compose-pull/image-present-locally/compose.yaml similarity index 100% rename from pkg/e2e/fixtures/compose-pull/image-present-locally/docker-compose.yaml rename to pkg/e2e/fixtures/compose-pull/image-present-locally/compose.yaml diff --git a/pkg/e2e/fixtures/compose-pull/no-image-name-given/docker-compose.yaml b/pkg/e2e/fixtures/compose-pull/no-image-name-given/compose.yaml similarity index 100% rename from pkg/e2e/fixtures/compose-pull/no-image-name-given/docker-compose.yaml rename to pkg/e2e/fixtures/compose-pull/no-image-name-given/compose.yaml diff --git a/pkg/e2e/fixtures/compose-pull/simple/docker-compose.yaml b/pkg/e2e/fixtures/compose-pull/simple/compose.yaml similarity index 100% rename from pkg/e2e/fixtures/compose-pull/simple/docker-compose.yaml rename to pkg/e2e/fixtures/compose-pull/simple/compose.yaml diff --git a/pkg/e2e/fixtures/compose-pull/unknown-image/Dockerfile b/pkg/e2e/fixtures/compose-pull/unknown-image/Dockerfile new file mode 100644 index 000000000..fd3bd1dc7 --- /dev/null +++ b/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 + diff --git a/pkg/e2e/fixtures/compose-pull/unknown-image/compose.yaml b/pkg/e2e/fixtures/compose-pull/unknown-image/compose.yaml new file mode 100644 index 000000000..de40d09c4 --- /dev/null +++ b/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 + diff --git a/pkg/e2e/pull_test.go b/pkg/e2e/pull_test.go index 6d7637351..dc7545f61 100644 --- a/pkg/e2e/pull_test.go +++ b/pkg/e2e/pull_test.go @@ -21,6 +21,7 @@ import ( "testing" "gotest.tools/v3/assert" + "gotest.tools/v3/icmd" ) 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")) }) + + 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:"}) + }) + }