mirror of https://github.com/docker/buildx.git
tests: build multiplatform
Signed-off-by: idnandre <andre@idntimes.com>
This commit is contained in:
parent
56cb197c0a
commit
56df4e98a0
|
@ -56,6 +56,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){
|
||||||
testListVariables,
|
testListVariables,
|
||||||
testBakeCallCheck,
|
testBakeCallCheck,
|
||||||
testBakeCallCheckFlag,
|
testBakeCallCheckFlag,
|
||||||
|
testBakeMultiPlatform,
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBakePrint(t *testing.T, sb integration.Sandbox) {
|
func testBakePrint(t *testing.T, sb integration.Sandbox) {
|
||||||
|
@ -887,6 +888,56 @@ target "def" {
|
||||||
require.Len(t, md.BuildWarnings, 3, string(dt))
|
require.Len(t, md.BuildWarnings, 3, string(dt))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testBakeMultiPlatform(t *testing.T, sb integration.Sandbox) {
|
||||||
|
registry, err := sb.NewRegistry()
|
||||||
|
if errors.Is(err, integration.ErrRequirements) {
|
||||||
|
t.Skip(err.Error())
|
||||||
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
|
target := registry + "/buildx/registry:latest"
|
||||||
|
|
||||||
|
dockerfile := []byte(`
|
||||||
|
FROM --platform=$BUILDPLATFORM busybox:latest AS base
|
||||||
|
COPY foo /etc/foo
|
||||||
|
RUN cp /etc/foo /etc/bar
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=base /etc/bar /bar
|
||||||
|
`)
|
||||||
|
bakefile := []byte(`
|
||||||
|
target "default" {
|
||||||
|
platforms = ["linux/amd64", "linux/arm64"]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
dir := tmpdir(
|
||||||
|
t,
|
||||||
|
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
||||||
|
fstest.CreateFile("Dockerfile", dockerfile, 0600),
|
||||||
|
fstest.CreateFile("foo", []byte("foo"), 0600),
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd := buildxCmd(sb, withDir(dir), withArgs("bake"), withArgs("--set", fmt.Sprintf("*.output=type=image,name=%s,push=true", target)))
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
if !isMobyWorker(sb) {
|
||||||
|
require.NoError(t, err, string(out))
|
||||||
|
|
||||||
|
desc, provider, err := contentutil.ProviderFromRef(target)
|
||||||
|
require.NoError(t, err)
|
||||||
|
imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
img := imgs.Find("linux/amd64")
|
||||||
|
require.NotNil(t, img)
|
||||||
|
img = imgs.Find("linux/arm64")
|
||||||
|
require.NotNil(t, img)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
require.Error(t, err, string(out))
|
||||||
|
require.Contains(t, string(out), "Multi-platform build is not supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testBakeMultiExporters(t *testing.T, sb integration.Sandbox) {
|
func testBakeMultiExporters(t *testing.T, sb integration.Sandbox) {
|
||||||
if !isDockerContainerWorker(sb) {
|
if !isDockerContainerWorker(sb) {
|
||||||
t.Skip("only testing with docker-container worker")
|
t.Skip("only testing with docker-container worker")
|
||||||
|
|
|
@ -62,7 +62,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
|
||||||
testBuildLabelNoKey,
|
testBuildLabelNoKey,
|
||||||
testBuildCacheExportNotSupported,
|
testBuildCacheExportNotSupported,
|
||||||
testBuildOCIExportNotSupported,
|
testBuildOCIExportNotSupported,
|
||||||
testBuildMultiPlatformNotSupported,
|
testBuildMultiPlatform,
|
||||||
testDockerHostGateway,
|
testDockerHostGateway,
|
||||||
testBuildNetworkModeBridge,
|
testBuildNetworkModeBridge,
|
||||||
testBuildShmSize,
|
testBuildShmSize,
|
||||||
|
@ -616,16 +616,47 @@ func testBuildOCIExportNotSupported(t *testing.T, sb integration.Sandbox) {
|
||||||
require.Contains(t, string(out), "OCI exporter is not supported")
|
require.Contains(t, string(out), "OCI exporter is not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBuildMultiPlatformNotSupported(t *testing.T, sb integration.Sandbox) {
|
func testBuildMultiPlatform(t *testing.T, sb integration.Sandbox) {
|
||||||
if !isMobyWorker(sb) {
|
dockerfile := []byte(`
|
||||||
t.Skip("only testing with docker worker")
|
FROM --platform=$BUILDPLATFORM busybox:latest AS base
|
||||||
}
|
COPY foo /etc/foo
|
||||||
|
RUN cp /etc/foo /etc/bar
|
||||||
|
|
||||||
dir := createTestProject(t)
|
FROM scratch
|
||||||
cmd := buildxCmd(sb, withArgs("build", "--platform=linux/amd64,linux/arm64", dir))
|
COPY --from=base /etc/bar /bar
|
||||||
|
`)
|
||||||
|
dir := tmpdir(
|
||||||
|
t,
|
||||||
|
fstest.CreateFile("Dockerfile", dockerfile, 0600),
|
||||||
|
fstest.CreateFile("foo", []byte("foo"), 0600),
|
||||||
|
)
|
||||||
|
registry, err := sb.NewRegistry()
|
||||||
|
if errors.Is(err, integration.ErrRequirements) {
|
||||||
|
t.Skip(err.Error())
|
||||||
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
|
target := registry + "/buildx/registry:latest"
|
||||||
|
|
||||||
|
cmd := buildxCmd(sb, withArgs("build", "--platform=linux/amd64,linux/arm64", fmt.Sprintf("--output=type=image,name=%s,push=true", target), dir))
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
require.Error(t, err, string(out))
|
|
||||||
require.Contains(t, string(out), "Multi-platform build is not supported")
|
if !isMobyWorker(sb) {
|
||||||
|
require.NoError(t, err, string(out))
|
||||||
|
|
||||||
|
desc, provider, err := contentutil.ProviderFromRef(target)
|
||||||
|
require.NoError(t, err)
|
||||||
|
imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
img := imgs.Find("linux/amd64")
|
||||||
|
require.NotNil(t, img)
|
||||||
|
img = imgs.Find("linux/arm64")
|
||||||
|
require.NotNil(t, img)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
require.Error(t, err, string(out))
|
||||||
|
require.Contains(t, string(out), "Multi-platform build is not supported")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDockerHostGateway(t *testing.T, sb integration.Sandbox) {
|
func testDockerHostGateway(t *testing.T, sb integration.Sandbox) {
|
||||||
|
|
Loading…
Reference in New Issue