mirror of https://github.com/docker/compose.git
keep the platform defined at service level during build if no build platforms provided
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
c4d79e60b6
commit
0e975262da
|
@ -363,8 +363,13 @@ func addPlatforms(project *types.Project, service types.ServiceConfig) ([]specs.
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Platform != "" && !utils.StringContains(service.Build.Platforms, service.Platform) {
|
if service.Platform != "" && !utils.StringContains(service.Build.Platforms, service.Platform) {
|
||||||
|
if len(service.Build.Platforms) > 0 {
|
||||||
return nil, fmt.Errorf("service.platform should be part of the service.build.platforms: %q", service.Platform)
|
return nil, fmt.Errorf("service.platform should be part of the service.build.platforms: %q", service.Platform)
|
||||||
}
|
}
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
for _, buildPlatform := range service.Build.Platforms {
|
for _, buildPlatform := range service.Build.Platforms {
|
||||||
p, err := platforms.Parse(buildPlatform)
|
p, err := platforms.Parse(buildPlatform)
|
||||||
|
|
|
@ -314,6 +314,14 @@ func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) {
|
||||||
res.Assert(t, icmd.Expected{Out: "I am building for linux/amd64"})
|
res.Assert(t, icmd.Expected{Out: "I am building for linux/amd64"})
|
||||||
assert.Assert(t, !strings.Contains(res.Stdout(), "I am building for linux/arm64"))
|
assert.Assert(t, !strings.Contains(res.Stdout(), "I am building for linux/arm64"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("use service platform value when no build platforms defined ", func(t *testing.T) {
|
||||||
|
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms",
|
||||||
|
"-f", "fixtures/build-test/platforms/compose-service-platform-and-no-build-platforms.yaml", "build")
|
||||||
|
assert.NilError(t, res.Error, res.Stderr())
|
||||||
|
res.Assert(t, icmd.Expected{Out: "I am building for linux/386"})
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildPlatformsStandardErrors(t *testing.T) {
|
func TestBuildPlatformsStandardErrors(t *testing.T) {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
services:
|
||||||
|
platforms:
|
||||||
|
image: build-test-platform:test
|
||||||
|
platform: linux/386
|
||||||
|
build:
|
||||||
|
context: .
|
Loading…
Reference in New Issue