Created
January 23, 2023 22:20
-
-
Save pryorda/1957ed26da0aefa60c207cf97fc0d18e to your computer and use it in GitHub Desktop.
Copy between repos
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 | |
TARGET_ACCOUNT_REGION="us-west-2" | |
SRC_PROFILE="temp-ignitebankstest" | |
DEST_PROFILE="temp-ignitebanksqa" | |
DESTINATION_ACCOUNT_REGION="us-west-2" | |
DESTINATION_ACCOUNT_BASE_PATH="304374835924.dkr.ecr.$DESTINATION_ACCOUNT_REGION.amazonaws.com" | |
REPO_LIST=($(aws ecr --profile ${SRC_PROFILE} describe-repositories --query 'repositories[].repositoryUri' --output text --region $TARGET_ACCOUNT_REGION)) | |
REPO_NAME=($(aws ecr --profile ${SRC_PROFILE} describe-repositories --query 'repositories[].repositoryName' --output text --region $TARGET_ACCOUNT_REGION)) | |
for repo_url in "${!REPO_LIST[@]}"; do | |
if ! [[ ${REPO_LIST[$repo_url]} =~ "achieva" ]]; then | |
continue | |
fi | |
# Login to src repositories | |
aws ecr --profile ${SRC_PROFILE} get-login-password --region $TARGET_ACCOUNT_REGION | docker login --username AWS --password-stdin "${REPO_LIST[$repo_url]/\/*/}" | |
NEW_IMAGE_NAME=${REPO_NAME[$repo_url]/achieva/abcbank} | |
echo "Start pulling image ${REPO_LIST[$repo_url]} from Target account" | |
docker pull "${REPO_LIST[$repo_url]}" | |
# Create repo in destination account, remove this line if already created | |
aws ecr --profile ${DEST_PROFILE} create-repository --repository-name "${NEW_IMAGE_NAME}" | |
# login to destination account | |
aws ecr --profile ${DEST_PROFILE} get-login-password --region $DESTINATION_ACCOUNT_REGION | docker login --username AWS --password-stdin $DESTINATION_ACCOUNT_BASE_PATH | |
docker tag "${REPO_LIST[$repo_url]}" $DESTINATION_ACCOUNT_BASE_PATH/"${NEW_IMAGE_NAME}" | |
docker push $DESTINATION_ACCOUNT_BASE_PATH/"${NEW_IMAGE_NAME}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment