Skip to content

Commit

Permalink
Create push-deploy.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
seniakalma authored Nov 28, 2024
1 parent f45f6f2 commit 02b82d4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/push-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy to Amazon ECS

on:
push:
tags:
- '*' # Triggers the workflow on any new tag

env:
AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: ${{ var.ECR_REPOSITORY }} # set this to your Amazon ECR repository name
ECS_SERVICE: ${{ var.ECS_SERVICE }} # set this to your Amazon ECS service name
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }} # set this to your Amazon ECS cluster name

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: latest
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Update ECS Service to use the latest image
run: |
# Force a new deployment of the ECS service
aws ecs update-service \
--cluster ${{ env.ECS_CLUSTER }} \
--service ${{ env.ECS_SERVICE }} \
--force-new-deployment

0 comments on commit 02b82d4

Please sign in to comment.