Merge pull request #34 from GovTechSG/fix/og-tags-2 #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deployment | |
on: | |
push: | |
branches: | |
- main | |
- staging | |
paths: | |
- "packages/app/**" | |
- "yarn.lock" | |
- ".github/workflows/app-*.yml" | |
env: | |
AWS_REGION: ${{ vars.AWS_REGION }} | |
jobs: | |
check-env: | |
name: Set Deployment Environment | |
runs-on: ubuntu-latest | |
outputs: | |
environment: ${{ steps.set-env.outputs.ENVIRONMENT }} | |
steps: | |
- name: Set Environment Output | |
id: set-env | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "ENVIRONMENT=production" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref }}" == "refs/heads/staging" ]]; then | |
echo "ENVIRONMENT=staging" >> $GITHUB_OUTPUT | |
else | |
echo "ENVIRONMENT=unknown" >> $GITHUB_OUTPUT | |
fi | |
echo "Deployment environment: $ENVIRONMENT" | |
deploy: | |
name: Deploy App Service (${{ needs.check-env.outputs.environment }}) | |
runs-on: ubuntu-latest | |
environment: ${{ needs.check-env.outputs.environment }} | |
needs: check-env | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
role-duration-seconds: 1200 | |
role-session-name: AssumeDeploymentSession | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
mask-password: true | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
working-directory: ${{ github.workspace }} | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ vars.APP_ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build \ | |
--build-arg INFURA_API_KEY=${{ secrets.INFURA_API_KEY }} \ | |
--build-arg ALCHEMY_API_KEY=${{ secrets.ALCHEMY_API_KEY }} \ | |
--build-arg WALLETCONNECT_PROJECT_ID=${{ vars.APP_WALLETCONNECT_PROJECT_ID }} \ | |
--build-arg ENABLE_MAINNETS=${{ vars.APP_ENABLE_MAINNETS }} \ | |
--build-arg ENABLE_TESTNETS=${{ vars.APP_ENABLE_TESTNETS }} \ | |
--build-arg ENABLE_HARDHAT_NODE=${{ vars.APP_ENABLE_HARDHAT_NODE }} \ | |
--build-arg ENABLE_AUTOMATION=${{ vars.APP_ENABLE_AUTOMATION }} \ | |
--build-arg GA_MEASUREMENT_ID=${{ vars.APP_GA_MEASUREMENT_ID }} \ | |
-f packages/app/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Get Task Definition | |
working-directory: ${{ github.workspace }} | |
run: | | |
aws ecs describe-task-definition \ | |
--task-definition ${{ vars.APP_TASK_DEF_NAME }} \ | |
--query taskDefinition \ | |
--output json > 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: ${{ vars.APP_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: ${{ vars.APP_SERVICE_NAME }} | |
cluster: ${{ vars.CLUSTER_NAME }} | |
wait-for-service-stability: true |