Add GitHub Actions deploy config to auto-push to Amazon ECR #3
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
# from https://awstip.com/dockerize-python-for-aws-lambda-deploy-with-github-workflow-9a930c1e86b1 | |
name: Push image on ECR | |
on: | |
push: | |
branches: | |
- "main" | |
workflow_dispatch: | |
inputs: | |
image_tag: | |
description: Set tag | |
type: string | |
default: 'latest' | |
jobs: | |
deploy: | |
name: Deploy ECR | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- 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: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push the image to Amazon ECR | |
id: build-image | |
env: | |
AWS_ECR_REGISTRY: ${{ secrets.AWS_ECR_REGISTRY }} | |
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ 'latest' || github.event.inputs.image_tag }} | |
run: | | |
# Build a docker container and push it to ECR | |
docker build -t $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:$IMAGE_TAG . | |
echo "Pushing image to ECR..." | |
docker push $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:$IMAGE_TAG | |
echo "::set-output name=image::$AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:$IMAGE_TAG" |