Skip to content

Commit 565c033

Browse files
committed
mariner2: Use empty rootfs for default contaienr
Before this we were using the distroless image's rootfs as the base for the output container. With this change an empty rootfs is used unless the spec has an image specified. Signed-off-by: Brian Goff <[email protected]>
1 parent db22914 commit 565c033

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

frontend/mariner2/handle_container.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/Azure/dalec/frontend"
1212
"github.com/moby/buildkit/client/llb"
1313
gwclient "github.com/moby/buildkit/frontend/gateway/client"
14+
"github.com/moby/buildkit/util/bklog"
1415
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1516
)
1617

@@ -33,7 +34,7 @@ func handleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Res
3334
}
3435

3536
worker := getWorkerImage(client, pg)
36-
st, err := specToContainerLLB(spec, targetKey, worker, rpmDir, sOpt, pg)
37+
st, err := specToContainerLLB(ctx, spec, targetKey, worker, rpmDir, sOpt, pg)
3738
if err != nil {
3839
return nil, nil, err
3940
}
@@ -69,7 +70,7 @@ func handleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Res
6970
})
7071
}
7172

72-
func specToContainerLLB(spec *dalec.Spec, target string, builderImg llb.State, rpmDir llb.State, sOpt dalec.SourceOpts, opts ...llb.ConstraintsOpt) (llb.State, error) {
73+
func specToContainerLLB(ctx context.Context, spec *dalec.Spec, target string, builderImg llb.State, rpmDir llb.State, sOpt dalec.SourceOpts, opts ...llb.ConstraintsOpt) (llb.State, error) {
7374
opts = append(opts, dalec.ProgressGroup("Install RPMs"))
7475
const workPath = "/tmp/rootfs"
7576

@@ -126,7 +127,13 @@ rm -rf ` + rpmdbDir + `
126127

127128
installer := llb.Scratch().File(llb.Mkfile("install.sh", 0o755, []byte(installCmd)), opts...)
128129

129-
baseImg := llb.Image(frontend.GetBaseOutputImage(spec, target, marinerDistrolessRef), llb.WithMetaResolver(sOpt.Resolver), dalec.WithConstraints(opts...))
130+
baseImg := llb.Scratch()
131+
132+
baseRef := frontend.GetBaseOutputImage(spec, target, "")
133+
if baseRef != "" {
134+
bklog.G(ctx).WithField("baseRef", baseRef).Debugf("Using custom base image rootfs")
135+
baseImg = llb.Image(baseRef, llb.WithMetaResolver(sOpt.Resolver), dalec.WithConstraints(opts...))
136+
}
130137
worker := builderImg.
131138
Run(
132139
shArgs("/tmp/install.sh"),

frontend/mariner2/handle_depsonly.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func handleDepsOnly(ctx context.Context, client gwclient.Client) (*gwclient.Resu
2626
if err != nil {
2727
return nil, nil, err
2828
}
29-
st, err := specToContainerLLB(spec, targetKey, baseImg, rpmDir, sOpt, pg)
29+
st, err := specToContainerLLB(ctx, spec, targetKey, baseImg, rpmDir, sOpt, pg)
3030
if err != nil {
3131
return nil, nil, err
3232
}

0 commit comments

Comments
 (0)