From a5cc9ff43b6eb016c0199fbff9947e1dfac0d0d0 Mon Sep 17 00:00:00 2001 From: Sheetal Date: Tue, 16 Apr 2024 17:38:24 +0530 Subject: [PATCH] pipeline implemetation --- .github/workflows/dev-agent-provisioning.yml | 45 ++++++++++++------- .github/workflows/dev-agent.yml | 30 ++++++++++--- .github/workflows/dev-api-gateway.yml | 26 +++++++++-- .github/workflows/dev-connection.yml | 22 ++++++++- .github/workflows/dev-ecosystem.yml | 22 ++++++++- .github/workflows/dev-issuance.yml | 24 ++++++++-- .github/workflows/dev-ledger.yml | 22 ++++++++- .../workflows/dev-notification-webhook.yml | 22 ++++++++- .github/workflows/dev-notification.yml | 28 +++++++++--- .github/workflows/dev-organization.yml | 28 +++++++++--- .github/workflows/dev-user.yml | 5 ++- .github/workflows/dev-utility.yml | 30 ++++++++++--- .github/workflows/dev-verification.yml | 22 ++++++++- .github/workflows/dev-webhook.yml | 24 ++++++++-- ...teway-service => api-gateway-service.json} | 0 ...liti-service.json => utility-service.json} | 0 16 files changed, 290 insertions(+), 60 deletions(-) rename taskdef/{api-gateway-service => api-gateway-service.json} (100%) rename taskdef/{utiliti-service.json => utility-service.json} (100%) diff --git a/.github/workflows/dev-agent-provisioning.yml b/.github/workflows/dev-agent-provisioning.yml index f1ea37d18..0f96eeec2 100644 --- a/.github/workflows/dev-agent-provisioning.yml +++ b/.github/workflows/dev-agent-provisioning.yml @@ -85,24 +85,35 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} - - name: Create or Update Service - run: | - echo "SERVICE_NAME: ${SERVICE_NAME}" - # Describe the service once and store the result - SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ${{ env.AWS_REGION }}) + - name: Update Task Definition and service + run: | + FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/user-service.json) + NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/user-service.json) + SERVICE_NAME="${NAME}-service" + + # Replace placeholders in the JSON file + sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/user-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json + + # Debug: Print the content of the modified JSON file + cat ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json + + # Register the task definition using the modified JSON file + aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) - # Check if the service exists - if [ -z "$SERVICE_INFO" ]; then - echo "Service does not exist, creating new service..." - # Your logic to create a new service goes here - else - echo "Entered existing service" - # Extract desired count from the stored service info + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') if [ "$DESIRED_COUNT" = "0" ]; then DESIRED_COUNT="1" - fi - # Update the existing service - REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ${{ env.AWS_REGION }} | jq -r '.taskDefinition.revision') - aws ecs update-service --cluster ${CLUSTER} --region ${{ env.AWS_REGION }} --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} - fi + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-agent.yml b/.github/workflows/dev-agent.yml index 50505efff..787eeebf9 100644 --- a/.github/workflows/dev-agent.yml +++ b/.github/workflows/dev-agent.yml @@ -3,10 +3,10 @@ name: Build and deploy Node.js app to ECSsdc on: push: branches: - - main - paths: - - 'apps/agent-service/**' - workflow_dispatch: + - pipeline-implementation +# paths: +# - 'apps/agent-service/**' +# workflow_dispatch: env: ECR_IMAGE_TAG: "AGENT_V_${{ github.run_number }}" @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/agent-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/agent-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/agent-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/agent-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-api-gateway.yml b/.github/workflows/dev-api-gateway.yml index 60dc1627e..d08f74f55 100644 --- a/.github/workflows/dev-api-gateway.yml +++ b/.github/workflows/dev-api-gateway.yml @@ -42,7 +42,7 @@ jobs: env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: dev-services - IMAGE_TAG: "API-GATEWAY_v_${{ github.run_number }}" + IMAGE_TAG: "API-GATEWAY_V_${{ github.run_number }}" run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfiles/Dockerfile.api-gateway . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG @@ -52,7 +52,7 @@ jobs: run: | echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV echo "ECR_REPOSITORY=dev-services" >> $GITHUB_ENV - echo "IMAGE_TAG=API-GATEWAY_v_${{ github.run_number }}" >> $GITHUB_ENV + echo "IMAGE_TAG=API-GATEWAY_V_${{ github.run_number }}" >> $GITHUB_ENV - name: Print environment variables run: | @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/api-gateway-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/api-gateway-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/api-gateway-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/api-gateway-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-connection.yml b/.github/workflows/dev-connection.yml index d73241f54..de33aa04f 100644 --- a/.github/workflows/dev-connection.yml +++ b/.github/workflows/dev-connection.yml @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/connection-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/connection-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/connection-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/connection-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-ecosystem.yml b/.github/workflows/dev-ecosystem.yml index 6bd15739b..910175955 100644 --- a/.github/workflows/dev-ecosystem.yml +++ b/.github/workflows/dev-ecosystem.yml @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/ecosystem-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/ecosystem-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/ecosystem-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/ecosystem-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-issuance.yml b/.github/workflows/dev-issuance.yml index d9ea4d86f..9d8885602 100644 --- a/.github/workflows/dev-issuance.yml +++ b/.github/workflows/dev-issuance.yml @@ -10,7 +10,7 @@ on: env: - ECR_IMAGE_TAG: "ISSUANCE_v_${{ github.run_number }}" + ECR_IMAGE_TAG: "ISSUANCE_V_${{ github.run_number }}" ECR_REPOSITORY: "dev-services" AWS_REGION: "ap-southeast-1" CLUSTER: "DEV-NGOTAG-CLUSTER" @@ -70,12 +70,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/issuance-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/issuance-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/issuance-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/issuance-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -84,3 +84,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-ledger.yml b/.github/workflows/dev-ledger.yml index a6cd78920..ef521b1aa 100644 --- a/.github/workflows/dev-ledger.yml +++ b/.github/workflows/dev-ledger.yml @@ -70,12 +70,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/ledger-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/ledger-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/ledger-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/ledger-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -84,3 +84,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-notification-webhook.yml b/.github/workflows/dev-notification-webhook.yml index b3d5331b8..caef72bf2 100644 --- a/.github/workflows/dev-notification-webhook.yml +++ b/.github/workflows/dev-notification-webhook.yml @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/notification-webhook-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/notification-webhook-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/notification-webhook-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/notification-webhook-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-notification.yml b/.github/workflows/dev-notification.yml index 13d472a76..67ce7d572 100644 --- a/.github/workflows/dev-notification.yml +++ b/.github/workflows/dev-notification.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: env: - ECR_IMAGE_TAG: "NOTIFICATION_v_${{ github.run_number }}" + ECR_IMAGE_TAG: "NOTIFICATION_V_${{ github.run_number }}" ECR_REPOSITORY: "dev-services" AWS_REGION: "ap-southeast-1" CLUSTER: "DEV-NGOTAG-CLUSTER" @@ -42,7 +42,7 @@ jobs: env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: dev-services - IMAGE_TAG: "NOTIFICATION_v_${{ github.run_number }}" + IMAGE_TAG: "NOTIFICATION_V_${{ github.run_number }}" run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfiles/Dockerfile.notification . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG @@ -52,7 +52,7 @@ jobs: run: | echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV echo "ECR_REPOSITORY=dev-services" >> $GITHUB_ENV - echo "IMAGE_TAG=NOTIFICATION_v_${{ github.run_number }}" >> $GITHUB_ENV + echo "IMAGE_TAG=NOTIFICATION_V_${{ github.run_number }}" >> $GITHUB_ENV - name: Print environment variables run: | @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/notification-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/notification-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/notification-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/notification-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-organization.yml b/.github/workflows/dev-organization.yml index 097d08c29..a8e4c4c8e 100644 --- a/.github/workflows/dev-organization.yml +++ b/.github/workflows/dev-organization.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: env: - ECR_IMAGE_TAG: "ORGANIZATION_v_${{ github.run_number }}" + ECR_IMAGE_TAG: "ORGANIZATION_V_${{ github.run_number }}" ECR_REPOSITORY: "dev-services" AWS_REGION: "ap-southeast-1" CLUSTER: "DEV-NGOTAG-CLUSTER" @@ -42,7 +42,7 @@ jobs: env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: dev-services - IMAGE_TAG: "ORGANIZATION_v_${{ github.run_number }}" + IMAGE_TAG: "ORGANIZATION_V_${{ github.run_number }}" run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfiles/Dockerfile.organization . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG @@ -52,7 +52,7 @@ jobs: run: | echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV echo "ECR_REPOSITORY=dev-services" >> $GITHUB_ENV - echo "IMAGE_TAG=ORGANIZATION_v_${{ github.run_number }}" >> $GITHUB_ENV + echo "IMAGE_TAG=ORGANIZATION_V_${{ github.run_number }}" >> $GITHUB_ENV - name: Print environment variables run: | @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/organization-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/organization-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/organization-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/organization-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-user.yml b/.github/workflows/dev-user.yml index c5951ac04..2e137823d 100644 --- a/.github/workflows/dev-user.yml +++ b/.github/workflows/dev-user.yml @@ -3,7 +3,10 @@ name: Build and deploy Node.js app to ECSsdc on: push: branches: - - pipeline-implementation + - develop + paths: + - 'apps/user/**' + workflow_dispatch: env: ECR_IMAGE_TAG: "USER_v_${{ github.run_number }}" diff --git a/.github/workflows/dev-utility.yml b/.github/workflows/dev-utility.yml index 9409d47c5..8b14593cf 100644 --- a/.github/workflows/dev-utility.yml +++ b/.github/workflows/dev-utility.yml @@ -67,19 +67,37 @@ jobs: - name: Replace executionRoleArn in task definition run: | - sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/utiliti-service.json + sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/utility-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | - FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/utiliti-service.json) - NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/utiliti-service.json) + FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/utility-service.json) + NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/utility-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file - sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/utiliti-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json + sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/utility-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json # Debug: Print the content of the modified JSON file cat ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-verification.yml b/.github/workflows/dev-verification.yml index 6f1e1ffaa..f4228397e 100644 --- a/.github/workflows/dev-verification.yml +++ b/.github/workflows/dev-verification.yml @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/verification-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/verification-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/verification-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/verification-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/.github/workflows/dev-webhook.yml b/.github/workflows/dev-webhook.yml index 2ae97460a..d3bc0fd0f 100644 --- a/.github/workflows/dev-webhook.yml +++ b/.github/workflows/dev-webhook.yml @@ -52,7 +52,7 @@ jobs: run: | echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV echo "ECR_REPOSITORY=dev-services" >> $GITHUB_ENV - echo "IMAGE_TAG=WEBHOOK_v_${{ github.run_number }}" >> $GITHUB_ENV + echo "IMAGE_TAG=WEBHOOK_V_${{ github.run_number }}" >> $GITHUB_ENV - name: Print environment variables run: | @@ -69,12 +69,12 @@ jobs: run: | sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/webhook-service.json - - name: Update Task Definition + - name: Update Task Definition and service run: | FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/webhook-service.json) NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/webhook-service.json) SERVICE_NAME="${NAME}-service" - + # Replace placeholders in the JSON file sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/webhook-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json @@ -83,3 +83,21 @@ jobs: # Register the task definition using the modified JSON file aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }} + + SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1) + + # Check if the service exists + if [ -z "$SERVICE_INFO" ]; then + echo "Service does not exist, creating new service..." + # Your logic to create a new service goes here + else + echo "Entered existing service" + # Extract desired count from the stored service info + DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount') + if [ "$DESIRED_COUNT" = "0" ]; then + DESIRED_COUNT="1" + fi + # Update the existing service + REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision') + aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT} + fi \ No newline at end of file diff --git a/taskdef/api-gateway-service b/taskdef/api-gateway-service.json similarity index 100% rename from taskdef/api-gateway-service rename to taskdef/api-gateway-service.json diff --git a/taskdef/utiliti-service.json b/taskdef/utility-service.json similarity index 100% rename from taskdef/utiliti-service.json rename to taskdef/utility-service.json