Deploy to Amazon ECR and Update App Runner #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Push Docker image to ECR | |
on: | |
push: | |
tags: | |
- "v*" # Triggers the workflow when a Git tag starting with 'v' is pushed | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository code | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Configure AWS credentials using access keys | |
- 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_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
# Authenticate Docker with Amazon ECR | |
- name: Authenticate Docker to Amazon ECR | |
run: | | |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com | |
# Build and tag the Docker image | |
- name: Build Docker image | |
run: | | |
IMAGE_TAG="${GITHUB_REF##*/}" | |
docker build -t ${{ secrets.AWS_ECR_REPOSITORY }}:$IMAGE_TAG . | |
# Tag the Docker image with the full ECR repository URL | |
- name: Tag Docker image | |
run: | | |
IMAGE_TAG="${GITHUB_REF##*/}" | |
docker tag ${{ secrets.AWS_ECR_REPOSITORY }}:$IMAGE_TAG ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_REPOSITORY }}:$IMAGE_TAG | |
# Push the Docker image to Amazon ECR | |
- name: Push Docker image to Amazon ECR | |
run: | | |
IMAGE_TAG="${GITHUB_REF##*/}" | |
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_REPOSITORY }}:$IMAGE_TAG | |
# Environment variables that are fetched from GitHub Secrets | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }} |