package tests import ( "os" "path/filepath" "testing" "github.com/containerd/continuity/fs/fstest" "github.com/docker/buildx/util/gitutil" "github.com/moby/buildkit/util/testutil/integration" "github.com/stretchr/testify/require" ) func bakeCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) { opts = append([]cmdOpt{withArgs("bake", "--progress=quiet")}, opts...) cmd := buildxCmd(sb, opts...) out, err := cmd.CombinedOutput() return string(out), err } var bakeTests = []func(t *testing.T, sb integration.Sandbox){ testBakeLocal, testBakeLocalMulti, testBakeRemote, testBakeRemoteCmdContext, testBakeRemoteLocalOverride, testBakeRemoteCmdContextOverride, testBakeRemoteContextSubdir, testBakeRemoteCmdContextEscapeRoot, testBakeRemoteCmdContextEscapeRelative, testBakeRemoteDockerfileCwd, testBakeRemoteLocalContextRemoteDockerfile, testBakeEmpty, } func testBakeLocal(t *testing.T, sb integration.Sandbox) { dockerfile := []byte(` FROM scratch COPY foo /foo `) bakefile := []byte(` target "default" { } `) dir := tmpdir( t, fstest.CreateFile("docker-bake.hcl", bakefile, 0600), fstest.CreateFile("Dockerfile", dockerfile, 0600), fstest.CreateFile("foo", []byte("foo"), 0600), ) dirDest := t.TempDir() cmd := buildxCmd(sb, withDir(dir), withArgs("bake", "--progress=plain", "--set", "*.output=type=local,dest="+dirDest)) out, err := cmd.CombinedOutput() require.NoError(t, err, out) require.Contains(t, string(out), `#1 [internal] load local bake definitions`) require.Contains(t, string(out), `#1 reading docker-bake.hcl`) require.FileExists(t, filepath.Join(dirDest, "foo")) } func testBakeLocalMulti(t *testing.T, sb integration.Sandbox) { dockerfile := []byte(` FROM scratch COPY foo /foo `) bakefile := []byte(` target "default" { } `) composefile := []byte(` services: app: build: {} `) dir := tmpdir( t, fstest.CreateFile("docker-bake.hcl", bakefile, 0600), fstest.CreateFile("compose.yaml", composefile, 0600), fstest.CreateFile("Dockerfile", dockerfile, 0600), fstest.CreateFile("foo", []byte("foo"), 0600), ) dirDest := t.TempDir() cmd := buildxCmd(sb, withDir(dir), withArgs("bake", "--progress=plain", "--set", "*.output=type=local,dest="+dirDest)) dt, err := cmd.CombinedOutput() require.NoError(t, err, string(dt)) require.Contains(t, string(dt), `#1 [internal] load local bake definitions`) require.Contains(t, string(dt), `#1 reading compose.yaml`) require.Contains(t, string(dt), `#1 reading docker-bake.hcl`) require.FileExists(t, filepath.Join(dirDest, "foo")) dirDest2 := t.TempDir() out, err := bakeCmd(sb, withDir(dir), withArgs("--file", "cwd://docker-bake.hcl", "--set", "*.output=type=local,dest="+dirDest2)) require.NoError(t, err, out) require.FileExists(t, filepath.Join(dirDest2, "foo")) } func testBakeRemote(t *testing.T, sb integration.Sandbox) { bakefile := []byte(` target "default" { dockerfile-inline = <