From 7c5675c30631178c4955856fb9ce6eecc0898525 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Wed, 16 Nov 2022 13:51:44 +0100 Subject: [PATCH] use platform defined by DOCKER_DEFAULT_PLATFORM when pulling and no service platform defined Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/compose/pull.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index d3b794c6e..80bb3b8ac 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -110,7 +110,7 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts imagesBeingPulled[service.Image] = service.Name eg.Go(func() error { - _, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false) + _, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false, project.Environment["DOCKER_DEFAULT_PLATFORM"]) if err != nil { if !opts.IgnoreFailures { if service.Build != nil { @@ -146,7 +146,8 @@ func imageAlreadyPresent(serviceImage string, localImages map[string]string) boo return ok && tagged.Tag() != "latest" } -func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) (string, error) { +func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, + configFile driver.Auth, w progress.Writer, quietPull bool, defaultPlatform string) (string, error) { w.Event(progress.Event{ ID: service.Name, Status: progress.Working, @@ -176,10 +177,14 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser if err != nil { return "", err } + platform := service.Platform + if platform == "" { + platform = defaultPlatform + } stream, err := s.apiClient().ImagePull(ctx, service.Image, moby.ImagePullOptions{ RegistryAuth: base64.URLEncoding.EncodeToString(buf), - Platform: service.Platform, + Platform: platform, }) // check if has error and the service has a build section @@ -269,7 +274,7 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types. for i, service := range needPull { i, service := i, service eg.Go(func() error { - id, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull) + id, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull, project.Environment["DOCKER_DEFAULT_PLATFORM"]) pulledImages[i] = id if err != nil && isServiceImageToBuild(service, project.Services) { // image can be built, so we can ignore pull failure