Skip to content

Instantly share code, notes, and snippets.

@allex
Last active March 3, 2023 10:21
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 allex/50a9fb121c3b97da6ca2a2a8738466ca to your computer and use it in GitHub Desktop.
Save allex/50a9fb121c3b97da6ca2a2a8738466ca to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
# Export and bundle docker image to local (both linux/amd64(x86), linux/arm64)
# by @allex_wang <https://iallex.com> | MIT
#
# Usage:
# bundle-image.sh <SOURCE_IMAGE_URL> <TARGET_IMAGE_NAME>
#
# For remote invoke:
# curl -skL https://fe.tidu.io/tools/bundle-images.sh |sh -s -- harbor.tidu.io/tdio/iam-ui:1.1.0 cmp/iam-ui:1.1.0
#
# GistID: 50a9fb121c3b97da6ca2a2a8738466ca
# GistURL: https://gist.github.com/50a9fb121c3b97da6ca2a2a8738466ca
img=${1:-};
if [ -z "$img" ]; then
echo >&2 "Usage: bundle-image.sh <SOURCE_IMAGE_URL> <TARGET_IMAGE_NAME>"
echo
echo >&2 "Export and bundle docker image to local (both linux/amd64(x86), linux/arm64)"
exit 1
fi
target_img=${2-${img#*/}}
echo >&2 "start to bundle image $img ..."
for p in amd64 arm64; do
(docker pull "$img" --platform=linux/$p && docker tag "$img" "$target_img") >/dev/null
f=$(echo "${target_img##*/}" |tr ':' '_')-$p.tar.gz
docker save "${target_img}" |gzip >./"$f";
echo >&2 "-> $f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment