-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (67 loc) · 2.6 KB
/
deployment-backend.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: deployment-backend
run-name: ${{ github.workflow }} (${{ inputs.branch }})
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: 'Environment to deploy'
options:
- dev
# - prod
branch:
description: 'Branch name to deploy'
required: true
default: 'dev'
env:
ENVIRONMENT: ${{ github.event.inputs.environment }}
AWS_REGION: ap-southeast-1
defaults:
run:
shell: bash
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
- name: Print branch name
run: echo "Checked out branch ${{ github.event.inputs.branch }}"
- name: Specify Deployment Role
run: |
echo "AWS_ROLE_ARN=${{ secrets.AWS_ROLE_ARN_PLAT }}" >> $GITHUB_ENV
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-session-name: GitHubActionsWorkflow
role-duration-seconds: 900
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set Environments
run: |
REPOSITORY_NAME="plat-movement-${{ env.ENVIRONMENT }}-backend"
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV
echo "ECR_REPOSITORY=${{ steps.login-ecr.outputs.registry }}/${REPOSITORY_NAME}" >> $GITHUB_ENV
echo "ECS_TASK_SERVICE_NAME=plat-movement-${{ env.ENVIRONMENT }}-backend" >> $GITHUB_ENV
echo "ECS_CLUSTER_NAME=plat-movement-${{ env.ENVIRONMENT }}-backend" >> $GITHUB_ENV
- name: Build Docker image
run: |
cd backend && docker build -t ${{ env.ECR_REPOSITORY }}:${{ github.sha }} . -f Dockerfile.nil
- name: Tag image, and push image to ECR Repository
run: |
aws ecr put-image-tag-mutability --repository-name ${{ env.REPOSITORY_NAME }} --image-tag-mutability MUTABLE
docker tag ${{ env.ECR_REPOSITORY }}:${{ github.sha }} ${{ env.ECR_REPOSITORY }}:latest
docker push -a ${{ env.ECR_REPOSITORY }}
aws ecr put-image-tag-mutability --repository-name ${{ env.REPOSITORY_NAME }} --image-tag-mutability IMMUTABLE
- name: Update Amazon ECS Service
run: |
aws ecs update-service --service ${{ env.ECS_TASK_SERVICE_NAME }} --cluster ${{ env.ECS_CLUSTER_NAME }} --force-new-deployment