Skip to content

Commit db52491

Browse files
committed
azlinux: use weak dependency for prebuilt-ca-certificates
As it turns out, the previous "fix" was causing dnf to *always* choose `ca-certificates`, presumably because it is what it sees first in the package repo. By using a weak dependency we can allow the built package to depend on ca-certificates and ignore the prebuilt-ca-certificates but by default install the prebuilt ones. The end result of the previous case is we end up with bash and some other tools int he final image, which is undesirable. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
1 parent 9151f94 commit db52491

File tree

13 files changed

+149
-26
lines changed

13 files changed

+149
-26
lines changed

packaging/linux/rpm/template.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ BuildArch: noarch
3535
{{- .Provides -}}
3636
{{- .Replaces -}}
3737
{{- .Requires -}}
38+
{{- .Recommends -}}
3839
3940
%description
4041
{{.Description}}
@@ -188,6 +189,26 @@ func (w *specWrapper) Requires() fmt.Stringer {
188189
return b
189190
}
190191

192+
func (w *specWrapper) Recommends() fmt.Stringer {
193+
b := &strings.Builder{}
194+
deps := w.GetPackageDeps(w.Target)
195+
if deps == nil {
196+
return b
197+
}
198+
199+
if len(deps.Recommends) == 0 {
200+
return b
201+
}
202+
203+
keys := dalec.SortMapKeys(deps.Recommends)
204+
for _, name := range keys {
205+
constraints := deps.Recommends[name]
206+
writeDep(b, "Recommends", name, constraints)
207+
}
208+
b.WriteString("\n")
209+
return b
210+
}
211+
191212
func writeDep(b *strings.Builder, kind, name string, constraints dalec.PackageConstraints) {
192213
do := func() {
193214
if len(constraints.Version) == 0 {

targets/linux/rpm/almalinux/common.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,29 @@ var (
3030
func Handlers(ctx context.Context, client gwclient.Client, m *frontend.BuildMux) error {
3131
return frontend.LoadBuiltinTargets(targets)(ctx, client, m)
3232
}
33+
34+
func basePackages(name string) []dalec.Spec {
35+
const (
36+
base = "dalec-base-"
37+
license = "Apache-2.0"
38+
39+
version = "0.0.1"
40+
rev = "1"
41+
)
42+
43+
return []dalec.Spec{
44+
{
45+
Name: base + name,
46+
Version: version,
47+
Revision: rev,
48+
License: license,
49+
Description: "DALEC base packages for " + name,
50+
Dependencies: &dalec.PackageDependencies{
51+
Runtime: map[string]dalec.PackageConstraints{
52+
"almalinux-release": {},
53+
"tzdata": {},
54+
},
55+
},
56+
},
57+
}
58+
}

targets/linux/rpm/almalinux/v8.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var ConfigV8 = &distro.Config{
2424

2525
ReleaseVer: "8",
2626
BuilderPackages: builderPackages,
27-
BasePackages: []string{"almalinux-release", "tzdata"},
27+
BasePackages: basePackages(v8TargetKey),
2828
RepoPlatformConfig: &defaultPlatformConfig,
2929
InstallFunc: distro.DnfInstall,
3030
}

targets/linux/rpm/almalinux/v9.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var ConfigV9 = &distro.Config{
2424

2525
ReleaseVer: "9",
2626
BuilderPackages: builderPackages,
27-
BasePackages: []string{"almalinux-release", "tzdata"},
27+
BasePackages: basePackages(v9TargetKey),
2828
RepoPlatformConfig: &defaultPlatformConfig,
2929
InstallFunc: distro.DnfInstall,
3030
}

targets/linux/rpm/azlinux/azlinux3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var Azlinux3Config = &distro.Config{
2525

2626
ReleaseVer: "3.0",
2727
BuilderPackages: builderPackages,
28-
BasePackages: []string{"distroless-packages-minimal", "(prebuilt-ca-certificates or ca-certificates)"},
28+
BasePackages: basePackages(AzLinux3TargetKey),
2929
RepoPlatformConfig: &defaultAzlinuxRepoPlatform,
3030
InstallFunc: distro.TdnfInstall,
3131
}

targets/linux/rpm/azlinux/common.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,32 @@ var (
3131
func Handlers(ctx context.Context, client gwclient.Client, m *frontend.BuildMux) error {
3232
return frontend.LoadBuiltinTargets(targets)(ctx, client, m)
3333
}
34+
35+
func basePackages(name string) []dalec.Spec {
36+
const (
37+
distMin = "distroless-packages-minimal"
38+
prebuilt = "prebuilt-ca-certificates"
39+
base = "dalec-base-"
40+
license = "Apache-2.0"
41+
version = "0.0.1"
42+
rev = "1"
43+
)
44+
45+
return []dalec.Spec{
46+
{
47+
Name: base + name,
48+
Version: version,
49+
Revision: rev,
50+
License: license,
51+
Description: "DALEC base packages for " + name,
52+
Dependencies: &dalec.PackageDependencies{
53+
Runtime: map[string]dalec.PackageConstraints{
54+
distMin: {},
55+
},
56+
Recommends: map[string]dalec.PackageConstraints{
57+
prebuilt: {},
58+
},
59+
},
60+
},
61+
}
62+
}

targets/linux/rpm/azlinux/mariner2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Mariner2Config = &distro.Config{
2222

2323
ReleaseVer: "2.0",
2424
BuilderPackages: builderPackages,
25-
BasePackages: []string{"distroless-packages-minimal", "(prebuilt-ca-certificates or ca-certificates)"},
25+
BasePackages: basePackages(Mariner2TargetKey),
2626
RepoPlatformConfig: &defaultAzlinuxRepoPlatform,
2727
InstallFunc: distro.TdnfInstall,
2828
}

targets/linux/rpm/distro/container.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,17 @@ func (cfg *Config) BuildContainer(ctx context.Context, client gwclient.Client, w
5252

5353
if !skipBase && len(cfg.BasePackages) > 0 {
5454
opts := append(opts, dalec.ProgressGroup("Create base virtual package"))
55-
baseSpec := &dalec.Spec{
56-
Name: "dalec-base",
57-
Version: "0.0.1",
58-
License: "Apache-2.0",
59-
Revision: "1",
60-
Description: "Virtual package for including base packages",
61-
Dependencies: &dalec.PackageDependencies{
62-
Runtime: func() map[string]dalec.PackageConstraints {
63-
out := make(map[string]dalec.PackageConstraints, len(cfg.BasePackages))
64-
for _, pkg := range cfg.BasePackages {
65-
out[pkg] = dalec.PackageConstraints{}
66-
}
67-
return out
68-
}(),
69-
},
70-
}
7155

72-
basePkgs, err = cfg.BuildPkg(ctx, client, worker, sOpt, baseSpec, targetKey, opts...)
73-
if err != nil {
74-
return llb.Scratch(), errors.Wrap(err, "error building base runtime deps package")
56+
var basePkgStates []llb.State
57+
for _, spec := range cfg.BasePackages {
58+
pkg, err := cfg.BuildPkg(ctx, client, worker, sOpt, &spec, targetKey, opts...)
59+
if err != nil {
60+
return llb.Scratch(), errors.Wrap(err, "error building base runtime deps package")
61+
}
62+
basePkgStates = append(basePkgStates, pkg)
7563
}
7664

65+
basePkgs = dalec.MergeAtPath(basePkgs, basePkgStates, "/")
7766
pkgs = append(pkgs, filepath.Join(baseMountPath, "**/*.rpm"))
7867
}
7968

targets/linux/rpm/distro/distro.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Config struct {
2424
BuilderPackages []string
2525

2626
// Dependencies to install in base image
27-
BasePackages []string
27+
BasePackages []dalec.Spec
2828
RepoPlatformConfig *dalec.RepoPlatformConfig
2929

3030
DefaultOutputImage string

targets/linux/rpm/rockylinux/common.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,29 @@ var (
2929
func Handlers(ctx context.Context, client gwclient.Client, m *frontend.BuildMux) error {
3030
return frontend.LoadBuiltinTargets(targets)(ctx, client, m)
3131
}
32+
33+
func basePackages(name string) []dalec.Spec {
34+
const (
35+
base = "dalec-base-"
36+
license = "Apache-2.0"
37+
38+
version = "0.0.1"
39+
rev = "1"
40+
)
41+
42+
return []dalec.Spec{
43+
{
44+
Name: base + name,
45+
Version: version,
46+
Revision: rev,
47+
License: license,
48+
Description: "DALEC base packages for " + name,
49+
Dependencies: &dalec.PackageDependencies{
50+
Runtime: map[string]dalec.PackageConstraints{
51+
"rocky-release": {},
52+
"tzdata": {},
53+
},
54+
},
55+
},
56+
}
57+
}

0 commit comments

Comments
 (0)