-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add cc-server pipeline * feat: add cc-server pipeline * feat: add permission * feat: add env file * feat: update env file * feat: update env file * feat: update env file * feat: update env file * feat: change container name * feat: change task definition * feat: output imageID * feat: change .env file * feat: change yml file * feat: remove grafana in taskdef-prod.json * feat: remove grafana in taskdef-prod.json * feat: change container name * feat: remove loki * feat: change taskdef-prod.json * feat: change change container name * feat: change change container name * feat: echo tag * feat: add test and lint * feat: change npm i to ci
- Loading branch information
1 parent
1dbf312
commit cbb320e
Showing
2 changed files
with
119 additions
and
37 deletions.
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,113 @@ | ||
name: Deploy to Amazon ECS | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
env: | ||
AWS_REGION: ap-southeast-2 | ||
ECR_REPOSITORY: cc-backend-dockerimage-repo | ||
ECS_SERVICE_UAT: CCS-F-UAT-service | ||
ECS_CLUSTER_UAT: CCS-F-UAT-cluster | ||
ECS_SERVICE_PROD: CCS-F-PROD-service | ||
ECS_CLUSTER_PROD: CCS-F-PROD-cluster | ||
CONTAINER_NAME_UAT: CC-UAT-container | ||
CONTAINER_NAME_PROD: CC-PROD-container | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: "Create env file" | ||
run: | | ||
echo "${{ secrets.ENV_FILE }}" > .env | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Lint code | ||
run: npm run lint | ||
|
||
- name: Test code | ||
run: npm run test | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
role-to-assume: arn:aws:iam::245866473499:role/OIDC-ECS-deployment | ||
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: | | ||
docker build -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 | ||
sed -i "s|{{imageID}}|${IMAGE_TAG}|" taskdef-uat.json | ||
sed -i "s|{{imageID}}|${IMAGE_TAG}|" taskdef-prod.json | ||
- name: Migrate DB to DEV | ||
env: | ||
DATA_MIGRATION_URL: ${{ secrets.DATA_MIGRATION_URL_DEV }} | ||
DATABASE_NAME: DEV | ||
run: npm run migrate-up | ||
|
||
- name: Render Amazon ECS task definition for uat container | ||
id: task-def-uat | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: taskdef-uat.json | ||
container-name: ${{ env.CONTAINER_NAME_UAT }} | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition for uat | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: taskdef-uat.json | ||
service: ${{ env.ECS_SERVICE_UAT }} | ||
cluster: ${{ env.ECS_CLUSTER_UAT }} | ||
wait-for-service-stability: true | ||
|
||
- name: Migrate DB to PROD | ||
env: | ||
DATA_MIGRATION_URL: ${{ secrets.DATA_MIGRATION_URL_PROD }} | ||
DATABASE_NAME: PROD | ||
run: npm run migrate-up | ||
|
||
- name: Render Amazon ECS task definition for prod container | ||
id: task-def-prod | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: taskdef-prod.json | ||
container-name: ${{ env.CONTAINER_NAME_PROD}} | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition for prod | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: taskdef-prod.json | ||
service: ${{ env.ECS_SERVICE_PROD }} | ||
cluster: ${{ env.ECS_CLUSTER_PROD }} | ||
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