Compare commits

...

6 Commits

Author SHA1 Message Date
Ettore Di Giacinto
6a86bf3f04 Tag 0.9.16 2020-12-12 16:05:18 +01:00
Ettore Di Giacinto
265e2371b4 Add ArtifactNode to test, now we get the gen Dockerfile in the diff 2020-12-12 16:04:54 +01:00
Daniele Rondina
78442c91fc events: Review description of build_artifact events 2020-12-12 16:03:40 +01:00
Ettore Di Giacinto
d97e606a31 Adapt fixtures and tests 2020-12-12 12:10:24 +01:00
Ettore Di Giacinto
95da20e366 Context files are immutable 2020-12-12 11:55:25 +01:00
Ettore Di Giacinto
797a34ba49 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
2020-12-12 11:16:34 +01:00
20 changed files with 52 additions and 66 deletions

View File

@@ -40,7 +40,7 @@ var Verbose bool
var LockedCommands = []string{"install", "uninstall", "upgrade"} var LockedCommands = []string{"install", "uninstall", "upgrade"}
const ( const (
LuetCLIVersion = "0.9.15" LuetCLIVersion = "0.9.16"
LuetEnvPrefix = "LUET" LuetEnvPrefix = "LUET"
) )

View File

@@ -16,9 +16,9 @@ var (
// EventPackagePreBuild is the event fired before a package is being built // EventPackagePreBuild is the event fired before a package is being built
EventPackagePreBuild pluggable.EventType = "package.pre.build" EventPackagePreBuild pluggable.EventType = "package.pre.build"
// EventPackagePreBuildArtifact is the event fired before a package artifact is being built // EventPackagePreBuildArtifact is the event fired before a package tarball is being generated
EventPackagePreBuildArtifact pluggable.EventType = "package.pre.build_artifact" EventPackagePreBuildArtifact pluggable.EventType = "package.pre.build_artifact"
// EventPackagePostBuildArtifact is the event fired after a package artifact was built // EventPackagePostBuildArtifact is the event fired after a package tarball is generated
EventPackagePostBuildArtifact pluggable.EventType = "package.post.build_artifact" EventPackagePostBuildArtifact pluggable.EventType = "package.post.build_artifact"
// EventPackagePostBuild is the event fired after a package was built // EventPackagePostBuild is the event fired after a package was built
EventPackagePostBuild pluggable.EventType = "package.post.build" EventPackagePostBuild pluggable.EventType = "package.post.build"

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
@@ -113,7 +114,10 @@ RUN echo bar > /test2`))
diffs, err := b.Changes(opts, opts2) diffs, err := b.Changes(opts, opts2)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
artifacts := []ArtifactNode{} artifacts := []ArtifactNode{{
Name: "/luetbuild/LuetDockerfile",
Size: 175,
}}
if os.Getenv("DOCKER_BUILDKIT") == "1" { if os.Getenv("DOCKER_BUILDKIT") == "1" {
artifacts = append(artifacts, ArtifactNode{Name: "/etc/resolv.conf", Size: 0}) artifacts = append(artifacts, ArtifactNode{Name: "/etc/resolv.conf", Size: 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
@@ -102,7 +103,10 @@ RUN echo bar > /test2`))
Expect(b.ImageDefinitionToTar(opts2)).ToNot(HaveOccurred()) Expect(b.ImageDefinitionToTar(opts2)).ToNot(HaveOccurred())
Expect(helpers.Exists(filepath.Join(tmpdir, "output2.tar"))).To(BeTrue()) Expect(helpers.Exists(filepath.Join(tmpdir, "output2.tar"))).To(BeTrue())
artifacts := []ArtifactNode{} artifacts := []ArtifactNode{{
Name: "/luetbuild/LuetDockerfile",
Size: 175,
}}
if os.Getenv("DOCKER_BUILDKIT") == "1" { if os.Getenv("DOCKER_BUILDKIT") == "1" {
artifacts = append(artifacts, ArtifactNode{Name: "/etc/resolv.conf", Size: 0}) artifacts = append(artifacts, ArtifactNode{Name: "/etc/resolv.conf", Size: 0})
} }

View File

@@ -50,8 +50,8 @@ var _ = Describe("Compiler", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
compiler.SetConcurrency(2) compiler.SetConcurrency(2)

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,22 @@ 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 // RenderBuildImage renders the dockerfile of the image used as a pre-build step
func (cs *LuetCompilationSpec) RenderBuildImage() (string, error) {
return cs.genDockerfile(cs.GetSeedImage(), cs.GetPreBuildSteps()), nil
}
// RenderStepImage renders the dockerfile used for the image used for building the package
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

View File

@@ -60,8 +60,8 @@ var _ = Describe("Installer", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
c.SetConcurrency(2) c.SetConcurrency(2)
@@ -176,8 +176,8 @@ urls:
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
c.SetConcurrency(2) c.SetConcurrency(2)
@@ -294,8 +294,8 @@ urls:
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
c.SetConcurrency(2) c.SetConcurrency(2)
@@ -412,8 +412,8 @@ urls:
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
c.SetConcurrency(2) c.SetConcurrency(2)

View File

@@ -60,8 +60,8 @@ var _ = Describe("Repository", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
compiler.SetConcurrency(1) compiler.SetConcurrency(1)
@@ -133,8 +133,8 @@ var _ = Describe("Repository", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
spec.SetOutputPath(tmpdir) spec.SetOutputPath(tmpdir)
spec2.SetOutputPath(tmpdir) spec2.SetOutputPath(tmpdir)

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /test5 - echo artifact5 > /test5
- echo artifact6 > /test6 - echo artifact6 > /test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /test5 - echo artifact5 > /test5
- echo artifact6 > /test6 - echo artifact6 > /test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /test5 - echo artifact5 > /test5
- echo artifact6 > /test6 - echo artifact6 > /test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -1,10 +1,10 @@
image: "alpine" image: "alpine"
prelude: prelude:
- mkdir /foo - mkdir /foo
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /foo/test5 - echo artifact5 > /foo/test5
- echo artifact6 > /foo/test6 - echo artifact6 > /foo/test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh
package_dir: /foo package_dir: /foo
includes: includes:

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /newc - echo artifact5 > /newc
- echo artifact6 > /newnewc - echo artifact6 > /newnewc
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /test5 - echo artifact5 > /test5
- echo artifact6 > /test6 - echo artifact6 > /test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /newc - echo artifact5 > /newc
- echo artifact6 > /newnewc - echo artifact6 > /newnewc
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /test5 - echo artifact5 > /test5
- echo artifact6 > /test6 - echo artifact6 > /test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /newc - echo artifact5 > /newc
- echo artifact6 > /newnewc - echo artifact6 > /newnewc
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /test5 - echo artifact5 > /test5
- echo artifact6 > /test6 - echo artifact6 > /test6
- chmod +x generate.sh
- ./generate.sh - ./generate.sh

View File

@@ -2,8 +2,8 @@ image: "alpine"
prelude: prelude:
- echo foo > /test - echo foo > /test
- echo bar > /test2 - echo bar > /test2
- chmod +x generate.sh
steps: steps:
- echo artifact5 > /newc - echo artifact5 > /newc
- echo artifact6 > /newnewc - echo artifact6 > /newnewc
- chmod +x generate.sh
- ./generate.sh - ./generate.sh