Skip to content

Commit

Permalink
fix regression running pull --ignore-pull-failures
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Dec 19, 2022
1 parent e42673d commit 49f5a4d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/e2e/fixtures/compose-pull/unknown-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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
8 changes: 8 additions & 0 deletions pkg/e2e/fixtures/compose-pull/unknown-image/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
fail:
image: does_not_exists
can_build:
image: doesn_t_exists_either
build: .
valid:
image: alpine:3.15
12 changes: 12 additions & 0 deletions pkg/e2e/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
)

func TestComposePull(t *testing.T) {
Expand Down Expand Up @@ -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:"})
})

}

0 comments on commit 49f5a4d

Please sign in to comment.