From ad6ab8aba28327aca485de658b1c3b8ea503a070 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sun, 4 Feb 2018 14:32:40 -0800 Subject: [PATCH] dockerfile: new tests for copy Signed-off-by: Tonis Tiigi --- frontend/dockerfile/dockerfile2llb/convert.go | 2 +- frontend/dockerfile/dockerfile_test.go | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index 559d0aa3..b15ee188 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -378,7 +378,7 @@ func dispatchWorkdir(d *dispatchState, c *instructions.WorkdirCommand, commit bo func dispatchCopy(d *dispatchState, c instructions.SourcesAndDest, sourceState llb.State, isAddCommand bool, cmdToPrint interface{}, chown string) error { // TODO: this should use CopyOp instead. Current implementation is inefficient - img := llb.Image("tonistiigi/copy@sha256:9e6b90a83acc95831c81a0c9c6e45e27b439c19e7974f34f258971e454c8b793") + img := llb.Image("tonistiigi/copy@sha256:476e0a67a1e4650c6adaf213269a2913deb7c52cbc77f954026f769d51e1a14e") dest := path.Join("/dest", pathRelativeToWorkingDir(d.state, c.Dest())) if c.Dest() == "." || c.Dest()[len(c.Dest())-1] == filepath.Separator { diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index 5ed4690a..720e29dd 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -47,6 +47,7 @@ func TestIntegration(t *testing.T) { testDockerfileFromGit, testCopyChown, testCopyWildcards, + testCopyOverrideFiles, }) } @@ -804,6 +805,60 @@ COPY --from=base /out / require.Equal(t, string(dt), "1000 nogroup\n") } +func testCopyOverrideFiles(t *testing.T, sb integration.Sandbox) { + t.Parallel() + + dockerfile := []byte(` +FROM scratch AS base +COPY sub sub +COPY sub sub +COPY files/foo.go dest/foo.go +COPY files/foo.go dest/foo.go +COPY files dest +`) + + dir, err := tmpdir( + fstest.CreateFile("Dockerfile", dockerfile, 0600), + fstest.CreateDir("sub", 0700), + fstest.CreateDir("sub/dir1", 0700), + fstest.CreateDir("sub/dir1/dir2", 0700), + fstest.CreateFile("sub/dir1/dir2/foo", []byte(`foo-contents`), 0600), + fstest.CreateDir("files", 0700), + fstest.CreateFile("files/foo.go", []byte(`foo.go-contents`), 0600), + ) + require.NoError(t, err) + defer os.RemoveAll(dir) + + c, err := client.New(sb.Address()) + require.NoError(t, err) + defer c.Close() + + destDir, err := ioutil.TempDir("", "buildkit") + require.NoError(t, err) + defer os.RemoveAll(destDir) + + err = c.Solve(context.TODO(), nil, client.SolveOpt{ + Frontend: "dockerfile.v0", + Exporter: client.ExporterLocal, + ExporterAttrs: map[string]string{ + "output": destDir, + }, + LocalDirs: map[string]string{ + builder.LocalNameDockerfile: dir, + builder.LocalNameContext: dir, + }, + }, nil) + require.NoError(t, err) + + dt, err := ioutil.ReadFile(filepath.Join(destDir, "sub/dir1/dir2/foo")) + require.NoError(t, err) + require.Equal(t, string(dt), "foo-contents") + + dt, err = ioutil.ReadFile(filepath.Join(destDir, "dest/foo.go")) + require.NoError(t, err) + require.Equal(t, string(dt), "foo.go-contents") +} + func testCopyWildcards(t *testing.T, sb integration.Sandbox) { t.Parallel()