mirror of
https://github.com/mudler/luet.git
synced 2025-09-04 00:34:41 +00:00
⚙️ Fixup runtime tree detection during join images
We need to hook up the runtime DB in order to query the correct part of the tree
This commit is contained in:
@@ -133,11 +133,16 @@ Build packages specifying multiple definition trees:
|
|||||||
db = pkg.NewInMemoryDatabase(false)
|
db = pkg.NewInMemoryDatabase(false)
|
||||||
defer db.Clean()
|
defer db.Clean()
|
||||||
|
|
||||||
|
runtimeDB := pkg.NewInMemoryDatabase(false)
|
||||||
|
defer runtimeDB.Clean()
|
||||||
|
|
||||||
|
installerRecipe := tree.NewInstallerRecipe(runtimeDB)
|
||||||
generalRecipe := tree.NewCompilerRecipe(db)
|
generalRecipe := tree.NewCompilerRecipe(db)
|
||||||
|
|
||||||
for _, src := range treePaths {
|
for _, src := range treePaths {
|
||||||
util.DefaultContext.Info("Loading tree", src)
|
util.DefaultContext.Info("Loading tree", src)
|
||||||
helpers.CheckErr(generalRecipe.Load(src))
|
helpers.CheckErr(generalRecipe.Load(src))
|
||||||
|
helpers.CheckErr(installerRecipe.Load(src))
|
||||||
}
|
}
|
||||||
|
|
||||||
if fromRepo {
|
if fromRepo {
|
||||||
@@ -172,6 +177,7 @@ Build packages specifying multiple definition trees:
|
|||||||
options.WithTemplateFolder(templateFolders),
|
options.WithTemplateFolder(templateFolders),
|
||||||
options.WithSolverOptions(opts),
|
options.WithSolverOptions(opts),
|
||||||
options.Wait(wait),
|
options.Wait(wait),
|
||||||
|
options.WithRuntimeDatabase(installerRecipe.GetDatabase()),
|
||||||
options.OnlyTarget(onlyTarget),
|
options.OnlyTarget(onlyTarget),
|
||||||
options.PullFirst(pull),
|
options.PullFirst(pull),
|
||||||
options.KeepImg(keepImages),
|
options.KeepImg(keepImages),
|
||||||
|
@@ -805,15 +805,15 @@ func (cs *LuetCompiler) FromDatabase(db types.PackageDatabase, minimum bool, dst
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *LuetCompiler) ComputeDepTree(p *compilerspec.LuetCompilationSpec) (types.PackagesAssertions, error) {
|
func (cs *LuetCompiler) ComputeDepTree(p *compilerspec.LuetCompilationSpec, db types.PackageDatabase) (types.PackagesAssertions, error) {
|
||||||
s := solver.NewResolver(cs.Options.SolverOptions.SolverOptions, pkg.NewInMemoryDatabase(false), cs.Database, pkg.NewInMemoryDatabase(false), solver.NewSolverFromOptions(cs.Options.SolverOptions))
|
s := solver.NewResolver(cs.Options.SolverOptions.SolverOptions, pkg.NewInMemoryDatabase(false), db, pkg.NewInMemoryDatabase(false), solver.NewSolverFromOptions(cs.Options.SolverOptions))
|
||||||
|
|
||||||
solution, err := s.Install(types.Packages{p.GetPackage()})
|
solution, err := s.Install(types.Packages{p.GetPackage()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "While computing a solution for "+p.GetPackage().HumanReadableString())
|
return nil, errors.Wrap(err, "While computing a solution for "+p.GetPackage().HumanReadableString())
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies, err := solution.Order(cs.Database, p.GetPackage().GetFingerPrint())
|
dependencies, err := solution.Order(db, p.GetPackage().GetFingerPrint())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "While order a solution for "+p.GetPackage().HumanReadableString())
|
return nil, errors.Wrap(err, "While order a solution for "+p.GetPackage().HumanReadableString())
|
||||||
}
|
}
|
||||||
@@ -831,7 +831,7 @@ func (cs *LuetCompiler) BuildTree(compilerSpecs compilerspec.LuetCompilationspec
|
|||||||
bt := &BuildTree{}
|
bt := &BuildTree{}
|
||||||
|
|
||||||
for _, sp := range compilerSpecs.All() {
|
for _, sp := range compilerSpecs.All() {
|
||||||
ass, err := cs.ComputeDepTree(sp)
|
ass, err := cs.ComputeDepTree(sp, cs.Database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -843,7 +843,7 @@ func (cs *LuetCompiler) BuildTree(compilerSpecs compilerspec.LuetCompilationspec
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ass, err := cs.ComputeDepTree(spec)
|
ass, err := cs.ComputeDepTree(spec, cs.Database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -872,7 +872,7 @@ func (cs *LuetCompiler) ComputeMinimumCompilableSet(p ...*compilerspec.LuetCompi
|
|||||||
allDependencies := types.PackagesAssertions{} // Get all packages that will be in deps
|
allDependencies := types.PackagesAssertions{} // Get all packages that will be in deps
|
||||||
result := []*compilerspec.LuetCompilationSpec{}
|
result := []*compilerspec.LuetCompilationSpec{}
|
||||||
for _, spec := range p {
|
for _, spec := range p {
|
||||||
sol, err := cs.ComputeDepTree(spec)
|
sol, err := cs.ComputeDepTree(spec, cs.Database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed querying hashtree")
|
return nil, errors.Wrap(err, "failed querying hashtree")
|
||||||
}
|
}
|
||||||
@@ -951,30 +951,33 @@ func (cs *LuetCompiler) resolveFinalImages(concurrency int, keepPermissions bool
|
|||||||
|
|
||||||
cs.Options.Context.Info(joinTag, "Generating a parent image from final packages")
|
cs.Options.Context.Info(joinTag, "Generating a parent image from final packages")
|
||||||
|
|
||||||
//fromPackages = p.Package.GetRequires() // (first level only)
|
if cs.Options.RuntimeDatabase != nil {
|
||||||
pTarget := p
|
// Create a fake db from runtime which has the target entry as the compiler view
|
||||||
|
db := pkg.NewInMemoryDatabase(false)
|
||||||
|
cs.Options.RuntimeDatabase.Clone(db)
|
||||||
|
defer db.Clean()
|
||||||
|
|
||||||
runtime, err := p.Package.GetRuntimePackage()
|
if err := db.UpdatePackage(p.Package); err != nil {
|
||||||
if err == nil {
|
return err
|
||||||
spec, err := cs.FromPackage(runtime)
|
|
||||||
if err == nil {
|
|
||||||
cs.Options.Context.Info(joinTag, "Using runtime package for deptree computation")
|
|
||||||
pTarget = spec
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// resolve deptree of runtime of p and use it in fromPackages
|
|
||||||
t, err := cs.ComputeDepTree(pTarget)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "failed querying hashtree")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, a := range t {
|
|
||||||
if !a.Value || a.Package.Matches(p.Package) {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fromPackages = append(fromPackages, a.Package)
|
// resolve deptree of runtime of p and use it in fromPackages
|
||||||
cs.Options.Context.Infof("Adding dependency '%s'.", a.Package.HumanReadableString())
|
t, err := cs.ComputeDepTree(p, db)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed querying hashtree")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, a := range t {
|
||||||
|
if !a.Value || a.Package.Matches(p.Package) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fromPackages = append(fromPackages, a.Package)
|
||||||
|
cs.Options.Context.Infof("Adding dependency '%s'.", a.Package.HumanReadableString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cs.Options.Context.Info(joinTag, "No runtime db present, first level join only")
|
||||||
|
fromPackages = p.Package.GetRequires() // first level only
|
||||||
}
|
}
|
||||||
|
|
||||||
// First compute a hash and check if image is available. if it is, then directly consume that
|
// First compute a hash and check if image is available. if it is, then directly consume that
|
||||||
|
@@ -1108,10 +1108,14 @@ var _ = Describe("Compiler", func() {
|
|||||||
Context("final images", func() {
|
Context("final images", func() {
|
||||||
It("reuses final images", func() {
|
It("reuses final images", func() {
|
||||||
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
||||||
|
installerRecipe := tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
||||||
|
|
||||||
err := generalRecipe.Load("../../tests/fixtures/join_complex")
|
err := generalRecipe.Load("../../tests/fixtures/join_complex")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
err = installerRecipe.Load("../../tests/fixtures/join_complex")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(6))
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(6))
|
||||||
logdir, err := ioutil.TempDir("", "log")
|
logdir, err := ioutil.TempDir("", "log")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -1139,7 +1143,7 @@ var _ = Describe("Compiler", func() {
|
|||||||
|
|
||||||
b := sd.NewSimpleDockerBackend(ctx)
|
b := sd.NewSimpleDockerBackend(ctx)
|
||||||
|
|
||||||
joinImage := "luet/cache:586b36482e3f238c76d3536e7ca12cc4" //resulting join image
|
joinImage := "luet/cache:08738767caa9a7397fad70ae53db85fa" //resulting join image
|
||||||
allImages := []string{
|
allImages := []string{
|
||||||
joinImage,
|
joinImage,
|
||||||
"test/test:c-test-1.2"}
|
"test/test:c-test-1.2"}
|
||||||
@@ -1155,6 +1159,7 @@ var _ = Describe("Compiler", func() {
|
|||||||
compiler := NewLuetCompiler(b, generalRecipe.GetDatabase(),
|
compiler := NewLuetCompiler(b, generalRecipe.GetDatabase(),
|
||||||
options.WithFinalRepository("test/test"),
|
options.WithFinalRepository("test/test"),
|
||||||
options.EnableGenerateFinalImages,
|
options.EnableGenerateFinalImages,
|
||||||
|
options.WithRuntimeDatabase(installerRecipe.GetDatabase()),
|
||||||
options.PullFirst(true),
|
options.PullFirst(true),
|
||||||
options.WithContext(c))
|
options.WithContext(c))
|
||||||
|
|
||||||
@@ -1181,6 +1186,7 @@ var _ = Describe("Compiler", func() {
|
|||||||
))
|
))
|
||||||
|
|
||||||
Expect(log).ToNot(And(
|
Expect(log).ToNot(And(
|
||||||
|
ContainSubstring("No runtime db present, first level join only"),
|
||||||
ContainSubstring("Final image already found test/test:c-test-1.2"),
|
ContainSubstring("Final image already found test/test:c-test-1.2"),
|
||||||
))
|
))
|
||||||
|
|
||||||
@@ -1199,11 +1205,13 @@ var _ = Describe("Compiler", func() {
|
|||||||
readLogs()
|
readLogs()
|
||||||
|
|
||||||
Expect(log).To(And(
|
Expect(log).To(And(
|
||||||
ContainSubstring("Final image already found test/test:a-test-1.2"),
|
ContainSubstring("Final image already found test/test:f-test-1.2"),
|
||||||
))
|
))
|
||||||
Expect(log).ToNot(And(
|
Expect(log).ToNot(And(
|
||||||
|
ContainSubstring("No runtime db present, first level join only"),
|
||||||
ContainSubstring("build test/c-1.2 compilation starts"),
|
ContainSubstring("build test/c-1.2 compilation starts"),
|
||||||
ContainSubstring("Final image not found for test/c-1.2"),
|
ContainSubstring("Final image not found for test/c-1.2"),
|
||||||
|
ContainSubstring("a-test-1.2"),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -121,7 +121,7 @@ func (ht *ImageHashTree) genBuilderImageTag(p *compilerspec.LuetCompilationSpec,
|
|||||||
// resolve computes the dependency tree of a compilation spec and returns solver assertions
|
// resolve computes the dependency tree of a compilation spec and returns solver assertions
|
||||||
// in order to be able to compile the spec.
|
// in order to be able to compile the spec.
|
||||||
func (ht *ImageHashTree) resolve(cs *LuetCompiler, p *compilerspec.LuetCompilationSpec) (types.PackagesAssertions, error) {
|
func (ht *ImageHashTree) resolve(cs *LuetCompiler, p *compilerspec.LuetCompilationSpec) (types.PackagesAssertions, error) {
|
||||||
dependencies, err := cs.ComputeDepTree(p)
|
dependencies, err := cs.ComputeDepTree(p, cs.Database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "While computing a solution for "+p.GetPackage().HumanReadableString())
|
return nil, errors.Wrap(err, "While computing a solution for "+p.GetPackage().HumanReadableString())
|
||||||
}
|
}
|
||||||
|
@@ -54,6 +54,7 @@ type Compiler struct {
|
|||||||
|
|
||||||
// Image repository to push to
|
// Image repository to push to
|
||||||
PushFinalImagesRepository string
|
PushFinalImagesRepository string
|
||||||
|
RuntimeDatabase types.PackageDatabase
|
||||||
|
|
||||||
Context types.Context
|
Context types.Context
|
||||||
}
|
}
|
||||||
@@ -93,6 +94,13 @@ func WithOptions(opt *Compiler) func(cfg *Compiler) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithRuntimeDatabase(db types.PackageDatabase) func(cfg *Compiler) error {
|
||||||
|
return func(cfg *Compiler) error {
|
||||||
|
cfg.RuntimeDatabase = db
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithFinalRepository Sets the final repository where to push
|
// WithFinalRepository Sets the final repository where to push
|
||||||
// images of built artifacts
|
// images of built artifacts
|
||||||
func WithFinalRepository(r string) func(cfg *Compiler) error {
|
func WithFinalRepository(r string) func(cfg *Compiler) error {
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
category: "test"
|
category: "test"
|
||||||
name: "c"
|
name: "c"
|
||||||
version: "1.2"
|
version: "1.2"
|
||||||
|
requires:
|
||||||
|
- name: "b"
|
||||||
|
category: "test"
|
||||||
|
version: ">=0"
|
@@ -22,7 +22,7 @@ testBuild() {
|
|||||||
buildst=$?
|
buildst=$?
|
||||||
assertEquals 'builds successfully' "$buildst" "0"
|
assertEquals 'builds successfully' "$buildst" "0"
|
||||||
assertTrue 'create package z' "[ -e '$tmpdir/testbuild/z-test-0.1.package.tar.gz' ]"
|
assertTrue 'create package z' "[ -e '$tmpdir/testbuild/z-test-0.1.package.tar.gz' ]"
|
||||||
assertTrue 'create package z' "[ -e '$tmpdir/testbuild/x-test-0.1.package.tar.gz' ]"
|
assertTrue 'create package x' "[ -e '$tmpdir/testbuild/x-test-0.1.package.tar.gz' ]"
|
||||||
|
|
||||||
mkdir $tmpdir/extract
|
mkdir $tmpdir/extract
|
||||||
tar -xvf $tmpdir/testbuild/x-test-0.1.package.tar.gz -C $tmpdir/extract
|
tar -xvf $tmpdir/testbuild/x-test-0.1.package.tar.gz -C $tmpdir/extract
|
||||||
|
Reference in New Issue
Block a user