Skip to content

Commit

Permalink
Merge pull request #5161 from nalind/never-empty-squash-confidential
Browse files Browse the repository at this point in the history
Never omit layers for emptyLayer instructions when squashing/cwing
  • Loading branch information
openshift-merge-bot[bot] authored Nov 17, 2023
2 parents 8d51917 + 2087848 commit 9bee64b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 6 additions & 6 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
if err != nil {
return nil, fmt.Errorf("unable to locate layer %q: %w", layerID, err)
}
// If we're up to the final layer, but we don't want to include
// a diff for it, we're done.
if i.emptyLayer && layerID == i.layerID {
continue
}
// If we already know the digest of the contents of parent
// layers, reuse their blobsums, diff IDs, and sizes.
if !i.confidentialWorkload.Convert && !i.squash && layerID != i.layerID && layer.UncompressedDigest != "" {
Expand Down Expand Up @@ -479,6 +474,11 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
return nil, err
}
} else {
// If we're up to the final layer, but we don't want to
// include a diff for it, we're done.
if i.emptyLayer && layerID == i.layerID {
continue
}
// Extract this layer, one of possibly many.
rc, err = i.store.Diff("", layerID, diffOptions)
if err != nil {
Expand Down Expand Up @@ -927,7 +927,7 @@ func (b *Builder) makeContainerImageRef(options CommitOptions) (*containerImageR
squash: options.Squash,
confidentialWorkload: options.ConfidentialWorkloadOptions,
omitHistory: options.OmitHistory,
emptyLayer: options.EmptyLayer && !options.Squash,
emptyLayer: options.EmptyLayer && !options.Squash && !options.ConfidentialWorkloadOptions.Convert,
idMappingOptions: &b.IDMappingOptions,
parent: parent,
blobDirectory: options.BlobDirectory,
Expand Down
13 changes: 11 additions & 2 deletions tests/mkcw.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ function mkcw_check_image() {
local expectedEnv="$2"
# Mount the container and take a look at what it got from the image.
run_buildah from "$imageID"
ctrID="$output"
local ctrID="$output"
run_buildah mount "$ctrID"
mountpoint="$output"
local mountpoint="$output"
# Should have a /disk.img file.
test -s "$mountpoint"/disk.img
# Should have a krun-sev.json file.
Expand All @@ -33,6 +33,8 @@ function mkcw_check_image() {
fi
# Should have a /tmp directory, at least.
test -d "$TEST_SCRATCH_DIR"/mount/tmp
# Should have a /bin/sh file from the base image, at least.
test -s "$TEST_SCRATCH_DIR"/mount/bin/sh || test -L "$TEST_SCRATCH_DIR"/mount/bin/sh

# Clean up.
umount "$TEST_SCRATCH_DIR"/mount
Expand Down Expand Up @@ -83,6 +85,13 @@ function mkcw_check_image() {
echo -n "mkcw build" > "$TEST_SCRATCH_DIR"/key
run_buildah build --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=SEV,ignore_attestation_errors,passphrase="mkcw build" -f bud/env/Dockerfile.check-env bud/env
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)

run_buildah build --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=sev,ignore_attestation_errors,passphrase="mkcw build" -f bud/env/Dockerfile.check-env bud/env
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)

# the key thing about this next bit is mixing --layers with a final
# instruction in the Dockerfile that normally wouldn't produce a layer
echo -n "mkcw build --layers" > "$TEST_SCRATCH_DIR"/key
run_buildah build --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=SEV,ignore_attestation_errors,passphrase="mkcw build --layers" --layers -f bud/env/Dockerfile.check-env bud/env
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)
}

0 comments on commit 9bee64b

Please sign in to comment.