From 4d9297e3da53f5818a96d741408a93e6119e1a87 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 9 Feb 2021 18:05:13 +0100 Subject: [PATCH] Be sure to copy exact folder structure when generating final images 'COPY *' has a different behavior than 'COPY .' - when regexes are involved, COPY behave differently, by unpacking directory content to the root. Enhance unit test to cover the scenario as well --- pkg/compiler/artifact.go | 2 +- pkg/compiler/artifact_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/artifact.go b/pkg/compiler/artifact.go index 5a087ea1..f1f10194 100644 --- a/pkg/compiler/artifact.go +++ b/pkg/compiler/artifact.go @@ -248,7 +248,7 @@ func (a *PackageArtifact) SetPath(p string) { func (a *PackageArtifact) genDockerfile() string { return ` FROM scratch -COPY * /` +COPY . /` } // CreateArtifactForFile creates a new artifact from the given file diff --git a/pkg/compiler/artifact_test.go b/pkg/compiler/artifact_test.go index 3aad23b4..3d015532 100644 --- a/pkg/compiler/artifact_test.go +++ b/pkg/compiler/artifact_test.go @@ -175,9 +175,14 @@ RUN echo bar > /test2`)) Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpWork) // clean up + Expect(os.MkdirAll(filepath.Join(tmpdir, "foo", "bar"), os.ModePerm)).ToNot(HaveOccurred()) + err = ioutil.WriteFile(filepath.Join(tmpdir, "test"), testString, 0644) Expect(err).ToNot(HaveOccurred()) + err = ioutil.WriteFile(filepath.Join(tmpdir, "foo", "bar", "test"), testString, 0644) + Expect(err).ToNot(HaveOccurred()) + artifact := NewPackageArtifact(filepath.Join(tmpWork, "fake.tar")) artifact.SetCompileSpec(&LuetCompilationSpec{Package: &pkg.DefaultPackage{Name: "foo", Version: "1.0"}}) @@ -201,6 +206,11 @@ RUN echo bar > /test2`)) Expect(err).ToNot(HaveOccurred()) Expect(content).To(Equal(testString)) + + content, err = ioutil.ReadFile(filepath.Join(result, "foo", "bar", "test")) + Expect(err).ToNot(HaveOccurred()) + + Expect(content).To(Equal(testString)) }) It("Generates empty packages images", func() {