mirror of
https://github.com/mudler/luet.git
synced 2025-06-25 15:01:55 +00:00
Use well defined structure for serializing, fixups to make test green
This commit is contained in:
parent
a879411c54
commit
e9c01b46a7
@ -91,7 +91,7 @@ type LuetCompilationSpec struct {
|
||||
Prelude []string `json:"prelude"` // Are run inside the image which will be our builder
|
||||
Image string `json:"image"`
|
||||
Seed string `json:"seed"`
|
||||
Package *pkg.DefaultPackage `json:"-"`
|
||||
Package *pkg.DefaultPackage `json:"package"`
|
||||
SourceAssertion solver.PackagesAssertions `json:"-"`
|
||||
|
||||
OutputPath string `json:"-"` // Where the build processfiles go
|
||||
|
@ -18,8 +18,11 @@ package client
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/mudler/luet/pkg/logger"
|
||||
|
||||
"github.com/mudler/luet/pkg/compiler"
|
||||
"github.com/mudler/luet/pkg/helpers"
|
||||
)
|
||||
@ -33,18 +36,20 @@ func NewLocalClient(r RepoData) *LocalClient {
|
||||
}
|
||||
|
||||
func (c *LocalClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Artifact, error) {
|
||||
|
||||
artifactName := path.Base(artifact.GetPath())
|
||||
Info("Downloading artifact", artifactName, "from", c.RepoData.Uri)
|
||||
file, err := ioutil.TempFile(os.TempDir(), "localclient")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//defer os.Remove(file.Name())
|
||||
|
||||
err = helpers.CopyFile(filepath.Join(c.RepoData.Uri, artifact.GetPath()), file.Name())
|
||||
err = helpers.CopyFile(filepath.Join(c.RepoData.Uri, artifactName), file.Name())
|
||||
|
||||
return compiler.NewPackageArtifact(file.Name()), nil
|
||||
}
|
||||
func (c *LocalClient) DownloadFile(name string) (string, error) {
|
||||
Info("Downloading file", name, "from", c.RepoData.Uri)
|
||||
|
||||
file, err := ioutil.TempFile(os.TempDir(), "localclient")
|
||||
if err != nil {
|
||||
|
@ -98,7 +98,7 @@ func (l *LuetInstaller) Install(p []pkg.Package, s *System) error {
|
||||
for _, r := range l.PackageRepositories {
|
||||
repo, err := r.Sync()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed syncing repository"+r.GetName())
|
||||
return errors.Wrap(err, "Failed syncing repository: "+r.GetName())
|
||||
}
|
||||
syncedRepos = append(syncedRepos, repo)
|
||||
}
|
||||
@ -171,6 +171,10 @@ func (l *LuetInstaller) Install(p []pkg.Package, s *System) error {
|
||||
}
|
||||
A:
|
||||
for _, artefact := range matches[0].Repo.GetIndex() {
|
||||
if artefact.GetCompileSpec().GetPackage() == nil {
|
||||
return errors.New("Package in compilespec empty")
|
||||
|
||||
}
|
||||
if matches[0].Package.Matches(artefact.GetCompileSpec().GetPackage()) {
|
||||
// TODO: Filter out already installed?
|
||||
toInstall[assertion.Package.GetFingerPrint()] = ArtifactMatch{Package: assertion.Package, Artifact: artefact, Repository: matches[0].Repo}
|
||||
|
@ -105,7 +105,7 @@ var _ = Describe("Installer", func() {
|
||||
name: "test"
|
||||
type: "local"
|
||||
uri: "`+tmpdir+`"
|
||||
`))
|
||||
`), pkg.NewInMemoryDatabase(false))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
inst.Repositories(Repositories{repo2})
|
||||
|
@ -41,6 +41,7 @@ type Repository interface {
|
||||
GetPriority() int
|
||||
GetIndex() compiler.ArtifactIndex
|
||||
GetTree() tree.Builder
|
||||
SetTree(tree.Builder)
|
||||
Write(path string) error
|
||||
Sync() (Repository, error)
|
||||
GetTreePath() string
|
||||
|
@ -43,6 +43,14 @@ type LuetRepository struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type LuetRepositorySerialized struct {
|
||||
Name string `json:"name"`
|
||||
Uri string `json:"uri"`
|
||||
Priority int `json:"priority"`
|
||||
Index []*compiler.PackageArtifact `json:"index"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func GenerateRepository(name, uri, t string, priority int, src, treeDir string, db pkg.PackageDatabase) (Repository, error) {
|
||||
|
||||
art, err := buildPackageIndex(src)
|
||||
@ -62,13 +70,25 @@ func NewLuetRepository(name, uri, t string, priority int, art []compiler.Artifac
|
||||
return &LuetRepository{Index: art, Type: t, Tree: builder, Name: name, Uri: uri, Priority: priority}
|
||||
}
|
||||
|
||||
func NewLuetRepositoryFromYaml(data []byte) (Repository, error) {
|
||||
var p LuetRepository
|
||||
func NewLuetRepositoryFromYaml(data []byte, db pkg.PackageDatabase) (Repository, error) {
|
||||
var p *LuetRepositorySerialized
|
||||
r := &LuetRepository{}
|
||||
err := yaml.Unmarshal(data, &p)
|
||||
if err != nil {
|
||||
return &p, err
|
||||
return nil, err
|
||||
}
|
||||
return &p, err
|
||||
r.Name = p.Name
|
||||
r.Uri = p.Uri
|
||||
r.Priority = p.Priority
|
||||
r.Type = p.Type
|
||||
i := compiler.ArtifactIndex{}
|
||||
for _, ii := range p.Index {
|
||||
i = append(i, ii)
|
||||
}
|
||||
r.Index = i
|
||||
r.Tree = tree.NewInstallerRecipe(db)
|
||||
|
||||
return r, err
|
||||
}
|
||||
|
||||
func buildPackageIndex(path string) ([]compiler.Artifact, error) {
|
||||
@ -114,6 +134,10 @@ func (r *LuetRepository) SetTreePath(p string) {
|
||||
r.TreePath = p
|
||||
}
|
||||
|
||||
func (r *LuetRepository) SetTree(b tree.Builder) {
|
||||
r.Tree = b
|
||||
}
|
||||
|
||||
func (r *LuetRepository) GetType() string {
|
||||
return r.Type
|
||||
}
|
||||
@ -141,6 +165,7 @@ func (r *LuetRepository) Write(dst string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.Index = r.Index.CleanPath()
|
||||
err = ioutil.WriteFile(filepath.Join(dst, "repository.yaml"), data, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -171,7 +196,9 @@ func (r *LuetRepository) Client() Client {
|
||||
}
|
||||
func (r *LuetRepository) Sync() (Repository, error) {
|
||||
c := r.Client()
|
||||
|
||||
if c == nil {
|
||||
return nil, errors.New("No client could be generated from repository.")
|
||||
}
|
||||
file, err := c.DownloadFile("repository.yaml")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "While downloading repository.yaml from "+r.GetUri())
|
||||
@ -182,7 +209,8 @@ func (r *LuetRepository) Sync() (Repository, error) {
|
||||
}
|
||||
defer os.Remove(file)
|
||||
|
||||
repo, err := NewLuetRepositoryFromYaml(dat)
|
||||
// TODO: make it swappable
|
||||
repo, err := NewLuetRepositoryFromYaml(dat, pkg.NewInMemoryDatabase(false))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error reading repository from file "+file)
|
||||
|
||||
@ -212,11 +240,12 @@ func (r *LuetRepository) Sync() (Repository, error) {
|
||||
return nil, errors.Wrap(err, "Error met while unpacking rootfs")
|
||||
}
|
||||
|
||||
reciper := tree.NewInstallerRecipe(r.GetTree().Tree().GetPackageSet())
|
||||
reciper := tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
||||
err = reciper.Load(treefs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error met while unpacking rootfs")
|
||||
}
|
||||
repo.SetTree(reciper)
|
||||
repo.SetTreePath(treefs)
|
||||
|
||||
return repo, nil
|
||||
|
@ -34,7 +34,11 @@ const (
|
||||
FinalizerFile = "finalize.yaml"
|
||||
)
|
||||
|
||||
func NewInstallerRecipe(db pkg.PackageDatabase) Builder { return &InstallerRecipe{Database: db} }
|
||||
func NewInstallerRecipe(db pkg.PackageDatabase) Builder {
|
||||
tree := NewDefaultTree()
|
||||
tree.SetPackageSet(db)
|
||||
return &InstallerRecipe{Database: db, PackageTree: tree}
|
||||
}
|
||||
|
||||
// InstallerRecipe is the "general" reciper for Trees
|
||||
type InstallerRecipe struct {
|
||||
|
Loading…
Reference in New Issue
Block a user