Skip to content

Commit

Permalink
fix: update AWS configuration values (#183)
Browse files Browse the repository at this point in the history
* fix: update AWS configuration values

* feat: add deploy workflows for dev and mainnet
  • Loading branch information
lucasvuotto authored Sep 12, 2024
1 parent a5e0eae commit 81a0c54
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 8 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/dev.deploy.yaml
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions .github/workflows/mainnet.deploy.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 9 additions & 8 deletions .github/workflows/testnet.deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
wait-for-service-stability: true

0 comments on commit 81a0c54

Please sign in to comment.