Skip to content

Commit

Permalink
Source packages metadata to update repository tree
Browse files Browse the repository at this point in the history
This allows to generate trees with `create-repo` by just having
the metadata files, making tree(s) an optional requirement.
  • Loading branch information
mudler committed Sep 16, 2021
1 parent 972421a commit e4fff77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pkg/installer/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"regexp"
"sort"
"strconv"
"strings"
"time"

artifact "github.com/mudler/luet/pkg/compiler/types/artifact"
Expand Down Expand Up @@ -297,6 +298,37 @@ func GenerateRepository(name, descr, t string, urls []string,
}
}

// Load packages from metadata files if not present already.
var ff = func(currentpath string, info os.FileInfo, err error) error {
if err != nil {
return nil
}

// Only those which are metadata
if !strings.HasSuffix(info.Name(), pkg.PackageMetaSuffix) {
return nil
}

dat, err := ioutil.ReadFile(currentpath)
if err != nil {
return nil
}

art, err := artifact.NewPackageArtifactFromYaml(dat)
if err != nil {
return nil
}
if _, err := runtimeTree.FindPackage(art.CompileSpec.Package); err != nil && art.CompileSpec.Package.Name != "" {
Debug("Added", art.CompileSpec.Package.HumanReadableString(), "from metadata files")
runtimeTree.CreatePackage(art.CompileSpec.Package)
}

return nil
}

// Best effort
filepath.Walk(src, ff)

repo := &LuetSystemRepository{
LuetRepository: config.NewLuetRepository(name, t, descr, urls, priority, true, false),
Tree: tree.NewInstallerRecipe(runtimeTree),
Expand Down
4 changes: 3 additions & 1 deletion pkg/package/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ type Package interface {
JSON() ([]byte, error)
}

const PackageMetaSuffix = "metadata.yaml"

type Tree interface {
GetPackageSet() PackageDatabase
Prelude() string // A tree might have a prelude to be able to consume a tree
Expand Down Expand Up @@ -246,7 +248,7 @@ func (t *DefaultPackage) JSON() ([]byte, error) {

// GetMetadataFilePath returns the canonical name of an artifact metadata file
func (d *DefaultPackage) GetMetadataFilePath() string {
return d.GetFingerPrint() + ".metadata.yaml"
return fmt.Sprintf("%s.%s", d.GetFingerPrint(), PackageMetaSuffix)
}

// DefaultPackage represent a standard package definition
Expand Down

0 comments on commit e4fff77

Please sign in to comment.