Skip to content

Instantly share code, notes, and snippets.

@y-takagi
Created August 24, 2016 02:18
Show Gist options
  • Save y-takagi/c4563f0a169a6529c3c0be75dfdaff00 to your computer and use it in GitHub Desktop.
Save y-takagi/c4563f0a169a6529c3c0be75dfdaff00 to your computer and use it in GitHub Desktop.
ECRのリージョン移行
#!/bin/bash
#
# 前準備として、移行先に各イメージのレポジトリを作成しておく必要あり。
# $from、$to、$aws_account_id、$images は適宜変更する。
#
set -e
from="us-east-1"
to="ap-northeast-1"
aws_account_id=""
images=("image1:tag" "image2:tag")
repo_format="%s.dkr.ecr.%s.amazonaws.com"
repo_from=$(printf $repo_format $aws_account_id $from)
repo_to=$(printf $repo_format $aws_account_id $to)
pull_and_tag_images() {
for image in ${images[@]}
do
docker pull $repo_from/$image
docker tag $repo_from/$image $repo_to/$image
done
unset image
}
push_images() {
for image in ${images[@]}
do
docker push $repo_to/$image
done
unset image
}
aws ecr get-login --region $from | bash
pull_and_tag_images
aws ecr get-login --region $to | bash
push_images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment