Skip to content

Commit

Permalink
Merge pull request #2740 from ohcnetwork/vysakh/updated-ecs
Browse files Browse the repository at this point in the history
updated deploy workflow
  • Loading branch information
vigneshhari authored Jan 15, 2025
2 parents b71e9e3 + 9d13c4a commit ed10b8c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 877 deletions.
84 changes: 43 additions & 41 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ on:
workflow_dispatch:
push:
tags:
- 'v*'
- "v*"
branches:
- develop
- staging
paths-ignore:
- "docs/**"

Expand All @@ -16,17 +15,11 @@ concurrency:
cancel-in-progress: true

env:
IMAGE_NAME: care
AWS_DEFAULT_REGION: ap-south-1
AWS_DEFAULT_OUTPUT: json
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EKS_CLUSTER_NAME: ${{ secrets.AWS_EKS_CLUSTER_NAME }}
ECS_SERVICE_BACKEND: "care-backend"
ECS_SERVICE_CELERY: "care-celery"
ECS_CLUSTER: "egov"
ECS_TASK_DEFINITION_BACKEND: "./aws/backend.json"
ECS_TASK_DEFINITION_CELERY: "./aws/celery.json"
CONTAINER_NAME_BACKEND: "care-backend"
CONTAINER_NAME_WORKER: "care-celery-worker"
CONTAINER_NAME_CRON: "care-celery-beat"
Expand Down Expand Up @@ -70,12 +63,6 @@ jobs:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -91,6 +78,11 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-build-
- name: Create new cache
run: |
mkdir -p /tmp/.buildx-cache
mkdir -p /tmp/.buildx-cache-new
- name: Build and push image
uses: docker/build-push-action@v6
with:
Expand All @@ -114,11 +106,13 @@ jobs:
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
version: ${{ github.sha }}

- name: Move cache
- name: Update cache
if: always() # Run even if previous steps fail
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
if [ -d "/tmp/.buildx-cache-new" ]; then
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
fi
notify-release:
needs: build
Expand All @@ -139,9 +133,6 @@ jobs:
name: Staging-egov
url: https://careapi.ohc.network
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -155,42 +146,53 @@ jobs:
IMAGE_TAG: latest-${{ github.run_number }}
run: echo "IMAGE_VALUE=`echo ghcr.io/${{ github.repository }}:$IMAGE_TAG`" >> $GITHUB_ENV

- name: Fill Celery Cron definition
id: task-def-celery-cron
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION_CELERY }}
container-name: ${{ env.CONTAINER_NAME_CRON }}
image: ${{env.IMAGE_VALUE}}

- name: Fill Celery Worker definition
id: task-def-celery-worker
- name: Download task definition for Celery Service
run: |
set -e
if aws ecs describe-task-definition --task-definition ${{ env.ECS_SERVICE_CELERY }} --query taskDefinition > celery-task-definition.json; then
echo "Successfully downloaded Celery task definition."
else
echo "Failed to download Celery task definition." >&2
exit 1
fi
- name: Fill in the new image ID in the Celery task definition
id: celery-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.task-def-celery-cron.outputs.task-definition }}
task-definition: celery-task-definition.json
container-name: ${{ env.CONTAINER_NAME_WORKER }}
image: ${{env.IMAGE_VALUE}}
image: ${{ env.IMAGE_VALUE }}

- name: Deploy Backend Celery
- name: Deploy Celery task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def-celery-worker.outputs.task-definition }}
task-definition: ${{ steps.celery-task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_CELERY }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true

- name: Fill Backend Api definition
id: task-def-api
- name: Download task definition for Backend Service
run: |
set -e
if aws ecs describe-task-definition --task-definition ${{ env.ECS_SERVICE_BACKEND }} --query taskDefinition > backend-task-definition.json; then
echo "Successfully downloaded Backend task definition."
else
echo "Failed to download Backend task definition." >&2
exit 1
fi
- name: Fill in the new image ID in the Backend task definition
id: backend-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION_BACKEND }}
task-definition: backend-task-definition.json
container-name: ${{ env.CONTAINER_NAME_BACKEND }}
image: ${{env.IMAGE_VALUE}}
image: ${{ env.IMAGE_VALUE }}

- name: Deploy Backend Api
- name: Deploy Backend task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def-api.outputs.task-definition }}
task-definition: ${{ steps.backend-task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_BACKEND }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
Loading

0 comments on commit ed10b8c

Please sign in to comment.