Preload all images to a local or remote registry
Using the mirror.sh
script below, you can mirror all images to a local or remote registry. This is useful if you are running in an airgapped environment or for various pipeline usecases.
Usage: ./mirror.sh -t [target] [other options]
Options:
-h, --help Show this help message and exit
-s, --source Specify the source type (dockerhub, native, default: native)
-t, --target Specify the target registry with namespace
-p, --platform Specify the platform (linux/amd64, linux/arm64, default: platform of the machine executing the script)
--[no]-retag Retag the images (default)
--tool Specify the tool to perform the mirroring (crane, docker, default: crane)
Example:
./mirror.sh -t ghcr.io/settlemint/onprem
mirror.sh
#!/bin/bash
set -eufo pipefail
images=(ghcr.io/settlemint/bpaas/onprem/installer:6.72.0 docker.io/postgres:15.3-bullseye docker.io/redis:7.0.11-bullseye quay.io/keycloak/keycloak:21.1.1 docker.io/prom/prometheus:v2.44.0 registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.2 ghcr.io/settlemint/bpaas/containers/vault:6.54.3 ghcr.io/settlemint/bpaas/docs:6.72.0 ghcr.io/settlemint/bpaas/onprem/api:6.72.0 ghcr.io/settlemint/bpaas/onprem/app:6.72.0 ghcr.io/settlemint/bpaas/onprem/deploy-workers:6.72.0 quay.io/oauth2-proxy/oauth2-proxy:v7.4.0 ghcr.io/settlemint/bpaas/containers/openresty:6.54.3 docker.io/debian:bullseye-20230208-slim docker.io/hyperledger/fabric-ca:1.5.6 docker.io/lachlanevenson/k8s-kubectl:v1.25.4 docker.io/curlimages/curl:8.1.1 docker.io/stakater/reloader:v1.0.25 docker.io/hyperledger/besu:23.4.1 docker.io/hyperledger/fabric-orderer:2.5.1 docker.io/hyperledger/fabric-tools:2.5.1 docker.io/hyperledger/fabric-peer:2.5.1 ghcr.io/settlemint/bpaas/services/fabric-manager:6.72.0 docker.io/apache/couchdb:3.3.2 docker.io/0xpolygon/polygon-edge:0.8.1 ghcr.io/settlemint/enteth-middleware:3.69.10 docker.io/graphprotocol/graph-node:v0.30.0 docker.io/ipfs/kubo:v0.20.0 ghcr.io/settlemint/ipfs-webui:main34 docker.io/minio/minio:RELEASE.2022-10-24T18-35-07Z ghcr.io/settlemint/blockscout-onprem:5.1.5-beta-6c54ac8d3 ghcr.io/settlemint/bpaas/services/txsigner:6.72.0 ghcr.io/hyperledger/firefly-signer:v1.1.8 docker.io/docker:dind docker.io/hasura/graphql-engine:v2.26.0 ghcr.io/settlemint/bpaas/containers/integration-studio:6.54.3 ghcr.io/settlemint/bpaas/containers/firefly-fabconnect:6.54.3 ghcr.io/settlemint/bpaas/services/ide-cli:6.72.0 ghcr.io/settlemint/bpaas/services/firefly-cli:6.72.0 docker.io/otterscan/otterscan:v1.30.0 ghcr.io/settlemint/bpaas/smartcontractsets/base-ide-fabric:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/base-ide-evm:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/chaincode-go-empty:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/chaincode-ts-empty:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-empty:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-statemachine:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-legacy-templateset:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc20:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc20-crowdsale:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc20-metatx:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc721:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc721a:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc721-cards:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-erc721-generative-art:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-supplychain:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-t-rex:6.54.0 ghcr.io/settlemint/bpaas/smartcontractsets/solidity-token-soulbound:6.54.0 )
function crane_mirror {
local image_full="$1"
local image="${image_full##*/}"
local target="$2"
local platform="--platform=$3"
local retag="$4"
local source="$5"
if [[ "$retag" == false ]]; then
echo "The crane tool can only be used with retagging"
exit 1
fi
if [[ "$source" == "dockerhub" ]]; then
crane copy ${platform} "docker.io/settlemint/${image}" "${target}/${image}"
else
crane copy ${platform} ${image_full} "${target}/${image}"
fi
}
function skopeo_mirror {
local image_full="$1"
local image="${image_full##*/}"
local target="$2"
local platform="$3"
local retag="$4"
local source="$5"
if [[ "$retag" == false ]]; then
echo "The skopeo tool can only be used with retagging"
exit 1
fi
if [[ "$platform" == "all" ]]; then
if [[ "$source" == "dockerhub" ]]; then
skopeo copy docker://docker.io/settlemint/${image} docker://${target}/${image}
else
skopeo copy docker://${image_full} docker://${target}/${image}
fi
else
echo "The skopeo tool can only be used with all architectures"
exit 1
fi
}
function docker_mirror {
local image_full="$1"
local image="${image_full##*/}"
local target="$2"
local platform="--platform=$3"
local retag="$4"
local source="$5"
if [[ "$source" == "dockerhub" ]]; then
docker pull ${platform} "docker.io/settlemint/${image}"
if [[ "$retag" == true ]]; then
docker tag "docker.io/settlemint/${image}" "${target}/${image}"
docker push "${target}/${image}"
fi
else
docker pull ${platform} ${image_full}
if [[ "$retag" == true ]]; then
docker tag ${image_full} "${target}/${image}"
docker push "${target}/${image}"
fi
fi
}
# Set default values
source_type="native"
target=""
platform="all"
retag=true
tool_type="crane"
# Define the help function
function show_help {
echo "Usage: ./mirror.sh -t [target] [other options]"
echo ""
echo "Options:"
echo " -h, --help Show this help message and exit"
echo " -s, --source Specify the source type (dockerhub, native, default: native)"
echo " -t, --target Specify the target registry with namespace"
echo " -p, --platform Specify the platform (all, linux/amd64, linux/arm64, default: all)"
echo " --[no]-retag Retag the images (default)"
echo " --tool Specify the tool to perform the mirroring (crane, docker, default: crane)"
}
# Parse command line options
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
show_help
exit 0
;;
-s|--source)
case "$2" in
dockerhub|native)
source_type="$2"
shift
;;
*)
echo "Invalid source type: $2"
show_help
exit 1
;;
esac
;;
-t|--target)
target="$2"
shift
;;
-p|--platform)
case "$2" in
linux/amd64|linux/arm64|all)
platform="$2"
shift
;;
*)
echo "Invalid platform: $2"
show_help
exit 1
;;
esac
;;
--retag)
retag=true
;;
--no-retag)
retag=false
;;
--tool)
case "$2" in
crane|docker|skopeo)
tool_type="$2"
shift
;;
*)
echo "Invalid tool type: $2"
show_help
exit 1
;;
esac
;;
*)
# Unknown option
echo "Unknown option: $key"
show_help
exit 1
;;
esac
shift
done
if [ -z "$target" ]; then
show_help
exit 1
fi
for image in "${images[@]}"
do
if [[ "$tool_type" == "crane" ]]; then
crane_mirror "${image}" "${target}" "${platform}" "${retag}" "${source_type}"
elif [[ "$tool_type" == "skopeo" ]]; then
skopeo_mirror "${image}" "${target}" "${platform}" "${retag}" "${source_type}"
else
docker_mirror "${image}" "${target}" "${platform}" "${retag}" "${source_type}"
fi
done