Skip to content

Commit

Permalink
Merge pull request #9999 from glours/pull-use-default-platform
Browse files Browse the repository at this point in the history
use platform defined by DOCKER_DEFAULT_PLATFORM when pulling and no service platform defined
  • Loading branch information
glours committed Nov 18, 2022
2 parents 88c3aaf + 7c5675c commit 481ae0a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 481ae0a

Please sign in to comment.