Skip to content

Commit c1ce53c

Browse files
committed
fix regression running pull --ignore-pull-failures
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent e42673d commit c1ce53c

File tree

8 files changed

+48
-9
lines changed

8 files changed

+48
-9
lines changed

pkg/compose/pull.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, optio
4747
})
4848
}
4949

50-
func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error {
50+
func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { //nolint:gocyclo
5151
info, err := s.apiClient().Info(ctx)
5252
if err != nil {
5353
return err
@@ -117,12 +117,12 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
117117
_, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false, project.Environment["DOCKER_DEFAULT_PLATFORM"])
118118
if err != nil {
119119
pullErrors[i] = err
120-
if !opts.IgnoreFailures {
121-
if service.Build != nil {
122-
mustBuild = append(mustBuild, service.Name)
123-
} else {
124-
return err // fail fast if image can't be pulled nor built
125-
}
120+
if service.Build != nil {
121+
mustBuild = append(mustBuild, service.Name)
122+
}
123+
if !opts.IgnoreFailures && service.Build == nil {
124+
// fail fast if image can't be pulled nor built
125+
return err
126126
}
127127
}
128128
return nil
@@ -131,14 +131,16 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
131131

132132
err = eg.Wait()
133133

134-
if !opts.IgnoreFailures && len(mustBuild) > 0 {
134+
if len(mustBuild) > 0 {
135135
w.TailMsgf("WARNING: Some service image(s) must be built from source by running:\n docker compose build %s", strings.Join(mustBuild, " "))
136136
}
137137

138138
if err != nil {
139139
return err
140140
}
141-
141+
if opts.IgnoreFailures {
142+
return nil
143+
}
142144
return multierror.Append(nil, pullErrors...).ErrorOrNil()
143145
}
144146

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM alpine:3.15
16+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
fail:
3+
image: does_not_exists
4+
can_build:
5+
image: doesn_t_exists_either
6+
build: .
7+
valid:
8+
image: alpine:3.15
9+

pkg/e2e/pull_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"gotest.tools/v3/assert"
24+
"gotest.tools/v3/icmd"
2425
)
2526

2627
func TestComposePull(t *testing.T) {
@@ -78,4 +79,15 @@ func TestComposePull(t *testing.T) {
7879

7980
assert.Assert(t, strings.Contains(output, "Skipped - No image to be pulled"))
8081
})
82+
83+
t.Run("Verify pull failure", func(t *testing.T) {
84+
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull")
85+
res.Assert(t, icmd.Expected{ExitCode: 18, Err: "pull access denied for does_not_exists"})
86+
})
87+
88+
t.Run("Verify ignore pull failure", func(t *testing.T) {
89+
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull", "--ignore-pull-failures")
90+
res.Assert(t, icmd.Expected{Err: "Some service image(s) must be built from source by running:"})
91+
})
92+
8193
}

0 commit comments

Comments
 (0)