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
This commit is contained in:
Ettore Di Giacinto 2021-02-09 18:05:13 +01:00
parent 544895e051
commit 4d9297e3da
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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() {