From a1c50ef2c987d4709865aa02c237f45b08c529e2 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Fri, 16 Sep 2022 22:19:31 +0200 Subject: [PATCH] keep the platform defined via DOCKER_DEFAULT_PLATFORM during build if no build platforms provided Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/compose/build.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/compose/build.go b/pkg/compose/build.go index 36f6ee5e8..ca94bc55c 100644 --- a/pkg/compose/build.go +++ b/pkg/compose/build.go @@ -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 { @@ -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)