Created
March 23, 2018 09:34
-
-
Save jippi/a4ad3a1caa787568df0ac1bd212cbf30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
filename="repo_dockerhub.conf" | |
source_registry="" | |
destination_prefix="hub/" | |
destination_registry="xxxx.dkr.ecr.us-east-1.amazonaws.com/${destination_prefix}" | |
existing_repos=$(aws ecr describe-repositories | jq -r '.repositories[].repositoryName') | |
# Read file to pull images | |
while IFS='' read -r repo || [[ -n "$repo" ]]; do | |
echo "Start to pull/tag/push/rmi the image: $repo" | |
if ! echo $existing_repos | grep -q "${destination_prefix}${repo}"; then | |
echo "-> creating repo ${source_registry}${repo}:${tag}" | |
aws ecr create-repository --repository-name "${destination_prefix}${repo}" | |
else | |
echo "-> existing repo ${source_registry}${repo}" | |
fi | |
source_tags="" | |
destination_tags="" | |
tags=$(wget -q https://registry.hub.docker.com/v1/repositories/$repo/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}') | |
for tag in $tags; do | |
source_tags="${source_tags} ${source_registry}${repo}:${tag}" | |
destination_tags="${destination_tags} ${destination_registry}${repo}:${tag}" | |
echo "-> pull ${source_registry}${repo}:${tag}" | |
docker pull "${source_registry}${repo}:${tag}" | |
echo "-> tag ${destination_registry}${repo}:${tag}" | |
docker tag "${source_registry}${repo}:${tag}" "${destination_registry}${repo}:${tag}" | |
echo "-> push ${destination_registry}${repo}:${tag}" | |
docker push "${destination_registry}${repo}:${tag}" | |
done | |
echo "-> rmi ${source_registry}${repo}:*" | |
docker rmi $source_tags | |
echo "-> rmi ${destination_registry}${repo}:*" | |
docker rmi $destination_tags | |
done < "$filename" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment