Skip to content

Build and Push to ECR #18

Build and Push to ECR

Build and Push to ECR #18

name: Build and Push to ECR
on:
workflow_run:
workflows: ["Run Tests"]
types:
- completed
branches: [ main ]
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: my_memory/memory
jobs:
build-push:
name: Build and push to ECR
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Trigger deployment workflow
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.PAT_TOKEN }}
event-type: deploy-prod
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push multi-platform image to Amazon ECR
uses: docker/build-push-action@v4
with:
context: .
file: memory-infra/docker/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest