diff --git a/pkg/compiler/artifact_test.go b/pkg/compiler/artifact_test.go index e8eb1377..a8b871a5 100644 --- a/pkg/compiler/artifact_test.go +++ b/pkg/compiler/artifact_test.go @@ -96,6 +96,7 @@ ENV PACKAGE_CATEGORY=app-admin`)) Expect(err).ToNot(HaveOccurred()) Expect(dockerfile).To(Equal(` FROM luet/base +COPY . /luetbuild WORKDIR /luetbuild ENV PACKAGE_NAME=enman ENV PACKAGE_VERSION=1.4.0 diff --git a/pkg/compiler/backend/simpledocker_test.go b/pkg/compiler/backend/simpledocker_test.go index 8732caf3..8a49a835 100644 --- a/pkg/compiler/backend/simpledocker_test.go +++ b/pkg/compiler/backend/simpledocker_test.go @@ -87,6 +87,7 @@ ENV PACKAGE_CATEGORY=app-admin`)) Expect(err).ToNot(HaveOccurred()) Expect(dockerfile).To(Equal(` FROM luet/base +COPY . /luetbuild WORKDIR /luetbuild ENV PACKAGE_NAME=enman ENV PACKAGE_VERSION=1.4.0 diff --git a/pkg/compiler/spec.go b/pkg/compiler/spec.go index 4b3d5fe4..2ad2a645 100644 --- a/pkg/compiler/spec.go +++ b/pkg/compiler/spec.go @@ -203,10 +203,9 @@ func (cs *LuetCompilationSpec) CopyRetrieves(dest string) error { 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) RenderBuildImage() (string, error) { +func (cs *LuetCompilationSpec) genDockerfile(image string, steps []string) string { spec := ` -FROM ` + cs.GetSeedImage() + ` +FROM ` + image + ` COPY . /luetbuild WORKDIR /luetbuild ENV PACKAGE_NAME=` + cs.Package.GetName() + ` @@ -231,45 +230,23 @@ ADD ` + s + ` /luetbuild/` ENV ` + s } - for _, s := range cs.GetPreBuildSteps() { + for _, s := range steps { spec = spec + ` 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 func (cs *LuetCompilationSpec) RenderStepImage(image string) (string, error) { - spec := ` -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 + return cs.genDockerfile(image, cs.BuildSteps()), nil } func (cs *LuetCompilationSpec) WriteBuildImageDefinition(path string) error { diff --git a/pkg/compiler/spec_test.go b/pkg/compiler/spec_test.go index 4233ba59..88e0c989 100644 --- a/pkg/compiler/spec_test.go +++ b/pkg/compiler/spec_test.go @@ -96,6 +96,7 @@ ENV test=1`)) Expect(err).ToNot(HaveOccurred()) Expect(dockerfile).To(Equal(` FROM luet/base +COPY . /luetbuild WORKDIR /luetbuild ENV PACKAGE_NAME=enman ENV PACKAGE_VERSION=1.4.0 @@ -169,6 +170,7 @@ ENV test=1`)) Expect(dockerfile).To(Equal(` FROM luet/base +COPY . /luetbuild WORKDIR /luetbuild ENV PACKAGE_NAME=a ENV PACKAGE_VERSION=1.0