mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
add more information when service.platform isn't part of service.build.platforms
Signed-off-by: Bartłomiej Klimczak <bartlomiej.klimczak88@gmail.com>
This commit is contained in:
parent
3c641ed265
commit
0d0a02cc6b
@ -368,6 +368,18 @@ func addPlatforms(project *types.Project, service types.ServiceConfig) ([]specs.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if service.Platform != "" && !utils.StringContains(service.Build.Platforms, service.Platform) {
|
||||||
|
if len(service.Build.Platforms) > 0 {
|
||||||
|
return nil, fmt.Errorf("service.platform %q should be part of the service.build.platforms: %q", service.Platform, service.Build.Platforms)
|
||||||
|
}
|
||||||
|
// 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)
|
||||||
|
if !utils.Contains(plats, p) {
|
||||||
|
plats = append(plats, p)
|
||||||
|
}
|
||||||
|
return plats, err
|
||||||
|
}
|
||||||
|
|
||||||
for _, buildPlatform := range service.Build.Platforms {
|
for _, buildPlatform := range service.Build.Platforms {
|
||||||
p, err := platforms.Parse(buildPlatform)
|
p, err := platforms.Parse(buildPlatform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -398,7 +410,7 @@ func useDockerDefaultPlatform(project *types.Project, platformList types.StringL
|
|||||||
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 len(platformList) > 0 && !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 %q value should be part of the service.build.platforms: %q", platform, platformList)
|
||||||
}
|
}
|
||||||
p, err := platforms.Parse(platform)
|
p, err := platforms.Parse(platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -417,7 +429,7 @@ func useDockerDefaultOrServicePlatform(project *types.Project, service types.Ser
|
|||||||
|
|
||||||
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 {
|
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 %q should be part of the service.build.platforms: %q", service.Platform, service.Build.Platforms)
|
||||||
}
|
}
|
||||||
// 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)
|
||||||
|
@ -366,7 +366,7 @@ func TestBuildPlatformsStandardErrors(t *testing.T) {
|
|||||||
"-f", "fixtures/build-test/platforms/compose-service-platform-not-in-build-platforms.yaml", "build")
|
"-f", "fixtures/build-test/platforms/compose-service-platform-not-in-build-platforms.yaml", "build")
|
||||||
res.Assert(t, icmd.Expected{
|
res.Assert(t, icmd.Expected{
|
||||||
ExitCode: 1,
|
ExitCode: 1,
|
||||||
Err: `service.platform should be part of the service.build.platforms: "linux/riscv64"`,
|
Err: `service.platform "linux/riscv64" should be part of the service.build.platforms: ["linux/amd64" "linux/arm64"]`,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ func TestBuildPlatformsStandardErrors(t *testing.T) {
|
|||||||
})
|
})
|
||||||
res.Assert(t, icmd.Expected{
|
res.Assert(t, icmd.Expected{
|
||||||
ExitCode: 1,
|
ExitCode: 1,
|
||||||
Err: `DOCKER_DEFAULT_PLATFORM value should be part of the service.build.platforms: "windows/amd64"`,
|
Err: `DOCKER_DEFAULT_PLATFORM "windows/amd64" value should be part of the service.build.platforms: ["linux/amd64" "linux/arm64"]`,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user