Skip to content

Instantly share code, notes, and snippets.

@mrgarymartin
Created April 21, 2023 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrgarymartin/4bac3897e70bdb3f8320ae2701936697 to your computer and use it in GitHub Desktop.
Save mrgarymartin/4bac3897e70bdb3f8320ae2701936697 to your computer and use it in GitHub Desktop.
name: Build and Push Docker Image
on:
push:
branches:
- main
env:
ECR_REGISTRY: <your ECR registry URL>
ECR_REPOSITORY: <your ECR repository name>
IMAGE_TAG: latest
AWS_ROLE_ARN: <ARN of the IAM Role to Assume>
AWS_EXTERNAL_ID: <External ID of the IAM Role>
APP_NAME: <app name>
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-external-id: ${{ env.AWS_EXTERNAL_ID }}
role-duration-seconds: 1200
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
registry: ${{ env.ECR_REGISTRY }}
- name: Build and Push Docker Image
id: build-image
env:
ECR_REGISTRY: ${{ env.ECR_REGISTRY }}
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ env.ECR_REGISTRY }}/${{ env.APP_NAME }}:${{ env.IMAGE_TAG }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment