From e35eabe94cab76c9e18904fdf656d634869de5d1 Mon Sep 17 00:00:00 2001 From: Sny Date: Mon, 14 Oct 2024 13:55:27 +0530 Subject: [PATCH] OpenConceptLab/ocl_issues#1934 | Staging v3 deployment github job --- .github/workflows/build.yml | 71 +++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 610f07e5..7e8c5a6e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,8 +7,10 @@ on: env: AWS_REGION: "us-east-2" # set this to your preferred AWS region, e.g. us-west-1 ECR_REPOSITORY: "oclweb3" # set this to your Amazon ECR repository name - ECS_SERVICE: "qa-web3" # set this to your Amazon ECS service name - ECS_CLUSTER: "ocl-qa-demo" # set this to your Amazon ECS cluster name + ECS_SERVICE_QA: "qa-web3" # set this to your Amazon ECS service name + ECS_CLUSTER_QA: "ocl-qa-demo" # set this to your Amazon ECS cluster name + ECS_SERVICE_STAGING: "staging-web3" # set this to your Amazon ECS service name + ECS_CLUSTER_STAGING: "ocl-staging-production" # set this to your Amazon ECS cluster name jobs: @@ -80,7 +82,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - deploy: + deploy-qa: needs: [release] name: Deploy to QA runs-on: ubuntu-latest @@ -120,18 +122,73 @@ jobs: echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT - name: Download task definition run: | - aws ecs describe-task-definition --task-definition $ECS_SERVICE --query taskDefinition > task-definition.json + aws ecs describe-task-definition --task-definition $ECS_SERVICE_QA --query taskDefinition > task-definition.json - name: Fill in the new image ID in the Amazon ECS task definition id: task-def uses: aws-actions/amazon-ecs-render-task-definition@v1 with: task-definition: "task-definition.json" - container-name: ${{ env.ECS_SERVICE }} + container-name: ${{ env.ECS_SERVICE_QA }} image: ${{ steps.push-image.outputs.image }} - name: Deploy Amazon ECS task definition uses: aws-actions/amazon-ecs-deploy-task-definition@v1 with: task-definition: ${{ steps.task-def.outputs.task-definition }} - service: ${{ env.ECS_SERVICE }} - cluster: ${{ env.ECS_CLUSTER }} + service: ${{ env.ECS_SERVICE_QA }} + cluster: ${{ env.ECS_CLUSTER_QA }} + deploy-staging: + needs: [deploy-qa] + name: Deploy to Staging + runs-on: ubuntu-latest + environment: staging + + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + 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@v1 + - name: Checkout repo + uses: actions/checkout@v3 + - name: Get npm version + id: package-version + uses: martinbeentjes/npm-get-version-action@v1.3.1 + - name: Add GITHUB_SHA_SHORT env property with commit short sha + run: echo "GITHUB_SHA_SHORT=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV + - name: Push image to Amazon ECR + id: push-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ steps.package-version.outputs.current-version}}-${{env.GITHUB_SHA_SHORT}} + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker pull openconceptlab/oclweb3:$IMAGE_TAG + docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:staging + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker push $ECR_REGISTRY/$ECR_REPOSITORY:staging + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + - name: Download task definition + run: | + aws ecs describe-task-definition --task-definition $ECS_SERVICE_STAGING --query taskDefinition > task-definition.json + - name: Fill in the new image ID in the Amazon ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: "task-definition.json" + container-name: ${{ env.ECS_SERVICE_STAGING }} + image: ${{ steps.push-image.outputs.image }} + + - name: Deploy Amazon ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ env.ECS_SERVICE_STAGING }} + cluster: ${{ env.ECS_CLUSTER_STAGING }}