-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: setup-staging-alt3-ghactions #8025
Open
kevin9foong
wants to merge
10
commits into
develop
Choose a base branch
from
staging-alt3
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
917b3e2
feat: add deploy to ECR
kevin9foong a89ac40
fix: add dd and fe env vars
kevin9foong b79e67d
fix: add checkout code
kevin9foong eff1bfa
fix: include fetch depth 0
kevin9foong 3f1f1dc
fix: include dd secrets
kevin9foong d313f5d
fix: add depths and env
kevin9foong 2343a6d
chore: remove failing dd command
kevin9foong 915afa6
feat: add task defintion for ecs
kevin9foong 6a4e753
feat: add script to populate value
kevin9foong cbef06c
fix: uncomment unintended comment
kevin9foong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
name: Deploy to AWS ECS | ||
on: | ||
push: | ||
branches: | ||
- staging-alt3 | ||
|
||
# used to configure IAM to trust Github's OIDC provider | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
set_environment: | ||
name: Set environment for deployment | ||
description: Sets the environment for the deployment, which is the same as the branch name | ||
outputs: | ||
current_env: ${{ steps.set_environment.outputs.current_env }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: set_environment | ||
run: echo "current_env=${{github.ref_name}}" >> $GITHUB_OUTPUT | ||
|
||
deploy: | ||
name: Deploy to ECS | ||
needs: set_environment | ||
runs-on: ubuntu-latest | ||
environment: ${{ needs.set_environment.outputs.current_env }} | ||
env: | ||
IMAGE_TAG: github-actions-${{ github.sha }}-${{ github.run_id }}-${{github.run_attempt}} | ||
CURRENT_ENV: ${{ needs.set_environment.outputs.current_env }} | ||
steps: | ||
- name: Checkout branch source code into runner environment | ||
description: Required for the frontend build env vars | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup secrets for datadog sourcemap deployment | ||
run: | | ||
echo "APP_VERSION=$(jq -r .version package.json)-$(echo ${GITHUB_REF##*/})-$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_ENV | ||
|
||
- name: Inject frontend build env vars | ||
env: | ||
VITE_APP_DD_RUM_APP_ID: ${{ secrets.DD_RUM_APP_ID }} | ||
VITE_APP_DD_RUM_CLIENT_TOKEN: ${{ secrets.DD_RUM_CLIENT_TOKEN }} | ||
VITE_APP_DD_RUM_ENV: ${{ secrets.DD_ENV }} | ||
VITE_APP_DD_SAMPLE_RATE: ${{ secrets.DD_SAMPLE_RATE }} | ||
VITE_APP_GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }} | ||
VITE_APP_FORMSG_SDK_MODE: ${{ secrets.REACT_APP_FORMSG_SDK_MODE }} | ||
VITE_APP_URL: ${{ secrets.APP_URL }} | ||
run: | | ||
sed -i -e "s|@VITE_APP_URL|${{secrets.APP_URL}}|g" -e "s/@VITE_APP_DD_RUM_APP_ID/$VITE_APP_DD_RUM_APP_ID/g" -e "s/@VITE_APP_DD_RUM_CLIENT_TOKEN/$VITE_APP_DD_RUM_CLIENT_TOKEN/g" -e "s/@VITE_APP_DD_RUM_ENV/$VITE_APP_DD_RUM_ENV/g" -e "s/@VITE_APP_VERSION/${{env.APP_VERSION}}/g" -e "s/@VITE_APP_DD_SAMPLE_RATE/$VITE_APP_DD_SAMPLE_RATE/g" frontend/datadog-chunk.ts | ||
echo VITE_APP_VERSION=${{env.APP_VERSION}} > frontend/.env | ||
echo VITE_APP_URL=$VITE_APP_URL > frontend/.env | ||
echo VITE_APP_GA_TRACKING_ID=$VITE_APP_GA_TRACKING_ID >> frontend/.env | ||
echo VITE_APP_FORMSG_SDK_MODE=$VITE_APP_FORMSG_SDK_MODE >> frontend/.env | ||
echo VITE_APP_DD_RUM_CLIENT_TOKEN=$VITE_APP_DD_RUM_CLIENT_TOKEN >> frontend/.env | ||
echo VITE_APP_DD_RUM_ENV=$VITE_APP_DD_RUM_ENV >> frontend/.env | ||
|
||
- name: Configure AWS credentials | ||
description: Configures the runner environment with AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
env: | ||
AWS_REGION: ${{ secrets.DEFAULT_AWS_REGION }} | ||
with: | ||
role-to-assume: ${{ secrets.AWS_CI_ROLE_TO_ASSUME }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
env: | ||
DD_API_KEY: ${{ secrets.DD_API_KEY }} | ||
DD_ENV: ${{ secrets.DD_ENV }} | ||
ECR_REPOSITORY: ${{ secrets.ECR_REPO }}-${{ env.CURRENT_ENV }} | ||
with: | ||
context: . | ||
file: Dockerfile.production | ||
push: true | ||
tags: | | ||
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | ||
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest | ||
build-args: | | ||
APP_VERSION=${{ env.APP_VERSION }} | ||
APP_URL=${{ secrets.APP_URL }} | ||
REPO_URL=${{ github.server_url }}/${{ github.repository }} | ||
secrets: | | ||
"dd_api_key=${{ secrets.DD_API_KEY }}" | ||
|
||
- name: Fill in the new image ID in the Amazon ECS task definition | ||
description: Create a new task definition file with the image to be deployed | ||
id: task-def | ||
env: | ||
ECS_TASK_DEFINITION: ecs-task-definition.json | ||
CONTAINER_NAME: formsg-app | ||
uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc | ||
with: | ||
task-definition: ${{ env.ECS_TASK_DEFINITION }} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | ||
environment-variables: | | ||
ENV_TYPE=${{ contains(env.CURRENT_ENV, 'staging') && 'staging' || contains(env.CURRENT_ENV, 'prod') && 'prod' || contains(env.CURRENT_ENV, 'uat') && 'uat' || env.CURRENT_ENV }} | ||
ENV_SITE_NAME=${{ env.CURRENT_ENV }} | ||
|
||
- name: Deploy Amazon ECS task definition | ||
env: # For ECS deployment | ||
ECS_SERVICE: ${{ sectets.ECS_SERVICE }} | ||
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }} | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: ${{ env.ECS_SERVICE }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
wait-for-service-stability: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
{ | ||
"containerDefinitions": [ | ||
{ | ||
"name": "formsg-app", | ||
"essential": true, | ||
"command": "/bin/sh -c \"./generate-env-from-ecs-params.sh && npm start\"", | ||
"portMappings": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to config the port mappings, ecs task and execution role etc |
||
{ "containerPort": 3000 } | ||
] | ||
} | ||
], | ||
"family": "formsg-app", | ||
"requiresCompatibilities": [ | ||
"FARGATE" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
TARGET_DIR=/etc/formsg | ||
ENV_TYPE=$ENV_TYPE | ||
ENV_SITE_NAME=$ENV_SITE_NAME | ||
|
||
# create target dir if not exist | ||
echo "Checking if ${TARGET_DIR} exists..." | ||
if [ ! -d ${TARGET_DIR} ]; then | ||
echo "Creating directory ${TARGET_DIR} ..." | ||
mkdir -p ${TARGET_DIR} | ||
if [ $? -ne 0 ]; then | ||
echo 'ERROR: Directory creation failed!' | ||
exit 1 | ||
fi | ||
else | ||
echo "Directory ${TARGET_DIR} already exists!" | ||
fi | ||
|
||
echo "${ENV_TYPE}-general" > $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-captcha" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-turnstile" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-ga" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-intranet" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-sms" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-ndi" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-verified-fields" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-webhook-verified-content" >> $TARGET_DIR/.env | ||
echo "${ENV_TYPE}-wogaa" >> $TARGET_DIR/.env | ||
echo "${ENV_SITE_NAME}-sgid" >> $TARGET_DIR/.env | ||
echo "${ENV_SITE_NAME}-payment" >> $TARGET_DIR/.env | ||
echo "${ENV_SITE_NAME}-cron-payment" >> $TARGET_DIR/.env | ||
echo "${ENV_SITE_NAME}-openai" >> $TARGET_DIR/.env |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to configure the s3 bucket image upload, static file upload and check if any dd config is still needed.
also, ensure that able to push to ECR