Skip to content

Commit

Permalink
manifest/push: add support for --add-compression
Browse files Browse the repository at this point in the history
Adds support for `--add-compression` which accepts multiple compression
formats and when used it will add all instances in a manifest list with
requested compression formats.

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Jul 31, 2023
1 parent d27a823 commit b9ac8d5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func init() {
flags.StringVar(&manifestPushOpts.creds, "creds", "", "use `[username[:password]]` for accessing the registry")
flags.StringVar(&manifestPushOpts.digestfile, "digestfile", "", "after copying the image, write the digest of the resulting digest to the file")
flags.StringVarP(&manifestPushOpts.format, "format", "f", "", "manifest type (oci or v2s2) to attempt to use when pushing the manifest list (default is manifest type of source)")
flags.StringSliceVar(&manifestPushOpts.addCompression, "add-compression", nil, "add instances with selected compression while pushing")
flags.BoolVarP(&manifestPushOpts.removeSignatures, "remove-signatures", "", false, "don't copy signatures when pushing images")
flags.StringVar(&manifestPushOpts.signBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`")
flags.StringVar(&manifestPushOpts.signaturePolicy, "signature-policy", "", "`pathname` of signature policy file (not usually used)")
Expand Down Expand Up @@ -908,6 +909,7 @@ func manifestPush(systemContext *types.SystemContext, store storage.Store, listI
RemoveSignatures: opts.removeSignatures,
SignBy: opts.signBy,
ManifestType: manifestType,
AddCompression: opts.addCompression,
}
if opts.all {
options.ImageListSelection = cp.CopyAllImages
Expand Down
1 change: 1 addition & 0 deletions cmd/buildah/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type pushOptions struct {
encryptionKeys []string
encryptLayers []int
insecure bool
addCompression []string
}

func init() {
Expand Down
9 changes: 9 additions & 0 deletions docs/buildah-manifest-push.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ The list image's ID and the digest of the image's manifest.

## OPTIONS

**--add-compression** *compression*

Makes sure that requested compression variant for each platform is added to the manifest list keeping original instance
intact in the same manifest list. Supported values are (`gzip`, `zstd` and `zstd:chunked`)

Note: This is different than `--compression` which replaces the instance with requested with specified compression
while `--add-compression` makes sure than each instance has it variant added to manifest list without modifying the
original instance.

**--all**

Push the images mentioned in the manifest list or image index, in addition to
Expand Down
61 changes: 61 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ load helpers
run_buildah build $BUDFILES/stdio
}

@test "bud: build manifest list and --add-compression zstd" {
local contextdir=${TEST_SCRATCH_DIR}/bud/platform
mkdir -p $contextdir

cat > $contextdir/Dockerfile1 << _EOF
FROM alpine
_EOF

start_registry
run_buildah login --tls-verify=false --authfile ${TEST_SCRATCH_DIR}/test.auth --username testuser --password testpassword localhost:${REGISTRY_PORT}
run_buildah build $WITH_POLICY_JSON -t image1 --platform linux/amd64 -f $contextdir/Dockerfile1
run_buildah build $WITH_POLICY_JSON -t image2 --platform linux/arm64 -f $contextdir/Dockerfile1

run_buildah manifest create foo
run_buildah manifest add foo image1
run_buildah manifest add foo image2

run_buildah manifest push $WITH_POLICY_JSON --authfile ${TEST_SCRATCH_DIR}/test.auth --all --add-compression zstd --tls-verify=false foo docker://localhost:${REGISTRY_PORT}/list

run_buildah manifest inspect --authfile ${TEST_SCRATCH_DIR}/test.auth --tls-verify=false localhost:${REGISTRY_PORT}/list
list="$output"

validate_instance_compression "0" "$list" "amd64" "gzip"
validate_instance_compression "1" "$list" "arm64" "gzip"
validate_instance_compression "2" "$list" "amd64" "zstd"
validate_instance_compression "3" "$list" "arm64" "zstd"
}

@test "bud with --dns* flags" {
_prefetch alpine

Expand Down Expand Up @@ -2103,6 +2131,39 @@ function _test_http() {
run_buildah from ${target}
}

# Helper function for several of the tests which verifies compression.
#
# Usage: validate_instance_compression INDEX MANIFEST ARCH COMPRESSION
#
# INDEX instance which needs to be verified in
# provided manifest list.
#
# MANIFEST OCI manifest specification in json format
#
# ARCH instance architecture
#
# COMPRESSION compression algorithm name; e.g "zstd".
#
function validate_instance_compression {
case $4 in

gzip)
run jq -r '.manifests['$1'].annotations' <<< $2
# annotation is `null` for gzip compression
assert "$output" = "null" ".manifests[$1].annotations (null means gzip)"
;;

zstd)
# annotation `'"io.github.containers.compression.zstd": "true"'` must be there for zstd compression
run jq -r '.manifests['$1'].annotations."io.github.containers.compression.zstd"' <<< $2
assert "$output" = "true" ".manifests[$1].annotations.'io.github.containers.compression.zstd' (io.github.containers.compression.zstd must be set)"
;;
esac

run jq -r '.manifests['$1'].platform.architecture' <<< $2
assert "$output" = $3 ".manifests[$1].platform.architecture"
}

@test "bud-http-Dockerfile" {
_test_http from-scratch Containerfile
}
Expand Down

0 comments on commit b9ac8d5

Please sign in to comment.