Skip to content

Commit

Permalink
Don't stop pull for images that can be built
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 8, 2022
1 parent c342891 commit 0234e13
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
"github.com/hashicorp/go-multierror"
"golang.org/x/sync/errgroup"

"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -65,12 +66,14 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
eg, ctx := errgroup.WithContext(ctx)
eg.SetLimit(s.maxConcurrency)

var mustBuild []string

imagesBeingPulled := map[string]string{}
var (
mustBuild []string
pullErrors = make([]error, len(project.Services))
imagesBeingPulled = map[string]string{}
)

for _, service := range project.Services {
service := service
for i, service := range project.Services {
i, service := i, service
if service.Image == "" {
w.Event(progress.Event{
ID: service.Name,
Expand Down Expand Up @@ -113,13 +116,14 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
eg.Go(func() error {
_, 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
}
return err
}
w.TailMsgf("Pulling %s: %s", service.Name, err.Error())
}
return nil
})
Expand All @@ -131,7 +135,11 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
w.TailMsgf("WARNING: Some service image(s) must be built from source by running:\n docker compose build %s", strings.Join(mustBuild, " "))
}

return err
if err != nil {
return err
}

return multierror.Append(nil, pullErrors...).ErrorOrNil()
}

func imageAlreadyPresent(serviceImage string, localImages map[string]string) bool {
Expand Down

0 comments on commit 0234e13

Please sign in to comment.