mirror of https://github.com/docker/compose.git
fix regression running pull --ignore-pull-failures
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
e42673daed
commit
c1ce53c972
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
fail:
|
||||
image: does_not_exists
|
||||
can_build:
|
||||
image: doesn_t_exists_either
|
||||
build: .
|
||||
valid:
|
||||
image: alpine:3.15
|
||||
|
|
@ -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:"})
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue