1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub Actions で multi-platform container image を build して ECR に push する

Last updated at Posted at 2023-12-12

AWS の EKS や ECS では x86_64 も Graviton の arm64 も選択可能です、どちらでも使うかもしれない Container image は multi-platform 対応の image にしておきたいなということで GitHub Actions で build & push を行えるようにしてみました。

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      # https://github.com/docker/setup-qemu-action
      - name: Setup QEMU
        uses: docker/setup-qemu-action@v3

      # https://github.com/docker/setup-buildx-action
      - name: Setup Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3

      # https://github.com/aws-actions/configure-aws-credentials
      - name: Get AWS Credentials
        id: creds
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: ${{ env.AWS_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

      # https://github.com/docker/metadata-action
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ steps.creds.outputs.aws-account-id }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}
          tags: |
            type=ref,event=tag
            type=sha

      # https://github.com/aws-actions/amazon-ecr-login
      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v2

      # https://github.com/docker/build-push-action
      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: some/where
          platforms: linux/amd64,linux/arm64
          push : true
          tags: ${{ steps.meta.outputs.tags }}
          provenance: false

実際には AWS Lambda を container image で実行しようと思って、その際 x86_64 でも arm64 でも実行できるようにしてみようと multi-platform image を試したんだけど AWS Lambda は multi-platform image をサポートしていませんでした... :cry:

てことで docker/metadata-actiondocker/build-push-actionlinux/amd64linux/arm64 それぞれ用に書きましたとさ。めでたしめでたし。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?