Skip to content

Instantly share code, notes, and snippets.

@byhbt
Last active November 28, 2021 15:41
Show Gist options
  • Save byhbt/a2a7d00c3eef1822321dbff1a686e214 to your computer and use it in GitHub Desktop.
Save byhbt/a2a7d00c3eef1822321dbff1a686e214 to your computer and use it in GitHub Desktop.
Github Action Workflow push image to ECR - Public 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: Login to Public ECR
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: <region_name>
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REGISTRY_PUBLIC: <public_registry_name>
ECR_REPOSITORY: <repository_name> # public.ecr.aws/t3e2d2e0
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY_PUBLIC/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY_PUBLIC/$ECR_REPOSITORY:$IMAGE_TAG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment