From 81a0c54d9c4fd685fc167facc0f2daf679cfdcc5 Mon Sep 17 00:00:00 2001 From: Lucas <39061310+lucasvuotto@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:31:15 +0000 Subject: [PATCH] fix: update AWS configuration values (#183) * fix: update AWS configuration values * feat: add deploy workflows for dev and mainnet --- .github/workflows/dev.deploy.yaml | 73 +++++++++++++++++++++++++++ .github/workflows/mainnet.deploy.yaml | 73 +++++++++++++++++++++++++++ .github/workflows/testnet.deploy.yaml | 17 ++++--- 3 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/dev.deploy.yaml create mode 100644 .github/workflows/mainnet.deploy.yaml diff --git a/.github/workflows/dev.deploy.yaml b/.github/workflows/dev.deploy.yaml new file mode 100644 index 00000000..d9916e9c --- /dev/null +++ b/.github/workflows/dev.deploy.yaml @@ -0,0 +1,73 @@ +name: Deploy to Amazon ECS (dev) + +on: + push: + branches: + - develop + +env: + AWS_REGION: us-east-1 + ECR_REPOSITORY: dao-frontend + ECS_CLUSTER: dao-frontend + ECS_SERVICE: dao-frontend-dev + ECS_TASK_DEFINITION: dao-frontend-dev + CONTAINER_NAME: dao-frontend-dev + + PROFILE: testnet + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + # NOTYET we need a non-free plan + #environment: + # name: dev + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_LOGIN_DEV_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg arg_env="$PROFILE" --build-arg NEXT_PUBLIC_BUILD_ID=${{ github.sha }} --no-cache . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" + + - name: Download task definition + run: aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --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.CONTAINER_NAME }} + image: ${{ steps.build-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 }} + wait-for-service-stability: true diff --git a/.github/workflows/mainnet.deploy.yaml b/.github/workflows/mainnet.deploy.yaml new file mode 100644 index 00000000..e9798971 --- /dev/null +++ b/.github/workflows/mainnet.deploy.yaml @@ -0,0 +1,73 @@ +name: Deploy to Amazon ECS (Mainnet) + +on: + push: + branches: + - develop + +env: + AWS_REGION: us-east-1 + ECR_REPOSITORY: dao-frontend + ECS_CLUSTER: dao-frontend + ECS_SERVICE: dao-frontend-mainnet + ECS_TASK_DEFINITION: dao-frontend-mainnet + CONTAINER_NAME: dao-frontend-mainnet + + PROFILE: testnet + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + # NOTYET we need a non-free plan + #environment: + # name: mainnet + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_LOGIN_MAINNET_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg arg_env="$PROFILE" --build-arg NEXT_PUBLIC_BUILD_ID=${{ github.sha }} --no-cache . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" + + - name: Download task definition + run: aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --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.CONTAINER_NAME }} + image: ${{ steps.build-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 }} + wait-for-service-stability: true diff --git a/.github/workflows/testnet.deploy.yaml b/.github/workflows/testnet.deploy.yaml index 2dc75dd6..b52e9967 100644 --- a/.github/workflows/testnet.deploy.yaml +++ b/.github/workflows/testnet.deploy.yaml @@ -6,10 +6,10 @@ on: - develop env: - AWS_REGION: us-east-1 - ECR_REPOSITORY: rif-dao-frontend + AWS_REGION: us-east-1 + ECR_REPOSITORY: dao-frontend + ECS_CLUSTER: dao-frontend ECS_SERVICE: dao-frontend-testnet - ECS_CLUSTER: dao-frontend-testnet ECS_TASK_DEFINITION: dao-frontend-testnet CONTAINER_NAME: dao-frontend-testnet @@ -19,8 +19,9 @@ jobs: deploy: name: Deploy runs-on: ubuntu-latest - environment: - name: testnet + # NOTYET we need a non-free plan + #environment: + # name: testnet permissions: id-token: write contents: read @@ -32,7 +33,7 @@ jobs: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: ${{ secrets.ROLE_ECS_ARN }} + role-to-assume: ${{ secrets.AWS_LOGIN_TESTNET_ROLE_ARN }} aws-region: ${{ env.AWS_REGION }} - name: Login to Amazon ECR @@ -51,7 +52,7 @@ jobs: docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg arg_env="$PROFILE" --build-arg NEXT_PUBLIC_BUILD_ID=${{ github.sha }} --no-cache . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" - + - name: Download task definition run: aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --query taskDefinition > task-definition.json @@ -69,4 +70,4 @@ jobs: task-definition: ${{ steps.task-def.outputs.task-definition }} service: ${{ env.ECS_SERVICE }} cluster: ${{ env.ECS_CLUSTER }} - wait-for-service-stability: true \ No newline at end of file + wait-for-service-stability: true