Skip to content

Commit

Permalink
fix: use overlay whiteouts when extracting tar layers
Browse files Browse the repository at this point in the history
If a tar layer has a deleted file, a whiteout entry is created. However,
when extracting tar and overlay whiteouts are incompatible.

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha committed Dec 12, 2023
1 parent f265e66 commit 04192a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/overlay/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func unpackOne(l ispec.Descriptor, ociDir string, extractDir string) error {
return err
}

err = layer.UnpackLayer(extractDir, uncompressed, nil)
err = layer.UnpackLayer(extractDir, uncompressed, &layer.UnpackOptions{WhiteoutMode: layer.OverlayFSWhiteout})
if err != nil {
if rmErr := os.RemoveAll(extractDir); rmErr != nil {
log.Errorf("Failed to remove dir '%s' after failed extraction: %v", extractDir, rmErr)
Expand Down
28 changes: 28 additions & 0 deletions test/publish.bats
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,31 @@ published:
EOF

}

@test "building from published images with whiteouts" {
# This tests the case where an image is published after deleting some entries
# We expect that the published image can now be used to build another image,
# while respecting the whiteouts (due to deletion)

cat > stacker.yaml <<EOF
parent:
from:
type: docker
url: docker://ghcr.io/project-stacker/alpine:edge
run: |
rm -rf /etc/apk/repositories
EOF
stacker build
stacker publish --skip-tls --url docker://${REGISTRY_URL} --tag latest
stacker clean

cat > stacker.yaml <<EOF
child:
from:
type: docker
url: docker://${REGISTRY_URL}/parent:latest
run: |
[ ! -f /etc/apk/repositories ]
EOF
stacker build
}

0 comments on commit 04192a3

Please sign in to comment.