Skip to content

Commit

Permalink
Add CICD to Deploy to NAXA ECS (#4)
Browse files Browse the repository at this point in the history
* CI: add ci to recreate on AWS

* CI: fix: permissions added for OIDC

* CI: fix: spec in ECS Service

* CI: fix: spec definition in ECS Service

* CI: use secrets

* Optimized for main branch
  • Loading branch information
nischalstha9 authored Jun 13, 2024
1 parent 5701edc commit ac17311
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build and Deploy Drone Tasking Manager

on:
push:
branches:
- main
workflow_dispatch:

permissions:
id-token: write
contents: read

env:
AWS_REGION: ap-south-1
ECR_REGISTRY: 685797548389.dkr.ecr.ap-south-1.amazonaws.com
ECR_REPOSITORY: dtmweb

jobs:
build:
name: Build Docker image
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}

- name: Setup AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}
role-session-name: GH-Actions-${{ github.run_id }}-${{ github.run_attempt }}
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }}

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

- name: Build and Push Docker Image
id: build-image
run: |
docker build -f ./src/backend/Dockerfile -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.ref_name }} .
docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.ref_name }}
- name: Image Digest
run: echo ImageDigest:${{ steps.build-image.outputs.imageDigest }}

deploy_to_ecs:
name: Deploy to ECS
needs:
- build
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}
role-session-name: GH-Actions-${{ github.run_id }}-${{ github.run_attempt }}
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }}

- name: Get Web App task definition
id: get-web-app-task-definition
shell: bash
run: |
TASK_DEFINITION_ARN=$(aws ecs describe-task-definition --task-definition fastapi-tdf --region ${{ env.AWS_REGION }} --query 'taskDefinition.taskDefinitionArn')
echo "TASK_DEFINITION_ARN=${TASK_DEFINITION_ARN}" >> $GITHUB_OUTPUT
- name: ECS Service
uses: scribd/amazon-ecs-service-action@v1
with:
force-new-deployment: true
spec: |
{
"taskDefinition": ${{ steps.get-web-app-task-definition.outputs.TASK_DEFINITION_ARN }},
"cluster": "${{ secrets.ECS_CLUSTER_NAME }}",
"serviceName": "${{ secrets.ECS_SERVICE_NAME }}"
}
wait-until-deployment-complete: true

0 comments on commit ac17311

Please sign in to comment.