Skip to content

Instantly share code, notes, and snippets.

@diegovarussa
Created February 14, 2020 07:25
Show Gist options
  • Save diegovarussa/85fa29fed3dd75c94e7660e6d10eb5d2 to your computer and use it in GitHub Desktop.
Save diegovarussa/85fa29fed3dd75c94e7660e6d10eb5d2 to your computer and use it in GitHub Desktop.
Azure Container Registry (ACR) Copy: This script pull all images from you source registry, re-tag it and push to destination registry
#!/bin/bash
SOURCE_SUBSCRIPTION_ID='REPLACE_HERE'
SOURCE_REGISTRY_NAME='REPLACE_HERE'
DESTINATION_REGISTRY_NAME='REPLACE_HERE'
# Get a json array with repository list of you source registry
SOURCE_REPOSITORIES=$(az acr repository list \
--name ${SOURCE_REGISTRY_NAME} \
--subscription ${SOURCE_SUBSCRIPTION_ID})
# Convert json array to bash array
SOURCE_REPOSITORIES_ARRAY=$(echo $SOURCE_REPOSITORIES | jq -r .[])
for repository in $SOURCE_REPOSITORIES_ARRAY; do
# Get the latest tag from each repository
TAG=$(az acr repository show-tags \
--name ${SOURCE_REGISTRY_NAME} \
--repository ${repository} \
--orderby time_desc \
--top 1 \
--subscription ${SOURCE_SUBSCRIPTION_ID})
# Convert json to a simple string
TAG_STRING=$(echo $TAG | jq -r .[])
docker pull ${SOURCE_REGISTRY_NAME}.azurecr.io/${repository}:${TAG_STRING}
docker tag ${SOURCE_REGISTRY_NAME}.azurecr.io/${repository}:${TAG_STRING} ${DESTINATION_REGISTRY_NAME}.azurecr.io/${repository}:${TAG_STRING}
docker push ${DESTINATION_REGISTRY_NAME}.azurecr.io/${repository}:${TAG_STRING}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment