Merge pull request #9854 from glours/fix-docker-default-platform--without-build-platform

keep the platform defined via DOCKER_DEFAULT_PLATFORM during build if no build platforms provided
This commit is contained in:
Guillaume Lours 2022-09-20 10:00:10 +02:00 committed by GitHub
commit db88241698
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

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