mirror of
https://github.com/mudler/luet.git
synced 2025-09-04 16:50:50 +00:00
Add IsVirtual() to compile spec
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -186,6 +186,7 @@ type CompilationSpec interface {
|
||||
EmptyPackage() bool
|
||||
UnpackedPackage() bool
|
||||
HasImageSource() bool
|
||||
IsVirtual() bool
|
||||
}
|
||||
|
||||
type CompilationSpecs interface {
|
||||
|
@@ -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 {
|
||||
|
@@ -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() {
|
||||
|
Reference in New Issue
Block a user