Skip to content

Commit

Permalink
azlinux: Make sure we install /etc/os-release
Browse files Browse the repository at this point in the history
This is needed for scanners and other things and is just generally good
to have in the image.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Aug 2, 2024
1 parent 63f2350 commit f46a139
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions frontend/azlinux/azlinux3.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (w azlinux3) Install(pkgs []string, opts ...installOpt) llb.RunOption {
return dalec.WithRunOptions(tdnfInstall(&cfg, "3.0", pkgs), w.tdnfCacheMount(cfg.root))
}

func (w azlinux3) BasePackages() []string {
return []string{"azurelinux-release"}
}

func (azlinux3) DefaultImageConfig(ctx context.Context, resolver llb.ImageMetaResolver, platform *ocispecs.Platform) (*dalec.DockerImageSpec, error) {
_, _, dt, err := resolver.ResolveImageConfig(ctx, azlinux3DistrolessRef, sourceresolver.Opt{Platform: platform})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion frontend/azlinux/handle_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func specToContainerLLB(w worker, spec *dalec.Spec, targetKey string, rpmDir llb

if len(files) > 0 {
rpmMountDir := "/tmp/rpms"
updated := make([]string, 0, len(files))
updated := w.BasePackages()
for _, f := range files {
updated = append(updated, filepath.Join(rpmMountDir, f))
}
Expand Down
1 change: 1 addition & 0 deletions frontend/azlinux/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type worker interface {
Install(pkgs []string, opts ...installOpt) llb.RunOption
DefaultImageConfig(context.Context, llb.ImageMetaResolver, *ocispecs.Platform) (*dalec.DockerImageSpec, error)
WorkerImageConfig(context.Context, llb.ImageMetaResolver, *ocispecs.Platform) (*dalec.DockerImageSpec, error)
BasePackages() []string
}

func newHandler(w worker) gwclient.BuildFunc {
Expand Down
4 changes: 4 additions & 0 deletions frontend/azlinux/mariner2.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (w mariner2) Install(pkgs []string, opts ...installOpt) llb.RunOption {
return dalec.WithRunOptions(tdnfInstall(&cfg, "2.0", pkgs), w.tdnfCacheMount(cfg.root))
}

func (w mariner2) BasePackages() []string {
return []string{"mariner-release"}
}

func (mariner2) DefaultImageConfig(ctx context.Context, resolver llb.ImageMetaResolver, platform *ocispecs.Platform) (*dalec.DockerImageSpec, error) {
_, _, dt, err := resolver.ResolveImageConfig(ctx, mariner2DistrolessRef, sourceresolver.Opt{
Platform: platform,
Expand Down
31 changes: 30 additions & 1 deletion test/azlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestMariner2(t *testing.T) {
ContextName: azlinux.Mariner2WorkerContextName,
CreateRepo: azlinuxWithRepo,
},
Release: OSRelease{
ID: "mariner",
VersionID: "2.0",
},
})
}

Expand All @@ -62,6 +66,10 @@ func TestAzlinux3(t *testing.T) {
ContextName: azlinux.Azlinux3WorkerContextName,
CreateRepo: azlinuxWithRepo,
},
Release: OSRelease{
ID: "azurelinux",
VersionID: "3.0",
},
})
}

Expand Down Expand Up @@ -116,7 +124,13 @@ type testLinuxConfig struct {
Units string
Targets string
}
Worker workerConfig
Worker workerConfig
Release OSRelease
}

type OSRelease struct {
ID string
VersionID string
}

func testLinuxDistro(ctx context.Context, t *testing.T, testConfig testLinuxConfig) {
Expand Down Expand Up @@ -401,6 +415,21 @@ echo "$BAR" > bar.txt
{Command: "/src1", Stdout: dalec.CheckOutput{Equals: "hello world\n"}, Stderr: dalec.CheckOutput{Empty: true}},
},
},
{
Name: "Check /etc/os-release",
Files: map[string]dalec.FileCheckOutput{
"/etc/os-release": {
CheckOutput: dalec.CheckOutput{
Contains: []string{
fmt.Sprintf("ID=%s\n", testConfig.Release.ID),
// Note: the value of `VERSION_ID` needs to be quoted!
// TODO: Something is stripping the quotes here...
// fmt.Sprintf("VERSION_ID=%q\n", testConfig.Release.VersionID),
},
},
},
},
},
},
}

Expand Down

0 comments on commit f46a139

Please sign in to comment.