Skip to content

Instantly share code, notes, and snippets.

@byhbt
Created November 28, 2021 15:50
Show Gist options
  • Save byhbt/cd92e17d17e80d85f62631dde453c88a to your computer and use it in GitHub Desktop.
Save byhbt/cd92e17d17e80d85f62631dde453c88a to your computer and use it in GitHub Desktop.
Github Action Workflow push image to ECR - Private Registry
name: Deploy to Amazon ECS
on:
push:
branches:
- main
env:
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
jobs:
deploy:
name: Deploy to ECS
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}
- name: Checkout
uses: actions/checkout@v2.3.4
- 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: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: elixir
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Log out of Amazon ECR
if: always()
run: docker logout ${{ steps.login-ecr.outputs.registry }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment