Reuse same dockerfile gen logic between prelude and steps

As now we build only when necessary, we need to make sure the images are
built similarly. The discrepancies between the two are less now, and
they can share the same logic.

This fixes a regresion where when no prelude is defined, the build
context isn't copied over
This commit is contained in:
Ettore Di Giacinto
2020-12-12 11:16:34 +01:00
parent fdba8dea71
commit 797a34ba49
4 changed files with 16 additions and 35 deletions

View File

@@ -96,6 +96,7 @@ ENV PACKAGE_CATEGORY=app-admin`))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(dockerfile).To(Equal(` Expect(dockerfile).To(Equal(`
FROM luet/base FROM luet/base
COPY . /luetbuild
WORKDIR /luetbuild WORKDIR /luetbuild
ENV PACKAGE_NAME=enman ENV PACKAGE_NAME=enman
ENV PACKAGE_VERSION=1.4.0 ENV PACKAGE_VERSION=1.4.0

View File

@@ -87,6 +87,7 @@ ENV PACKAGE_CATEGORY=app-admin`))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(dockerfile).To(Equal(` Expect(dockerfile).To(Equal(`
FROM luet/base FROM luet/base
COPY . /luetbuild
WORKDIR /luetbuild WORKDIR /luetbuild
ENV PACKAGE_NAME=enman ENV PACKAGE_NAME=enman
ENV PACKAGE_VERSION=1.4.0 ENV PACKAGE_VERSION=1.4.0

View File

@@ -203,10 +203,9 @@ func (cs *LuetCompilationSpec) CopyRetrieves(dest string) error {
return err return err
} }
// TODO: docker build image first. Then a backend can be used to actually spin up a container with it and run the steps within func (cs *LuetCompilationSpec) genDockerfile(image string, steps []string) string {
func (cs *LuetCompilationSpec) RenderBuildImage() (string, error) {
spec := ` spec := `
FROM ` + cs.GetSeedImage() + ` FROM ` + image + `
COPY . /luetbuild COPY . /luetbuild
WORKDIR /luetbuild WORKDIR /luetbuild
ENV PACKAGE_NAME=` + cs.Package.GetName() + ` ENV PACKAGE_NAME=` + cs.Package.GetName() + `
@@ -231,45 +230,23 @@ ADD ` + s + ` /luetbuild/`
ENV ` + s ENV ` + s
} }
for _, s := range cs.GetPreBuildSteps() { for _, s := range steps {
spec = spec + ` spec = spec + `
RUN ` + s RUN ` + s
} }
return spec, nil return spec
}
// TODO: docker build image first. Then a backend can be used to actually spin up a container with it and run the steps within
func (cs *LuetCompilationSpec) RenderBuildImage() (string, error) {
return cs.genDockerfile(cs.GetSeedImage(), cs.GetPreBuildSteps()), nil
} }
// TODO: docker build image first. Then a backend can be used to actually spin up a container with it and run the steps within // TODO: docker build image first. Then a backend can be used to actually spin up a container with it and run the steps within
func (cs *LuetCompilationSpec) RenderStepImage(image string) (string, error) { func (cs *LuetCompilationSpec) RenderStepImage(image string) (string, error) {
spec := ` return cs.genDockerfile(image, cs.BuildSteps()), nil
FROM ` + image + `
WORKDIR /luetbuild
ENV PACKAGE_NAME=` + cs.Package.GetName() + `
ENV PACKAGE_VERSION=` + cs.Package.GetVersion() + `
ENV PACKAGE_CATEGORY=` + cs.Package.GetCategory()
if len(cs.Retrieve) > 0 {
for _, s := range cs.Retrieve {
//var file string
// if helpers.IsValidUrl(s) {
// file = s
// } else {
// file = cs.Rel(s)
// }
spec = spec + `
ADD ` + s + ` /luetbuild/`
}
}
for _, s := range cs.Env {
spec = spec + `
ENV ` + s
}
for _, s := range cs.BuildSteps() {
spec = spec + `
RUN ` + s
}
return spec, nil
} }
func (cs *LuetCompilationSpec) WriteBuildImageDefinition(path string) error { func (cs *LuetCompilationSpec) WriteBuildImageDefinition(path string) error {

View File

@@ -96,6 +96,7 @@ ENV test=1`))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(dockerfile).To(Equal(` Expect(dockerfile).To(Equal(`
FROM luet/base FROM luet/base
COPY . /luetbuild
WORKDIR /luetbuild WORKDIR /luetbuild
ENV PACKAGE_NAME=enman ENV PACKAGE_NAME=enman
ENV PACKAGE_VERSION=1.4.0 ENV PACKAGE_VERSION=1.4.0
@@ -169,6 +170,7 @@ ENV test=1`))
Expect(dockerfile).To(Equal(` Expect(dockerfile).To(Equal(`
FROM luet/base FROM luet/base
COPY . /luetbuild
WORKDIR /luetbuild WORKDIR /luetbuild
ENV PACKAGE_NAME=a ENV PACKAGE_NAME=a
ENV PACKAGE_VERSION=1.0 ENV PACKAGE_VERSION=1.0