Skip to content

Instantly share code, notes, and snippets.

@imjasonh
Created January 3, 2022 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imjasonh/a4c4c1859db94251918e5a15ddb69ad7 to your computer and use it in GitHub Desktop.
Save imjasonh/a4c4c1859db94251918e5a15ddb69ad7 to your computer and use it in GitHub Desktop.

Combining manifest list with crane and docker manifest create

Usage:

./combine.sh <out> <manifest-list-1> <manifest-list-2> ...

Example:

./combine.sh gcr.io/imjasonh/combined \
    gcr.io/distroless/static:nonroot \
    mcr.microsoft.com/windows/nanoserver:1809 \
    mcr.microsoft.com/windows/servercore:ltsc2022 \
    mcr.microsoft.com/windows/servercore:ltsc2019
...
gcr.io/imjasonh/combined@sha256:6285208815d2e7f53a6cbc4b1858545e14b9e1e84d7aca85a12c566c2ebe18a6
#!/usr/bin/env bash
set -euxo pipefail
if [[ $# -lt 3 ]]; then
echo "Usage: combine.sh <out> <img1> <img2> ..."
exit 1
fi
out=$1
shift
first=$1
shift
# Trim off any tags from the out argument.
outrepo=${out%:*}
docker manifest rm $out || true
# Copy the first manifest list to the output repository, and list and
# append each constituent image to the output manifest list.
crane cp $first $outrepo
crane manifest $first | jq -r '.manifests[].digest' | sed "s|^|${outrepo}@|" | xargs -n 100 docker manifest create $out 1>&2
for img in "$@"; do
# Copy each subsequent manifest list to the output repository, and list and
# append each constituent image to the output manifest list.
crane cp $img $outrepo
crane manifest $img | jq -r '.manifests[].digest' | sed "s|^|${outrepo}@|" | xargs -n 100 docker manifest create --amend $out 1>&2
done
outsha=$(docker manifest push $out)
outimg=${outrepo}@${outsha}
crane manifest $outimg 1>&2
# Only the final combined manifest list by digest should be printed to stdout,
# all else should be redirected to stderr.
echo $outimg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment