From 61a7854659cc338f4f519b4fd36d750290d5b69c Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Thu, 25 May 2023 17:54:17 +0100 Subject: [PATCH] tests: add bake test for remote subdir context Fixed in 12b6a3ad9aeda4bdf67a6a55d22fc43594125ec4, but now we have regression tests! So we can add a check that we don't break this behavior again. Signed-off-by: Justin Chadwell --- tests/bake.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/bake.go b/tests/bake.go index facd07e9..62824a6a 100644 --- a/tests/bake.go +++ b/tests/bake.go @@ -22,6 +22,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){ testBakeRemote, testBakeRemoteCmdContext, testBakeRemoteCmdContextOverride, + testBakeRemoteContextSubdir, } func testBakeRemote(t *testing.T, sb integration.Sandbox) { @@ -127,3 +128,37 @@ EOT require.FileExists(t, filepath.Join(dirDest, "foo")) } + +// https://github.com/docker/buildx/issues/1738 +func testBakeRemoteContextSubdir(t *testing.T, sb integration.Sandbox) { + bakefile := []byte(` +target default { + context = "./bar" +} +`) + dockerfile := []byte(` +FROM scratch +COPY super-cool.txt / +`) + + dir := tmpdir( + t, + fstest.CreateFile("docker-bake.hcl", bakefile, 0600), + fstest.CreateDir("bar", 0700), + fstest.CreateFile("bar/Dockerfile", dockerfile, 0600), + fstest.CreateFile("bar/super-cool.txt", []byte("super cool"), 0600), + ) + dirDest := t.TempDir() + + git, err := gitutil.New(gitutil.WithWorkingDir(dir)) + require.NoError(t, err) + gitutil.GitInit(git, t) + gitutil.GitAdd(git, t, "docker-bake.hcl", "bar") + gitutil.GitCommit(git, t, "initial commit") + addr := gitutil.GitServeHTTP(git, t) + + out, err := bakeCmd(sb, "/tmp", addr, "--set", "*.output=type=local,dest="+dirDest) + require.NoError(t, err, out) + + require.FileExists(t, filepath.Join(dirDest, "super-cool.txt")) +}