From 12c80822f8c0ea93123e831729490eedb69af203 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 16 Feb 2026 10:51:49 +0100 Subject: [PATCH 1/5] test: target package instead of container where possible That should make tests more targetted for their intended scope. Signed-off-by: Mateusz Gozdek --- test/custom_repo_test.go | 6 ++-- test/linux_target_test.go | 64 ++++++++++++++++----------------- test/multiple_artifacts_test.go | 6 ++-- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/test/custom_repo_test.go b/test/custom_repo_test.go index 2183eb348..bf1188757 100644 --- a/test/custom_repo_test.go +++ b/test/custom_repo_test.go @@ -154,8 +154,7 @@ func testCustomRepo(ctx context.Context, t *testing.T, workerCfg workerConfig, t sr = newSolveRequest( withSpec(ctx, t, getSpec(depSpec, nil, repoPath, "public.key")), withBuildContext(ctx, t, "test-repo", repoState), - withBuildTarget(targetCfg.Container), - withPlatformPtr(workerCfg.Platform), + withBuildTarget(targetCfg.Package), ) _, err := gwc.Solve(ctx, sr) @@ -204,8 +203,7 @@ func testCustomRepo(ctx context.Context, t *testing.T, workerCfg workerConfig, t withSpec(ctx, t, spec), withBuildContext(ctx, t, "test-repo", repoState), withBuildContext(ctx, t, "repo-public-key", gpgKey), - withBuildTarget(targetCfg.Container), - withPlatformPtr(workerCfg.Platform), + withBuildTarget(targetCfg.Package), ) res := solveT(ctx, t, gwc, sr) diff --git a/test/linux_target_test.go b/test/linux_target_test.go index c7bd6a976..b97d281e0 100644 --- a/test/linux_target_test.go +++ b/test/linux_target_test.go @@ -167,7 +167,7 @@ func testLinuxDistro(ctx context.Context, t *testing.T, testConfig testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget(testConfig.Target.Container)) + sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget(testConfig.Target.Package)) sr.Evaluate = true _, err := gwc.Solve(ctx, sr) var xErr *moby_buildkit_v1_frontend.ExitError @@ -252,7 +252,7 @@ echo "$BAR" > bar.txt testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Container), + withBuildTarget(testConfig.Target.Package), ) solveT(ctx, t, gwc, sr) }) @@ -489,7 +489,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Container), + withBuildTarget(testConfig.Target.Package), withBuildContext(ctx, t, patchContextName, patchContext), ) sr.Evaluate = true @@ -538,7 +538,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Container), + withBuildTarget(testConfig.Target.Package), ) solveT(ctx, t, gwc, sr) }) @@ -616,7 +616,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Container), + withBuildTarget(testConfig.Target.Package), ) solveT(ctx, t, gwc, sr) }) @@ -708,7 +708,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Container), + withBuildTarget(testConfig.Target.Package), ) solveT(ctx, t, gwc, sr) }) @@ -1828,7 +1828,7 @@ WantedBy=multi-user.target } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) @@ -1854,7 +1854,7 @@ WantedBy=multi-user.target } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) @@ -1883,7 +1883,7 @@ WantedBy=multi-user.target } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -1999,7 +1999,7 @@ Environment="FOO_ARGS=--some-foo-args" } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2056,7 +2056,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2110,7 +2110,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2177,7 +2177,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2259,7 +2259,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2327,7 +2327,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2406,7 +2406,7 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2472,7 +2472,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2556,7 +2556,7 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2631,7 +2631,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2702,7 +2702,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) req.Evaluate = true solveT(ctx, t, client, req) }) @@ -2757,7 +2757,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2810,7 +2810,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -3289,7 +3289,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - sr := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + sr := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) sr.Evaluate = true solveT(ctx, t, client, sr) }) @@ -3416,7 +3416,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - sr := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) + sr := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) sr.Evaluate = true solveT(ctx, t, client, sr) }) @@ -3632,7 +3632,7 @@ func testNodeNpmGenerator(ctx context.Context, t *testing.T, targetCfg targetCon } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - reqOpts := append([]srOpt{withBuildTarget(targetCfg.Container), withSpec(ctx, t, spec)}, opts...) + reqOpts := append([]srOpt{withBuildTarget(targetCfg.Package), withSpec(ctx, t, spec)}, opts...) req := newSolveRequest(reqOpts...) solveT(ctx, t, client, req) }) @@ -3679,7 +3679,7 @@ func testCustomLinuxWorker(ctx context.Context, t *testing.T, targetCfg targetCo } // Make sure the built-in worker can't build this package - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Container)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Package)) _, err := gwc.Solve(ctx, sr) if err == nil { t.Fatal("expected solve to fail") @@ -3708,7 +3708,7 @@ func testCustomLinuxWorker(ctx context.Context, t *testing.T, targetCfg targetCo // Now build again with our custom worker // Note, we are solving the main spec, not depSpec here. - sr = newSolveRequest(withSpec(ctx, t, spec), withBuildContext(ctx, t, workerCfg.ContextName, worker), withBuildTarget(targetCfg.Container)) + sr = newSolveRequest(withSpec(ctx, t, spec), withBuildContext(ctx, t, workerCfg.ContextName, worker), withBuildTarget(targetCfg.Package)) solveT(ctx, t, gwc, sr) // TODO: we should have a test to make sure this also works with source policies. @@ -3905,7 +3905,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) res := solveT(ctx, t, gwc, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -3960,7 +3960,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) res := solveT(ctx, t, gwc, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -4027,7 +4027,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) res := solveT(ctx, t, gwc, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -4071,7 +4071,7 @@ func testLinuxSymlinkArtifacts(ctx context.Context, t *testing.T, cfg testLinuxC } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) res := solveT(ctx, t, client, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -4323,7 +4323,7 @@ func testLinuxPackageTestsFail(ctx context.Context, t *testing.T, cfg testLinuxC } t.Run("package", testForTarget(cfg.Target.Package)) - t.Run("container", testForTarget(cfg.Target.Container)) + t.Run("container", testForTarget(cfg.Target.Package)) }) t.Run("positive test", func(t *testing.T) { diff --git a/test/multiple_artifacts_test.go b/test/multiple_artifacts_test.go index 2452f44fa..1082384f2 100644 --- a/test/multiple_artifacts_test.go +++ b/test/multiple_artifacts_test.go @@ -31,7 +31,7 @@ func testEmptyArtifacts(ctx context.Context, t *testing.T, targetCfg targetConfi t.Run("primary", func(t *testing.T) { t.Parallel() testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Container)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Package)) solveT(ctx, t, gwc, sr) }) }) @@ -39,7 +39,7 @@ func testEmptyArtifacts(ctx context.Context, t *testing.T, targetCfg targetConfi // testArtifactsAtSpecLevel tests that artifacts defined in spec.artifacts are built and tested. func testArtifactsAtSpecLevel(ctx context.Context, t *testing.T, targetCfg targetConfig) { - vals := strings.Split(targetCfg.Container, "/") + vals := strings.Split(targetCfg.Package, "/") primaryTarget := vals[0] spec := &dalec.Spec{ @@ -86,7 +86,7 @@ func testArtifactsAtSpecLevel(ctx context.Context, t *testing.T, targetCfg targe // testMultipleArtifacts tests that a package with multiple artifacts defined in spec.target takes precedent over spec.artifacts func testTargetArtifactsTakePrecedence(ctx context.Context, t *testing.T, targetCfg targetConfig) { // get the target we want to test for - vals := strings.Split(targetCfg.Container, "/") + vals := strings.Split(targetCfg.Package, "/") primaryTarget := vals[0] // prevent primaryTarget from being the same as secondaryTarget or tertiaryTarget secondaryTarget := "mariner2" From 53b3619618ce51df8f13ff5ee6981eb4a04e79a5 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 16 Feb 2026 17:43:49 +0100 Subject: [PATCH 2/5] targets/linux/deb/distro/container.go: refactor for bootstrapped containers Signed-off-by: Mateusz Gozdek --- targets/linux/deb/distro/container.go | 164 ++++++++++++++++---------- 1 file changed, 104 insertions(+), 60 deletions(-) diff --git a/targets/linux/deb/distro/container.go b/targets/linux/deb/distro/container.go index b1701fcb6..2957d13bc 100644 --- a/targets/linux/deb/distro/container.go +++ b/targets/linux/deb/distro/container.go @@ -13,81 +13,125 @@ import ( func (c *Config) BuildContainer(ctx context.Context, client gwclient.Client, sOpt dalec.SourceOpts, spec *dalec.Spec, targetKey string, debSt llb.State, opts ...llb.ConstraintsOpt) llb.State { opts = append(opts, frontend.IgnoreCache(client), dalec.ProgressGroup("Build Container Image")) - baseImg := llb.Image(c.DefaultOutputImage, llb.WithMetaResolver(sOpt.Resolver), dalec.WithConstraints(opts...)) - - bi, err := spec.GetSingleBase(targetKey) - if err != nil { - return dalec.ErrorState(llb.Scratch(), err) + input := buildContainerInput{ + Config: c, + Client: client, + Worker: c.Worker(sOpt, dalec.Platform(sOpt.TargetPlatform), dalec.WithConstraints(opts...)), + SOpt: sOpt, + Spec: spec, + Target: targetKey, + SpecPackages: debSt, + Opts: opts, } - if bi != nil { - baseImg = bi.ToState(sOpt, opts...) - } - - // Those base repos come from distro configuration. - repos := dalec.GetExtraRepos(c.ExtraRepos, "install") - - // These are user specified via spec. - repos = append(repos, spec.GetInstallRepos(targetKey)...) - - withRepos := c.RepoMounts(repos, sOpt, opts...) - - debug := llb.Scratch().File(llb.Mkfile("debug", 0o644, []byte(`debug=2`)), opts...) - opts = append(opts, dalec.ProgressGroup("Install spec package")) + baseImg := baseImageFromSpec(llb.Image(c.DefaultOutputImage, llb.WithMetaResolver(sOpt.Resolver), dalec.WithConstraints(opts...)), input) - // If we have base packages to install, create a meta-package to install them. if len(c.BasePackages) > 0 { - runtimePkgs := make(dalec.PackageDependencyList, len(c.BasePackages)) - for _, pkgName := range c.BasePackages { - runtimePkgs[pkgName] = dalec.PackageConstraints{} - } - basePkgSpec := &dalec.Spec{ - Name: "dalec-deb-base-packages", - Packager: "dalec", - Description: "Base Packages for Debian-based Distros", - Version: "0.1", - Revision: "1", - Dependencies: &dalec.PackageDependencies{ - Runtime: runtimePkgs, - }, - } - - basePkg := c.BuildPkg(ctx, client, sOpt, basePkgSpec, targetKey, opts...) + opts = append(opts, dalec.ProgressGroup("Install base image packages")) // Update the base image to include the base packages. // This may include things that are necessary to even install the debSt package. // So this must be done separately from the debSt package. - opts := append(opts, dalec.ProgressGroup("Install base image packages")) baseImg = baseImg.Run( dalec.WithConstraints(opts...), - InstallLocalPkg(basePkg, true, opts...), + InstallLocalPkg(basePackages(ctx, input), true, opts...), dalec.WithMountedAptCache(c.AptCachePrefix, opts...), + frontend.IgnoreCache(client, targets.IgnoreCacheKeyContainer), ).Root() } - worker := c.Worker(sOpt, dalec.Platform(sOpt.TargetPlatform), dalec.WithConstraints(opts...)) + return installPackagesInContainer(baseImg, input, []llb.RunOption{ + dalec.WithMountedAptCache(input.Config.AptCachePrefix, opts...), + InstallLocalPkg(debSt, true, opts...), + }) +} + +func baseImageFromSpec(baseImg llb.State, input buildContainerInput) llb.State { + bi, err := input.Spec.GetSingleBase(input.Target) + if err != nil { + return dalec.ErrorState(llb.Scratch(), err) + } + + if bi == nil { + return baseImg + } + + return bi.ToState(input.SOpt, input.Opts...) +} + +func basePackages(ctx context.Context, input buildContainerInput) llb.State { + if len(input.Config.BasePackages) == 0 { + return llb.Scratch() + } + + // If we have base packages to install, create a meta-package to install them. + runtimePkgs := make(dalec.PackageDependencyList, len(input.Config.BasePackages)) + for _, pkgName := range input.Config.BasePackages { + runtimePkgs[pkgName] = dalec.PackageConstraints{} + } + basePkgSpec := &dalec.Spec{ + Name: "dalec-deb-base-packages", + Packager: "dalec", + Description: "Base Packages for Debian-based Distros", + Version: "0.1", + Revision: "1", + Dependencies: &dalec.PackageDependencies{ + Runtime: runtimePkgs, + }, + } + + opts := append(input.Opts, dalec.ProgressGroup("Install base image packages")) + + return input.Config.BuildPkg(ctx, input.Client, input.SOpt, basePkgSpec, input.Target, opts...) +} + +type buildContainerInput struct { + Config *Config + Client gwclient.Client + Worker llb.State + SOpt dalec.SourceOpts + Spec *dalec.Spec + Target string + SpecPackages llb.State + Opts []llb.ConstraintsOpt +} + +func extraRepos(input buildContainerInput) llb.RunOption { + // Those base repos come from distro configuration. + repos := dalec.GetExtraRepos(input.Config.ExtraRepos, "install") + + // These are user specified via spec. + repos = append(repos, input.Spec.GetInstallRepos(input.Target)...) + + return input.Config.RepoMounts(repos, input.SOpt, input.Opts...) +} + +func installPackagesInContainer(baseImg llb.State, input buildContainerInput, ro []llb.RunOption) llb.State { + opts := append(input.Opts, dalec.ProgressGroup("Install DEB Packages")) + + debug := llb.Scratch().File(llb.Mkfile("debug", 0o644, []byte(`debug=2`)), opts...) return baseImg.Run( - dalec.WithConstraints(opts...), - withRepos, - dalec.WithMountedAptCache(c.AptCachePrefix, opts...), - // This file makes dpkg give more verbose output which can be useful when things go awry. - llb.AddMount("/etc/dpkg/dpkg.cfg.d/99-dalec-debug", debug, llb.SourcePath("debug"), llb.Readonly), - dalec.RunOptFunc(func(cfg *llb.ExecInfo) { - // Warning: HACK here - // The base ubuntu image has this `excludes` config file which prevents - // installation of a lot of things, including doc files. - // This is mounting over that file with an empty file so that our test suite - // passes (as it is looking at these files). - if !spec.GetArtifacts(targetKey).HasDocs() { - return - } - - tmp := llb.Scratch().File(llb.Mkfile("tmp", 0o644, nil), opts...) - llb.AddMount("/etc/dpkg/dpkg.cfg.d/excludes", tmp, llb.SourcePath("tmp")).SetRunOption(cfg) - }), - InstallLocalPkg(debSt, true, opts...), - frontend.IgnoreCache(client, targets.IgnoreCacheKeyContainer), + append(ro, + dalec.WithConstraints(opts...), + extraRepos(input), + // This file makes dpkg give more verbose output which can be useful when things go awry. + llb.AddMount("/etc/dpkg/dpkg.cfg.d/99-dalec-debug", debug, llb.SourcePath("debug"), llb.Readonly), + dalec.RunOptFunc(func(cfg *llb.ExecInfo) { + // Warning: HACK here + // The base ubuntu image has this `excludes` config file which prevents + // installation of a lot of things, including doc files. + // This is mounting over that file with an empty file so that our test suite + // passes (as it is looking at these files). + if !input.Spec.GetArtifacts(input.Target).HasDocs() { + return + } + + tmp := llb.Scratch().File(llb.Mkfile("tmp", 0o644, nil), opts...) + llb.AddMount("/etc/dpkg/dpkg.cfg.d/excludes", tmp, llb.SourcePath("tmp")).SetRunOption(cfg) + }), + frontend.IgnoreCache(input.Client, targets.IgnoreCacheKeyContainer), + )..., ).Root(). - With(dalec.InstallPostSymlinks(spec.GetImagePost(targetKey), worker, opts...)) + With(dalec.InstallPostSymlinks(input.Spec.GetImagePost(input.Target), input.Worker, opts...)) } From 6a531969a941fe5fc828f7d564e22a6261fad962 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Tue, 17 Feb 2026 06:56:24 +0100 Subject: [PATCH 3/5] Revert "test: target package instead of container where possible" This reverts commit 12c80822f8c0ea93123e831729490eedb69af203. --- test/custom_repo_test.go | 6 ++-- test/linux_target_test.go | 64 ++++++++++++++++----------------- test/multiple_artifacts_test.go | 6 ++-- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/test/custom_repo_test.go b/test/custom_repo_test.go index bf1188757..2183eb348 100644 --- a/test/custom_repo_test.go +++ b/test/custom_repo_test.go @@ -154,7 +154,8 @@ func testCustomRepo(ctx context.Context, t *testing.T, workerCfg workerConfig, t sr = newSolveRequest( withSpec(ctx, t, getSpec(depSpec, nil, repoPath, "public.key")), withBuildContext(ctx, t, "test-repo", repoState), - withBuildTarget(targetCfg.Package), + withBuildTarget(targetCfg.Container), + withPlatformPtr(workerCfg.Platform), ) _, err := gwc.Solve(ctx, sr) @@ -203,7 +204,8 @@ func testCustomRepo(ctx context.Context, t *testing.T, workerCfg workerConfig, t withSpec(ctx, t, spec), withBuildContext(ctx, t, "test-repo", repoState), withBuildContext(ctx, t, "repo-public-key", gpgKey), - withBuildTarget(targetCfg.Package), + withBuildTarget(targetCfg.Container), + withPlatformPtr(workerCfg.Platform), ) res := solveT(ctx, t, gwc, sr) diff --git a/test/linux_target_test.go b/test/linux_target_test.go index b97d281e0..c7bd6a976 100644 --- a/test/linux_target_test.go +++ b/test/linux_target_test.go @@ -167,7 +167,7 @@ func testLinuxDistro(ctx context.Context, t *testing.T, testConfig testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget(testConfig.Target.Package)) + sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget(testConfig.Target.Container)) sr.Evaluate = true _, err := gwc.Solve(ctx, sr) var xErr *moby_buildkit_v1_frontend.ExitError @@ -252,7 +252,7 @@ echo "$BAR" > bar.txt testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Package), + withBuildTarget(testConfig.Target.Container), ) solveT(ctx, t, gwc, sr) }) @@ -489,7 +489,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Package), + withBuildTarget(testConfig.Target.Container), withBuildContext(ctx, t, patchContextName, patchContext), ) sr.Evaluate = true @@ -538,7 +538,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Package), + withBuildTarget(testConfig.Target.Container), ) solveT(ctx, t, gwc, sr) }) @@ -616,7 +616,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Package), + withBuildTarget(testConfig.Target.Container), ) solveT(ctx, t, gwc, sr) }) @@ -708,7 +708,7 @@ index 0000000..5260cb1 testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { sr := newSolveRequest( withSpec(ctx, t, &spec), - withBuildTarget(testConfig.Target.Package), + withBuildTarget(testConfig.Target.Container), ) solveT(ctx, t, gwc, sr) }) @@ -1828,7 +1828,7 @@ WantedBy=multi-user.target } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) @@ -1854,7 +1854,7 @@ WantedBy=multi-user.target } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) @@ -1883,7 +1883,7 @@ WantedBy=multi-user.target } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -1999,7 +1999,7 @@ Environment="FOO_ARGS=--some-foo-args" } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2056,7 +2056,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2110,7 +2110,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2177,7 +2177,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2259,7 +2259,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2327,7 +2327,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2406,7 +2406,7 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2472,7 +2472,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2556,7 +2556,7 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2631,7 +2631,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) solveT(ctx, t, client, req) }) }) @@ -2702,7 +2702,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt)) req.Evaluate = true solveT(ctx, t, client, req) }) @@ -2757,7 +2757,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -2810,7 +2810,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) solveT(ctx, t, client, req) }) }) @@ -3289,7 +3289,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - sr := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + sr := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) sr.Evaluate = true solveT(ctx, t, client, sr) }) @@ -3416,7 +3416,7 @@ func main() { } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - sr := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec)) + sr := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec)) sr.Evaluate = true solveT(ctx, t, client, sr) }) @@ -3632,7 +3632,7 @@ func testNodeNpmGenerator(ctx context.Context, t *testing.T, targetCfg targetCon } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - reqOpts := append([]srOpt{withBuildTarget(targetCfg.Package), withSpec(ctx, t, spec)}, opts...) + reqOpts := append([]srOpt{withBuildTarget(targetCfg.Container), withSpec(ctx, t, spec)}, opts...) req := newSolveRequest(reqOpts...) solveT(ctx, t, client, req) }) @@ -3679,7 +3679,7 @@ func testCustomLinuxWorker(ctx context.Context, t *testing.T, targetCfg targetCo } // Make sure the built-in worker can't build this package - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Package)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Container)) _, err := gwc.Solve(ctx, sr) if err == nil { t.Fatal("expected solve to fail") @@ -3708,7 +3708,7 @@ func testCustomLinuxWorker(ctx context.Context, t *testing.T, targetCfg targetCo // Now build again with our custom worker // Note, we are solving the main spec, not depSpec here. - sr = newSolveRequest(withSpec(ctx, t, spec), withBuildContext(ctx, t, workerCfg.ContextName, worker), withBuildTarget(targetCfg.Package)) + sr = newSolveRequest(withSpec(ctx, t, spec), withBuildContext(ctx, t, workerCfg.ContextName, worker), withBuildTarget(targetCfg.Container)) solveT(ctx, t, gwc, sr) // TODO: we should have a test to make sure this also works with source policies. @@ -3905,7 +3905,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) res := solveT(ctx, t, gwc, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -3960,7 +3960,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) res := solveT(ctx, t, gwc, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -4027,7 +4027,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf } testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) res := solveT(ctx, t, gwc, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -4071,7 +4071,7 @@ func testLinuxSymlinkArtifacts(ctx context.Context, t *testing.T, cfg testLinuxC } testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container)) res := solveT(ctx, t, client, sr) _, err := res.SingleRef() assert.NilError(t, err) @@ -4323,7 +4323,7 @@ func testLinuxPackageTestsFail(ctx context.Context, t *testing.T, cfg testLinuxC } t.Run("package", testForTarget(cfg.Target.Package)) - t.Run("container", testForTarget(cfg.Target.Package)) + t.Run("container", testForTarget(cfg.Target.Container)) }) t.Run("positive test", func(t *testing.T) { diff --git a/test/multiple_artifacts_test.go b/test/multiple_artifacts_test.go index 1082384f2..2452f44fa 100644 --- a/test/multiple_artifacts_test.go +++ b/test/multiple_artifacts_test.go @@ -31,7 +31,7 @@ func testEmptyArtifacts(ctx context.Context, t *testing.T, targetCfg targetConfi t.Run("primary", func(t *testing.T) { t.Parallel() testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) { - sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Package)) + sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Container)) solveT(ctx, t, gwc, sr) }) }) @@ -39,7 +39,7 @@ func testEmptyArtifacts(ctx context.Context, t *testing.T, targetCfg targetConfi // testArtifactsAtSpecLevel tests that artifacts defined in spec.artifacts are built and tested. func testArtifactsAtSpecLevel(ctx context.Context, t *testing.T, targetCfg targetConfig) { - vals := strings.Split(targetCfg.Package, "/") + vals := strings.Split(targetCfg.Container, "/") primaryTarget := vals[0] spec := &dalec.Spec{ @@ -86,7 +86,7 @@ func testArtifactsAtSpecLevel(ctx context.Context, t *testing.T, targetCfg targe // testMultipleArtifacts tests that a package with multiple artifacts defined in spec.target takes precedent over spec.artifacts func testTargetArtifactsTakePrecedence(ctx context.Context, t *testing.T, targetCfg targetConfig) { // get the target we want to test for - vals := strings.Split(targetCfg.Package, "/") + vals := strings.Split(targetCfg.Container, "/") primaryTarget := vals[0] // prevent primaryTarget from being the same as secondaryTarget or tertiaryTarget secondaryTarget := "mariner2" From 85bd19c8f211aba18fc7c0a128e5d774092b1a9b Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Tue, 17 Feb 2026 06:56:28 +0100 Subject: [PATCH 4/5] Revert "targets/linux/deb/distro/container.go: refactor for bootstrapped containers" This reverts commit 53b3619618ce51df8f13ff5ee6981eb4a04e79a5. --- targets/linux/deb/distro/container.go | 164 ++++++++++---------------- 1 file changed, 60 insertions(+), 104 deletions(-) diff --git a/targets/linux/deb/distro/container.go b/targets/linux/deb/distro/container.go index 2957d13bc..b1701fcb6 100644 --- a/targets/linux/deb/distro/container.go +++ b/targets/linux/deb/distro/container.go @@ -13,125 +13,81 @@ import ( func (c *Config) BuildContainer(ctx context.Context, client gwclient.Client, sOpt dalec.SourceOpts, spec *dalec.Spec, targetKey string, debSt llb.State, opts ...llb.ConstraintsOpt) llb.State { opts = append(opts, frontend.IgnoreCache(client), dalec.ProgressGroup("Build Container Image")) - input := buildContainerInput{ - Config: c, - Client: client, - Worker: c.Worker(sOpt, dalec.Platform(sOpt.TargetPlatform), dalec.WithConstraints(opts...)), - SOpt: sOpt, - Spec: spec, - Target: targetKey, - SpecPackages: debSt, - Opts: opts, + baseImg := llb.Image(c.DefaultOutputImage, llb.WithMetaResolver(sOpt.Resolver), dalec.WithConstraints(opts...)) + + bi, err := spec.GetSingleBase(targetKey) + if err != nil { + return dalec.ErrorState(llb.Scratch(), err) } - baseImg := baseImageFromSpec(llb.Image(c.DefaultOutputImage, llb.WithMetaResolver(sOpt.Resolver), dalec.WithConstraints(opts...)), input) + if bi != nil { + baseImg = bi.ToState(sOpt, opts...) + } + + // Those base repos come from distro configuration. + repos := dalec.GetExtraRepos(c.ExtraRepos, "install") + + // These are user specified via spec. + repos = append(repos, spec.GetInstallRepos(targetKey)...) + + withRepos := c.RepoMounts(repos, sOpt, opts...) + + debug := llb.Scratch().File(llb.Mkfile("debug", 0o644, []byte(`debug=2`)), opts...) + opts = append(opts, dalec.ProgressGroup("Install spec package")) + // If we have base packages to install, create a meta-package to install them. if len(c.BasePackages) > 0 { - opts = append(opts, dalec.ProgressGroup("Install base image packages")) + runtimePkgs := make(dalec.PackageDependencyList, len(c.BasePackages)) + for _, pkgName := range c.BasePackages { + runtimePkgs[pkgName] = dalec.PackageConstraints{} + } + basePkgSpec := &dalec.Spec{ + Name: "dalec-deb-base-packages", + Packager: "dalec", + Description: "Base Packages for Debian-based Distros", + Version: "0.1", + Revision: "1", + Dependencies: &dalec.PackageDependencies{ + Runtime: runtimePkgs, + }, + } + + basePkg := c.BuildPkg(ctx, client, sOpt, basePkgSpec, targetKey, opts...) // Update the base image to include the base packages. // This may include things that are necessary to even install the debSt package. // So this must be done separately from the debSt package. + opts := append(opts, dalec.ProgressGroup("Install base image packages")) baseImg = baseImg.Run( dalec.WithConstraints(opts...), - InstallLocalPkg(basePackages(ctx, input), true, opts...), + InstallLocalPkg(basePkg, true, opts...), dalec.WithMountedAptCache(c.AptCachePrefix, opts...), - frontend.IgnoreCache(client, targets.IgnoreCacheKeyContainer), ).Root() } - return installPackagesInContainer(baseImg, input, []llb.RunOption{ - dalec.WithMountedAptCache(input.Config.AptCachePrefix, opts...), - InstallLocalPkg(debSt, true, opts...), - }) -} - -func baseImageFromSpec(baseImg llb.State, input buildContainerInput) llb.State { - bi, err := input.Spec.GetSingleBase(input.Target) - if err != nil { - return dalec.ErrorState(llb.Scratch(), err) - } - - if bi == nil { - return baseImg - } - - return bi.ToState(input.SOpt, input.Opts...) -} - -func basePackages(ctx context.Context, input buildContainerInput) llb.State { - if len(input.Config.BasePackages) == 0 { - return llb.Scratch() - } - - // If we have base packages to install, create a meta-package to install them. - runtimePkgs := make(dalec.PackageDependencyList, len(input.Config.BasePackages)) - for _, pkgName := range input.Config.BasePackages { - runtimePkgs[pkgName] = dalec.PackageConstraints{} - } - basePkgSpec := &dalec.Spec{ - Name: "dalec-deb-base-packages", - Packager: "dalec", - Description: "Base Packages for Debian-based Distros", - Version: "0.1", - Revision: "1", - Dependencies: &dalec.PackageDependencies{ - Runtime: runtimePkgs, - }, - } - - opts := append(input.Opts, dalec.ProgressGroup("Install base image packages")) - - return input.Config.BuildPkg(ctx, input.Client, input.SOpt, basePkgSpec, input.Target, opts...) -} - -type buildContainerInput struct { - Config *Config - Client gwclient.Client - Worker llb.State - SOpt dalec.SourceOpts - Spec *dalec.Spec - Target string - SpecPackages llb.State - Opts []llb.ConstraintsOpt -} - -func extraRepos(input buildContainerInput) llb.RunOption { - // Those base repos come from distro configuration. - repos := dalec.GetExtraRepos(input.Config.ExtraRepos, "install") - - // These are user specified via spec. - repos = append(repos, input.Spec.GetInstallRepos(input.Target)...) - - return input.Config.RepoMounts(repos, input.SOpt, input.Opts...) -} - -func installPackagesInContainer(baseImg llb.State, input buildContainerInput, ro []llb.RunOption) llb.State { - opts := append(input.Opts, dalec.ProgressGroup("Install DEB Packages")) - - debug := llb.Scratch().File(llb.Mkfile("debug", 0o644, []byte(`debug=2`)), opts...) + worker := c.Worker(sOpt, dalec.Platform(sOpt.TargetPlatform), dalec.WithConstraints(opts...)) return baseImg.Run( - append(ro, - dalec.WithConstraints(opts...), - extraRepos(input), - // This file makes dpkg give more verbose output which can be useful when things go awry. - llb.AddMount("/etc/dpkg/dpkg.cfg.d/99-dalec-debug", debug, llb.SourcePath("debug"), llb.Readonly), - dalec.RunOptFunc(func(cfg *llb.ExecInfo) { - // Warning: HACK here - // The base ubuntu image has this `excludes` config file which prevents - // installation of a lot of things, including doc files. - // This is mounting over that file with an empty file so that our test suite - // passes (as it is looking at these files). - if !input.Spec.GetArtifacts(input.Target).HasDocs() { - return - } - - tmp := llb.Scratch().File(llb.Mkfile("tmp", 0o644, nil), opts...) - llb.AddMount("/etc/dpkg/dpkg.cfg.d/excludes", tmp, llb.SourcePath("tmp")).SetRunOption(cfg) - }), - frontend.IgnoreCache(input.Client, targets.IgnoreCacheKeyContainer), - )..., + dalec.WithConstraints(opts...), + withRepos, + dalec.WithMountedAptCache(c.AptCachePrefix, opts...), + // This file makes dpkg give more verbose output which can be useful when things go awry. + llb.AddMount("/etc/dpkg/dpkg.cfg.d/99-dalec-debug", debug, llb.SourcePath("debug"), llb.Readonly), + dalec.RunOptFunc(func(cfg *llb.ExecInfo) { + // Warning: HACK here + // The base ubuntu image has this `excludes` config file which prevents + // installation of a lot of things, including doc files. + // This is mounting over that file with an empty file so that our test suite + // passes (as it is looking at these files). + if !spec.GetArtifacts(targetKey).HasDocs() { + return + } + + tmp := llb.Scratch().File(llb.Mkfile("tmp", 0o644, nil), opts...) + llb.AddMount("/etc/dpkg/dpkg.cfg.d/excludes", tmp, llb.SourcePath("tmp")).SetRunOption(cfg) + }), + InstallLocalPkg(debSt, true, opts...), + frontend.IgnoreCache(client, targets.IgnoreCacheKeyContainer), ).Root(). - With(dalec.InstallPostSymlinks(input.Spec.GetImagePost(input.Target), input.Worker, opts...)) + With(dalec.InstallPostSymlinks(spec.GetImagePost(targetKey), worker, opts...)) } From 78e6bb1042e181449bbe2b52a25e75f267398d2b Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Tue, 17 Feb 2026 06:59:23 +0100 Subject: [PATCH 5/5] tmp Signed-off-by: Mateusz Gozdek --- targets/linux/deb/distro/container.go | 1 + 1 file changed, 1 insertion(+) diff --git a/targets/linux/deb/distro/container.go b/targets/linux/deb/distro/container.go index b1701fcb6..374c2f878 100644 --- a/targets/linux/deb/distro/container.go +++ b/targets/linux/deb/distro/container.go @@ -10,6 +10,7 @@ import ( "github.com/project-dalec/dalec/targets" ) +// test func (c *Config) BuildContainer(ctx context.Context, client gwclient.Client, sOpt dalec.SourceOpts, spec *dalec.Spec, targetKey string, debSt llb.State, opts ...llb.ConstraintsOpt) llb.State { opts = append(opts, frontend.IgnoreCache(client), dalec.ProgressGroup("Build Container Image"))