mirror of
https://github.com/mudler/luet.git
synced 2025-09-03 00:06:36 +00:00
Annotate artifact metadata after compiling
This commit is contained in:
@@ -18,6 +18,7 @@ package compiler
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -26,23 +27,64 @@ import (
|
|||||||
|
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
"github.com/mudler/luet/pkg/solver"
|
"github.com/mudler/luet/pkg/solver"
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PackageArtifact struct {
|
type ArtifactIndex []Artifact
|
||||||
Path string
|
|
||||||
Dependencies []Artifact
|
|
||||||
CompileSpec CompilationSpec
|
|
||||||
|
|
||||||
SourceAssertion solver.PackagesAssertions
|
func (i ArtifactIndex) CleanPath() ArtifactIndex {
|
||||||
|
var newIndex []Artifact
|
||||||
|
copy(newIndex, i)
|
||||||
|
for _, n := range newIndex {
|
||||||
|
n.SetPath(path.Base(n.GetPath()))
|
||||||
|
}
|
||||||
|
return newIndex
|
||||||
|
//Update if exists, otherwise just create
|
||||||
|
}
|
||||||
|
|
||||||
|
// When compiling, we write also a fingerprint.metadata.yaml file with PackageArtifact. In this way we can have another command to create the repository
|
||||||
|
// which will consist in just of an repository.yaml which is just the repository structure with the list of package artifact.
|
||||||
|
// In this way a generic client can fetch the packages and, after unpacking the tree, performing queries to install packages.
|
||||||
|
type PackageArtifact struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
Dependencies []Artifact `json:"dependencies"`
|
||||||
|
CompileSpec CompilationSpec `json:"compilationspec"`
|
||||||
|
|
||||||
|
SourceAssertion solver.PackagesAssertions `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPackageArtifact(path string) Artifact {
|
func NewPackageArtifact(path string) Artifact {
|
||||||
return &PackageArtifact{Path: path, Dependencies: []Artifact{}}
|
return &PackageArtifact{Path: path, Dependencies: []Artifact{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewPackageArtifactFromYaml(data []byte) (Artifact, error) {
|
||||||
|
var p PackageArtifact
|
||||||
|
err := yaml.Unmarshal(data, &p)
|
||||||
|
if err != nil {
|
||||||
|
return &p, err
|
||||||
|
}
|
||||||
|
return &p, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *PackageArtifact) WriteYaml(dst string) error {
|
||||||
|
a.CompileSpec.GetPackage().SetPath("")
|
||||||
|
for _, ass := range a.CompileSpec.GetSourceAssertion() {
|
||||||
|
ass.Package.SetPath("")
|
||||||
|
}
|
||||||
|
data, err := yaml.Marshal(a)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "While marshalling for PackageArtifact YAML")
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(filepath.Join(dst, a.GetCompileSpec().GetPackage().GetFingerPrint()+".metadata.yaml"), data, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "While writing PackageArtifact YAML")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *PackageArtifact) GetSourceAssertion() solver.PackagesAssertions {
|
func (a *PackageArtifact) GetSourceAssertion() solver.PackagesAssertions {
|
||||||
return a.SourceAssertion
|
return a.SourceAssertion
|
||||||
}
|
}
|
||||||
|
@@ -276,6 +276,10 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
artifact.SetCompileSpec(p)
|
artifact.SetCompileSpec(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = artifact.WriteYaml(p.GetOutputPath())
|
||||||
|
if err != nil {
|
||||||
|
return artifact, err
|
||||||
|
}
|
||||||
return artifact, nil
|
return artifact, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,6 +336,10 @@ func (cs *LuetCompiler) packageFromImage(p CompilationSpec, tag string, keepPerm
|
|||||||
Info(pkgTag, " :white_check_mark: Done")
|
Info(pkgTag, " :white_check_mark: Done")
|
||||||
artifact := NewPackageArtifact(p.Rel(p.GetPackage().GetFingerPrint() + ".package.tar"))
|
artifact := NewPackageArtifact(p.Rel(p.GetPackage().GetFingerPrint() + ".package.tar"))
|
||||||
artifact.SetCompileSpec(p)
|
artifact.SetCompileSpec(p)
|
||||||
|
err = artifact.WriteYaml(p.GetOutputPath())
|
||||||
|
if err != nil {
|
||||||
|
return artifact, err
|
||||||
|
}
|
||||||
return artifact, nil
|
return artifact, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -292,6 +292,8 @@ var _ = Describe("Compiler", func() {
|
|||||||
|
|
||||||
Expect(helpers.Exists(spec.Rel("usr/bin/pkgs-checker"))).To(BeTrue())
|
Expect(helpers.Exists(spec.Rel("usr/bin/pkgs-checker"))).To(BeTrue())
|
||||||
Expect(helpers.Exists(spec.Rel("base-layer-0.1.package.tar"))).To(BeTrue())
|
Expect(helpers.Exists(spec.Rel("base-layer-0.1.package.tar"))).To(BeTrue())
|
||||||
|
Expect(helpers.Exists(spec.Rel("base-layer-0.1.metadata.yaml"))).To(BeTrue())
|
||||||
|
Expect(helpers.Exists(spec.Rel("extra-layer-0.1.metadata.yaml"))).To(BeTrue())
|
||||||
Expect(helpers.Exists(spec.Rel("extra-layer-0.1.package.tar"))).To(BeTrue())
|
Expect(helpers.Exists(spec.Rel("extra-layer-0.1.package.tar"))).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -62,6 +62,7 @@ type Artifact interface {
|
|||||||
|
|
||||||
SetCompileSpec(as CompilationSpec)
|
SetCompileSpec(as CompilationSpec)
|
||||||
GetCompileSpec() CompilationSpec
|
GetCompileSpec() CompilationSpec
|
||||||
|
WriteYaml(dst string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactNode struct {
|
type ArtifactNode struct {
|
||||||
|
@@ -25,4 +25,6 @@ type Builder interface {
|
|||||||
Load(string) error // A tree might be loaded from a db (e.g. bolt) and written to folder
|
Load(string) error // A tree might be loaded from a db (e.g. bolt) and written to folder
|
||||||
Tree() pkg.Tree // generates world
|
Tree() pkg.Tree // generates world
|
||||||
WithTree(pkg.Tree)
|
WithTree(pkg.Tree)
|
||||||
|
|
||||||
|
GetSourcePath() string
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ func (r *CompilerRecipe) Load(path string) error {
|
|||||||
if r.Tree() == nil {
|
if r.Tree() == nil {
|
||||||
r.PackageTree = NewDefaultTree()
|
r.PackageTree = NewDefaultTree()
|
||||||
}
|
}
|
||||||
|
r.SourcePath = path
|
||||||
//tmpfile, err := ioutil.TempFile("", "luet")
|
//tmpfile, err := ioutil.TempFile("", "luet")
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return err
|
// return err
|
||||||
@@ -106,5 +106,6 @@ func (r *CompilerRecipe) Load(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CompilerRecipe) Tree() pkg.Tree { return r.PackageTree }
|
func (r *CompilerRecipe) Tree() pkg.Tree { return r.PackageTree }
|
||||||
func (r *CompilerRecipe) WithTree(t pkg.Tree) { r.PackageTree = t }
|
func (r *CompilerRecipe) WithTree(t pkg.Tree) { r.PackageTree = t }
|
||||||
|
func (r *CompilerRecipe) GetSourcePath() string { return r.SourcePath }
|
||||||
|
@@ -38,6 +38,7 @@ func NewGeneralRecipe(db pkg.PackageDatabase) Builder { return &Recipe{Database:
|
|||||||
// Recipe is the "general" reciper for Trees
|
// Recipe is the "general" reciper for Trees
|
||||||
type Recipe struct {
|
type Recipe struct {
|
||||||
PackageTree pkg.Tree
|
PackageTree pkg.Tree
|
||||||
|
SourcePath string
|
||||||
Database pkg.PackageDatabase
|
Database pkg.PackageDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +76,7 @@ func (r *Recipe) Load(path string) error {
|
|||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
r.Tree().SetPackageSet(r.Database)
|
r.Tree().SetPackageSet(r.Database)
|
||||||
|
r.SourcePath = path
|
||||||
|
|
||||||
//r.Tree().SetPackageSet(pkg.NewBoltDatabase(tmpfile.Name()))
|
//r.Tree().SetPackageSet(pkg.NewBoltDatabase(tmpfile.Name()))
|
||||||
// TODO: Handle cleaning after? Cleanup implemented in GetPackageSet().Clean()
|
// TODO: Handle cleaning after? Cleanup implemented in GetPackageSet().Clean()
|
||||||
@@ -112,5 +114,6 @@ func (r *Recipe) Load(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Recipe) Tree() pkg.Tree { return r.PackageTree }
|
func (r *Recipe) Tree() pkg.Tree { return r.PackageTree }
|
||||||
func (r *Recipe) WithTree(t pkg.Tree) { r.PackageTree = t }
|
func (r *Recipe) WithTree(t pkg.Tree) { r.PackageTree = t }
|
||||||
|
func (r *Recipe) GetSourcePath() string { return r.SourcePath }
|
||||||
|
Reference in New Issue
Block a user