mirror of
https://github.com/mudler/luet.git
synced 2025-08-11 20:21:44 +00:00
Add Environment to compilespec #24
Now compilespecs can define envs and have PACKAGE_NAME, PACKAGE_VERSION and PACKAGE_CATEGORY injected
This commit is contained in:
parent
55fa7265e5
commit
ebf818ff08
@ -21,6 +21,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
//"strconv"
|
//"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -75,6 +75,9 @@ var _ = Describe("Artifact", func() {
|
|||||||
FROM alpine
|
FROM alpine
|
||||||
COPY . /luetbuild
|
COPY . /luetbuild
|
||||||
WORKDIR /luetbuild
|
WORKDIR /luetbuild
|
||||||
|
ENV PACKAGE_NAME=enman
|
||||||
|
ENV PACKAGE_VERSION=1.4.0
|
||||||
|
ENV PACKAGE_CATEGORY=app-admin
|
||||||
`))
|
`))
|
||||||
b := NewSimpleDockerBackend()
|
b := NewSimpleDockerBackend()
|
||||||
opts := CompilerBackendOptions{
|
opts := CompilerBackendOptions{
|
||||||
@ -93,6 +96,9 @@ WORKDIR /luetbuild
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(dockerfile).To(Equal(`
|
Expect(dockerfile).To(Equal(`
|
||||||
FROM luet/base
|
FROM luet/base
|
||||||
|
ENV PACKAGE_NAME=enman
|
||||||
|
ENV PACKAGE_VERSION=1.4.0
|
||||||
|
ENV PACKAGE_CATEGORY=app-admin
|
||||||
RUN echo foo > /test
|
RUN echo foo > /test
|
||||||
RUN echo bar > /test2`))
|
RUN echo bar > /test2`))
|
||||||
opts = CompilerBackendOptions{
|
opts = CompilerBackendOptions{
|
||||||
|
@ -88,6 +88,7 @@ func (specs *LuetCompilationspecs) Unique() CompilationSpecs {
|
|||||||
|
|
||||||
type LuetCompilationSpec struct {
|
type LuetCompilationSpec struct {
|
||||||
Steps []string `json:"steps"` // Are run inside a container and the result layer diff is saved
|
Steps []string `json:"steps"` // Are run inside a container and the result layer diff is saved
|
||||||
|
Env []string `json:"env"`
|
||||||
Prelude []string `json:"prelude"` // Are run inside the image which will be our builder
|
Prelude []string `json:"prelude"` // Are run inside the image which will be our builder
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Seed string `json:"seed"`
|
Seed string `json:"seed"`
|
||||||
@ -169,7 +170,16 @@ func (cs *LuetCompilationSpec) RenderBuildImage() (string, error) {
|
|||||||
FROM ` + cs.GetSeedImage() + `
|
FROM ` + cs.GetSeedImage() + `
|
||||||
COPY . /luetbuild
|
COPY . /luetbuild
|
||||||
WORKDIR /luetbuild
|
WORKDIR /luetbuild
|
||||||
|
ENV PACKAGE_NAME=` + cs.Package.GetName() + `
|
||||||
|
ENV PACKAGE_VERSION=` + cs.Package.GetVersion() + `
|
||||||
|
ENV PACKAGE_CATEGORY=` + cs.Package.GetCategory() + `
|
||||||
`
|
`
|
||||||
|
|
||||||
|
for _, s := range cs.Env {
|
||||||
|
spec = spec + `
|
||||||
|
ENV ` + s
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range cs.GetPreBuildSteps() {
|
for _, s := range cs.GetPreBuildSteps() {
|
||||||
spec = spec + `
|
spec = spec + `
|
||||||
RUN ` + s
|
RUN ` + s
|
||||||
@ -180,7 +190,15 @@ RUN ` + s
|
|||||||
// 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 := `
|
spec := `
|
||||||
FROM ` + image
|
FROM ` + image + `
|
||||||
|
ENV PACKAGE_NAME=` + cs.Package.GetName() + `
|
||||||
|
ENV PACKAGE_VERSION=` + cs.Package.GetVersion() + `
|
||||||
|
ENV PACKAGE_CATEGORY=` + cs.Package.GetCategory()
|
||||||
|
|
||||||
|
for _, s := range cs.Env {
|
||||||
|
spec = spec + `
|
||||||
|
ENV ` + s
|
||||||
|
}
|
||||||
for _, s := range cs.BuildSteps() {
|
for _, s := range cs.BuildSteps() {
|
||||||
spec = spec + `
|
spec = spec + `
|
||||||
RUN ` + s
|
RUN ` + s
|
||||||
|
@ -75,6 +75,7 @@ var _ = Describe("Spec", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer os.RemoveAll(tmpdir) // clean up
|
defer os.RemoveAll(tmpdir) // clean up
|
||||||
|
|
||||||
|
lspec.Env = []string{"test=1"}
|
||||||
err = lspec.WriteBuildImageDefinition(filepath.Join(tmpdir, "Dockerfile"))
|
err = lspec.WriteBuildImageDefinition(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
dockerfile, err := helpers.Read(filepath.Join(tmpdir, "Dockerfile"))
|
dockerfile, err := helpers.Read(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
@ -83,6 +84,10 @@ var _ = Describe("Spec", func() {
|
|||||||
FROM alpine
|
FROM alpine
|
||||||
COPY . /luetbuild
|
COPY . /luetbuild
|
||||||
WORKDIR /luetbuild
|
WORKDIR /luetbuild
|
||||||
|
ENV PACKAGE_NAME=enman
|
||||||
|
ENV PACKAGE_VERSION=1.4.0
|
||||||
|
ENV PACKAGE_CATEGORY=app-admin
|
||||||
|
ENV test=1
|
||||||
`))
|
`))
|
||||||
|
|
||||||
err = lspec.WriteStepImageDefinition(lspec.Image, filepath.Join(tmpdir, "Dockerfile"))
|
err = lspec.WriteStepImageDefinition(lspec.Image, filepath.Join(tmpdir, "Dockerfile"))
|
||||||
@ -91,6 +96,10 @@ WORKDIR /luetbuild
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(dockerfile).To(Equal(`
|
Expect(dockerfile).To(Equal(`
|
||||||
FROM luet/base
|
FROM luet/base
|
||||||
|
ENV PACKAGE_NAME=enman
|
||||||
|
ENV PACKAGE_VERSION=1.4.0
|
||||||
|
ENV PACKAGE_CATEGORY=app-admin
|
||||||
|
ENV test=1
|
||||||
RUN echo foo > /test
|
RUN echo foo > /test
|
||||||
RUN echo bar > /test2`))
|
RUN echo bar > /test2`))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user