Skip to content

Commit

Permalink
Merge pull request #9854 from glours/fix-docker-default-platform--wit…
Browse files Browse the repository at this point in the history
…hout-build-platform

keep the platform defined via DOCKER_DEFAULT_PLATFORM during build if no build platforms provided
  • Loading branch information
glours authored Sep 20, 2022
2 parents 2977f4c + a1c50ef commit db88241
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ func addPlatforms(project *types.Project, service types.ServiceConfig) ([]specs.
}
// User defined a service platform and no build platforms, so we should keep the one define on the service level
p, err := platforms.Parse(service.Platform)
return append(plats, p), err
if !utils.Contains(plats, p) {
plats = append(plats, p)
}
return plats, err
}

for _, buildPlatform := range service.Build.Platforms {
Expand Down Expand Up @@ -400,7 +403,7 @@ func getImageBuildLabels(project *types.Project, service types.ServiceConfig) ty
func useDockerDefaultPlatform(project *types.Project, platformList types.StringList) ([]specs.Platform, error) {
var plats []specs.Platform
if platform, ok := project.Environment["DOCKER_DEFAULT_PLATFORM"]; ok {
if !utils.StringContains(platformList, platform) {
if len(platformList) > 0 && !utils.StringContains(platformList, platform) {
return nil, fmt.Errorf("the DOCKER_DEFAULT_PLATFORM value should be part of the service.build.platforms: %q", platform)
}
p, err := platforms.Parse(platform)
Expand Down

0 comments on commit db88241

Please sign in to comment.