(t *testing.T)
| 395 | } |
| 396 | |
| 397 | func TestBuildPlatformsStandardErrors(t *testing.T) { |
| 398 | c := NewParallelCLI(t) |
| 399 | |
| 400 | t.Run("no platform support with Classic Builder", func(t *testing.T) { |
| 401 | cmd := c.NewDockerComposeCmd(t, "--project-directory", "fixtures/build-test/platforms", "build") |
| 402 | |
| 403 | res := icmd.RunCmd(cmd, func(cmd *icmd.Cmd) { |
| 404 | cmd.Env = append(cmd.Env, "DOCKER_BUILDKIT=0") |
| 405 | }) |
| 406 | res.Assert(t, icmd.Expected{ |
| 407 | ExitCode: 1, |
| 408 | Err: "the classic builder doesn't support multi-arch build, set DOCKER_BUILDKIT=1 to use BuildKit", |
| 409 | }) |
| 410 | }) |
| 411 | |
| 412 | t.Run("builder does not support multi-arch", func(t *testing.T) { |
| 413 | // Docker Desktop with containerd image store uses the docker driver |
| 414 | // but supports multi-platform builds, so this error won't occur. |
| 415 | inspect := c.RunDockerCmd(t, "buildx", "inspect", "--bootstrap") |
| 416 | output := inspect.Stdout() |
| 417 | isDockerDriver := false |
| 418 | platforms := "" |
| 419 | for line := range strings.SplitSeq(output, "\n") { |
| 420 | trimmed := strings.TrimSpace(line) |
| 421 | if after, ok := strings.CutPrefix(trimmed, "Driver:"); ok { |
| 422 | isDockerDriver = strings.TrimSpace(after) == "docker" |
| 423 | } |
| 424 | if strings.HasPrefix(trimmed, "Platforms:") { |
| 425 | platforms = trimmed |
| 426 | } |
| 427 | } |
| 428 | if isDockerDriver && strings.Contains(platforms, "linux/amd64") && strings.Contains(platforms, "linux/arm64") { |
| 429 | t.Skip("docker driver supports multi-platform (containerd image store enabled)") |
| 430 | } |
| 431 | |
| 432 | res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "build") |
| 433 | res.Assert(t, icmd.Expected{ |
| 434 | ExitCode: 1, |
| 435 | Err: "Multi-platform build is not supported for the docker driver.", |
| 436 | }) |
| 437 | }) |
| 438 | |
| 439 | t.Run("service platform not defined in platforms build section", func(t *testing.T) { |
| 440 | res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", |
| 441 | "-f", "fixtures/build-test/platforms/compose-service-platform-not-in-build-platforms.yaml", "build") |
| 442 | res.Assert(t, icmd.Expected{ |
| 443 | ExitCode: 1, |
| 444 | Err: `service.build.platforms MUST include service.platform "linux/riscv64"`, |
| 445 | }) |
| 446 | }) |
| 447 | |
| 448 | t.Run("DOCKER_DEFAULT_PLATFORM value not defined in platforms build section", func(t *testing.T) { |
| 449 | cmd := c.NewDockerComposeCmd(t, "--project-directory", "fixtures/build-test/platforms", "build") |
| 450 | res := icmd.RunCmd(cmd, func(cmd *icmd.Cmd) { |
| 451 | cmd.Env = append(cmd.Env, "DOCKER_DEFAULT_PLATFORM=windows/amd64") |
| 452 | }) |
| 453 | res.Assert(t, icmd.Expected{ |
| 454 | ExitCode: 1, |
nothing calls this directly
no test coverage detected