Skip to content

Commit

Permalink
updated deploy workflow
Browse files Browse the repository at this point in the history
The GitHub action is updated to use currently active ecs task definition
instead of the one defined in the repo. This ensures changes made in ecs
cluster stay there instead of getting reset.
  • Loading branch information
tellmeY18 committed Jan 14, 2025
1 parent 73f36db commit a6f7227
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 875 deletions.
73 changes: 34 additions & 39 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- '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 @@ -130,6 +124,8 @@ jobs:
run: |
echo "Release ${{ github.sha }} is ready to be deployed to production"
deploy-staging-egov:
needs: build
if: github.ref == 'refs/heads/develop'
Expand All @@ -139,9 +135,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 +148,44 @@ 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: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_SERVICE_CELERY }} --query taskDefinition > celery-task-definition.json
- 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: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_SERVICE_BACKEND }} --query taskDefinition > backend-task-definition.json
- 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 a6f7227

Please sign in to comment.