diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index f3ce50f9..4b0b197b 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -522,9 +522,9 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage p CompilationSpec, generateArtifact bool) (Artifact, error) { // If it is a virtual, check if we have to generate an empty artifact or not. - if generateArtifact && p.EmptyPackage() && !p.HasImageSource() { + if generateArtifact && p.IsVirtual() { return cs.genArtifact(p, CompilerBackendOptions{}, CompilerBackendOptions{}, concurrency, keepPermissions) - } else if p.EmptyPackage() && !p.HasImageSource() { + } else if p.IsVirtual() { return &PackageArtifact{}, nil } diff --git a/pkg/compiler/interface.go b/pkg/compiler/interface.go index 0bf49111..012484f3 100644 --- a/pkg/compiler/interface.go +++ b/pkg/compiler/interface.go @@ -186,6 +186,7 @@ type CompilationSpec interface { EmptyPackage() bool UnpackedPackage() bool HasImageSource() bool + IsVirtual() bool } type CompilationSpecs interface { diff --git a/pkg/compiler/spec.go b/pkg/compiler/spec.go index 3e4840a7..97929931 100644 --- a/pkg/compiler/spec.go +++ b/pkg/compiler/spec.go @@ -114,12 +114,12 @@ func NewLuetCompilationSpec(b []byte, p pkg.Package) (CompilationSpec, error) { spec.Package = p.(*pkg.DefaultPackage) return &spec, nil } -func (a *LuetCompilationSpec) GetSourceAssertion() solver.PackagesAssertions { - return a.SourceAssertion +func (cs *LuetCompilationSpec) GetSourceAssertion() solver.PackagesAssertions { + return cs.SourceAssertion } -func (a *LuetCompilationSpec) SetSourceAssertion(as solver.PackagesAssertions) { - a.SourceAssertion = as +func (cs *LuetCompilationSpec) SetSourceAssertion(as solver.PackagesAssertions) { + cs.SourceAssertion = as } func (cs *LuetCompilationSpec) GetPackage() pkg.Package { return cs.Package @@ -157,6 +157,12 @@ func (cs *LuetCompilationSpec) GetRetrieve() []string { return cs.Retrieve } +// IsVirtual returns true if the spec is virtual. +// A spec is virtual if the package is empty, and it has no image source to unpack from. +func (cs *LuetCompilationSpec) IsVirtual() bool { + return cs.EmptyPackage() && !cs.HasImageSource() +} + func (cs *LuetCompilationSpec) GetSeedImage() string { return cs.Seed } @@ -199,8 +205,11 @@ func (cs *LuetCompilationSpec) UnpackedPackage() bool { return unpack } +// HasImageSource returns true when the compilation spec has an image source. +// a compilation spec has an image source when it depends on other packages or have a source image +// explictly supplied func (cs *LuetCompilationSpec) HasImageSource() bool { - return len(cs.GetPackage().GetRequires()) != 0 || cs.GetImage() != "" + return (cs.Package != nil && len(cs.GetPackage().GetRequires()) != 0) || cs.GetImage() != "" } func (cs *LuetCompilationSpec) CopyRetrieves(dest string) error { diff --git a/pkg/compiler/spec_test.go b/pkg/compiler/spec_test.go index 88e0c989..ff35b9cf 100644 --- a/pkg/compiler/spec_test.go +++ b/pkg/compiler/spec_test.go @@ -51,6 +51,26 @@ var _ = Describe("Spec", func() { Expect(newSpec2.All()).To(Equal([]CompilationSpec{testSpec3})) }) + Context("virtuals", func() { + When("is empty", func() { + It("is virtual", func() { + spec := &LuetCompilationSpec{} + Expect(spec.IsVirtual()).To(BeTrue()) + }) + }) + When("has defined steps", func() { + It("is not a virtual", func() { + spec := &LuetCompilationSpec{Steps: []string{"foo"}} + Expect(spec.IsVirtual()).To(BeFalse()) + }) + }) + When("has defined image", func() { + It("is not a virtual", func() { + spec := &LuetCompilationSpec{Image: "foo"} + Expect(spec.IsVirtual()).To(BeFalse()) + }) + }) + }) }) Context("Simple package build definition", func() {