概要
- ECRからpullするときに
docker login
する必要がある -
aws ecr get-login-password
で取得したパスワードには有効期限がある
で一手間必要です。
参考:
- https://github.community/t/github-actions-new-pulling-from-private-docker-repositories/16089
- https://agileek.github.io/software/aws/2020/10/28/using-an-ecr-image-in-github-actions/
設定例
以下の設定で動いた雰囲気。
name: Test
on:
- push
- pull_request
jobs:
login:
runs-on: ubuntu-latest
outputs:
password: ${{ steps.get_password.outputs.password }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-1
- id: get_password
run: echo "::set-output name=password::$(aws ecr get-login-password)"
test:
needs: login
runs-on: ubuntu-latest
container:
image: xxx.dkr.ecr.ap-northeast-1.amazonaws.com/test:latest
credentials:
username: AWS
password: ${{ needs.login.outputs.password }}
steps:
- run: node -v
- run: npm -v
ポイント
- job: loginで
aws ecr get-login-password
してパスワードを取得 - job: testでそのパスワードを利用してECRのプライベートコンテナ利用
気になるポイント(懸念点)
パスワードがログに出力されてなかったから大丈夫だと思うけど aws ecr get-login-password
してるところ
まとめ
ちょっと気になるポイントがありますが、GitHub ActionsでECRのプライベートイメージを使えました。