From a02ab1651079723f790e9ffa8023b5d3c15a8100 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 24 Nov 2021 21:59:43 +0100 Subject: [PATCH] Don't load requires while parsing compilespec that consume final images When depending on those package otherwise we try to compile the full tree instead of reconstrucing the image which is result of a join while keeping the revdep tree invariate --- pkg/compiler/compiler.go | 41 ++++++++++++------- pkg/tree/compiler_recipe.go | 1 + tests/fixtures/join_complex/c/c1/build.yaml | 6 ++- .../join_complex/cat/b-1.1/build.yaml | 3 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index a367626c..44b2715f 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -239,19 +239,6 @@ func (cs *LuetCompiler) unpackFs(concurrency int, keepPermissions bool, p *compi return nil, err } - // artifact.ImageToArtifact( - // cs.Options.Context, - // img, - // cs.Options.CompressionType, - // p.Rel(p.GetPackage().GetFingerPrint()+".package.tar"), - // image.ExtractFiles( - // cs.Options.Context, - // strings.TrimLeft(p.GetPackageDir(), "/"), - // p.GetIncludes(), - // p.GetExcludes(), - // ), - // ) - // TODO: Trim includes/excludes from "/" ? _, rootfs, err := image.Extract( cs.Options.Context, img, @@ -1090,7 +1077,31 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, generateF ht := NewHashTree(cs.Database) - packageHashTree, err := ht.Query(cs, p) + // When computing the hash tree, we need to take into consideration + // that packages that require final images have to be seen as packages without deps + // This is because we don't really want to calculate the deptree of them as + // as it is handled already when we are creating the images in resolveFinalImages(). + c := *cs + copy := &c + memDB := pkg.NewInMemoryDatabase(false) + // Create a copy to avoid races + dbCopy := pkg.NewInMemoryDatabase(false) + err := cs.Database.Clone(dbCopy) + if err != nil { + return nil, errors.Wrap(err, "failed cloning db") + } + for _, p := range dbCopy.World() { + copy := p.Clone() + spec, _ := cs.FromPackage(p) + if spec.RequiresFinalImages { + copy.Requires([]*pkg.DefaultPackage{}) + } + + memDB.CreatePackage(copy) + } + copy.Database = memDB + + packageHashTree, err := ht.Query(copy, p) if err != nil { return nil, errors.Wrap(err, "failed querying hashtree") } @@ -1148,6 +1159,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, generateF buildTarget := !cs.Options.OnlyDeps if buildDeps { + cs.Options.Context.Info(":deciduous_tree: Build dependencies for " + p.GetPackage().HumanReadableString()) for _, assertion := range dependencies { //highly dependent on the order depsN++ @@ -1163,6 +1175,7 @@ func (cs *LuetCompiler) compile(concurrency int, keepPermissions bool, generateF return nil, errors.Wrap(err, "Error while generating compilespec for "+assertion.Package.GetName()) } compileSpec.BuildOptions.PullImageRepository = append(compileSpec.BuildOptions.PullImageRepository, p.BuildOptions.PullImageRepository...) + cs.Options.Context.Debug("PullImage repos:", compileSpec.BuildOptions.PullImageRepository) compileSpec.SetOutputPath(p.GetOutputPath()) diff --git a/pkg/tree/compiler_recipe.go b/pkg/tree/compiler_recipe.go index 20d3057e..9f401742 100644 --- a/pkg/tree/compiler_recipe.go +++ b/pkg/tree/compiler_recipe.go @@ -174,6 +174,7 @@ func (r *CompilerRecipe) Load(path string) error { filepath.Dir(currentpath)) } pack.Requires(packbuild.GetRequires()) + pack.Conflicts(packbuild.GetConflicts()) } diff --git a/tests/fixtures/join_complex/c/c1/build.yaml b/tests/fixtures/join_complex/c/c1/build.yaml index 2f604fb5..30abbb23 100644 --- a/tests/fixtures/join_complex/c/c1/build.yaml +++ b/tests/fixtures/join_complex/c/c1/build.yaml @@ -6,4 +6,8 @@ requires: category: "test" version: ">=0" -requires_final_images: true \ No newline at end of file +requires_final_images: true + +steps: +- | + /bin/sh -c "if [ -e /usr/bin/generate.sh ]; then ls -liah /usr/bin && exit 1; fi" \ No newline at end of file diff --git a/tests/fixtures/join_complex/cat/b-1.1/build.yaml b/tests/fixtures/join_complex/cat/b-1.1/build.yaml index 62d26ddc..8eeca812 100644 --- a/tests/fixtures/join_complex/cat/b-1.1/build.yaml +++ b/tests/fixtures/join_complex/cat/b-1.1/build.yaml @@ -6,8 +6,9 @@ requires: prelude: - echo foo > /test - echo bar > /test2 + - cp -rf generate.sh /usr/bin/ steps: - echo artifact5 > /newc - echo artifact6 > /newnewc - chmod +x generate.sh - - ./generate.sh + - ./generate.sh \ No newline at end of file