LoginSignup
0
0

More than 5 years have passed since last update.

Amazon Elastic Container Registry (ECR) へイメージをプッシュするシェルを書いた

Posted at

IAMからECRへのイメージをアップロードするロールを作成します。
既存のポリシーAmazonEC2ContainerRegistryPowerUserを使っても良いと思います。
リージョンはap-northeast-1前提で進みます。

aws ecr get-loginコマンドでloginコマンドを取得します。

アカウントIDが必要になるのですが、jqコマンドを使って逃げます。

aws sts get-caller-identity | jq .Account

シェル

ecr-push.sh

#!/bin/bash

DOCKER_TAG="$1"

AWSID=$(aws sts get-caller-identity | jq -r  .Account)

LOGIN=$(aws ecr get-login --no-include-email --region ap-northeast-1)

${LOGIN}

# docker build -t $DOCKER_TAG .

docker tag $DOCKER_TAG:latest $AWSID.dkr.ecr.ap-northeast-1.amazonaws.com/$DOCKER_TAG:latest

docker push $AWSID.dkr.ecr.ap-northeast-1.amazonaws.com/$DOCKER_TAG:latest

シェルの起動

sh ecr-push.sh docker-tag

注意点

jq コマンドで文字列にアクセスすると、"\"xxx\""とクオーテーションがエスケープされて出力されてしまう。
jq -rまたはjq --row-outputオプションを付けることで文字列をシェル上の文字列として扱うことができる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0