Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No empty layers #293

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions repack.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,38 @@ func Repack(engineExt casext.Engine, tagName string, bundlePath string, meta Met
mtreefilter.MaskFilter(maskedPaths),
mtreefilter.SimplifyFilter(diffs))

reader, err := layer.GenerateLayer(fullRootfsPath, diffs, &meta.MapOptions)
if err != nil {
return errors.Wrap(err, "generate diff layer")
}
defer reader.Close()
if len(diffs) == 0 {
config, err := mutator.Config(context.Background())
if err != nil {
return err
}

// TODO: We should add a flag to allow for a new layer to be made
// non-distributable.
if err := mutator.Add(context.Background(), reader, history); err != nil {
return errors.Wrap(err, "add diff layer")
imageMeta, err := mutator.Meta(context.Background())
if err != nil {
return err
}

annotations, err := mutator.Annotations(context.Background())
if err != nil {
return err
}

err = mutator.Set(context.Background(), config, imageMeta, annotations, history)
if err != nil {
return err
}
} else {
reader, err := layer.GenerateLayer(fullRootfsPath, diffs, &meta.MapOptions)
if err != nil {
return errors.Wrap(err, "generate diff layer")
}
defer reader.Close()

// TODO: We should add a flag to allow for a new layer to be made
// non-distributable.
if err := mutator.Add(context.Background(), reader, history); err != nil {
return errors.Wrap(err, "add diff layer")
}
}

newDescriptorPath, err := mutator.Commit(context.Background())
Expand Down
23 changes: 22 additions & 1 deletion test/repack.bats
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function teardown() {
bundle-verify "$BUNDLE"

# Make some small change.
touch "$BUNDLE/a_small_change"
touch "$ROOTFS/a_small_change"
now="$(date --iso-8601=seconds --utc)"

# Repack the image, setting history values.
Expand Down Expand Up @@ -790,3 +790,24 @@ function teardown() {
[ "$numLinesB" -gt "$numLinesA" ]
[ "$numLinesC" -gt "$numLinesB" ]
}

@test "umoci repack (empty diff)" {
# Unpack the original image
new_bundle_rootfs
umoci unpack --image "${IMAGE}:${TAG}" "$BUNDLE"
[ "$status" -eq 0 ]
bundle-verify "$BUNDLE"

# Repack the image under a new tag.
umoci repack --image "${IMAGE}:${TAG}-new" "$BUNDLE"
[ "$status" -eq 0 ]
image-verify "${IMAGE}"

# The two manifests should have the same number of layers.
manifest0=$(cat "${IMAGE}/oci/index.json" | jq -r .manifests[0].digest | cut -f2 -d:)
manifest1=$(cat "${IMAGE}/oci/index.json" | jq -r .manifests[1].digest | cut -f2 -d:)

layers0=$(cat "${IMAGE}/oci/blobs/sha256/$manifest0" | jq -r .layers)
layers1=$(cat "${IMAGE}/oci/blobs/sha256/$manifest1" | jq -r .layers)
[ "$layers0" == "$layers1" ]
}