-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (54 loc) · 2.03 KB
/
deploy-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
name: Deploy containers AWS ECS
on:
push:
branches:
- main
paths:
- "backend/**"
pull_request:
branches:
- main
paths:
- "backend/**"
jobs:
deploy-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install AWS CLI
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --update
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Retrieve Redis Password from AWS Secrets Manager
run: |
REDIS_PASSWORD=$(aws secretsmanager get-secret-value \
--secret-id redis_password \
--query SecretString \
--output text)
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> $GITHUB_ENV
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v1
- name: Build Docker image
working-directory: ./backend
run: |
docker buildx build \
--platform linux/amd64 \
--provenance=false \
--build-arg REDIS_PASSWORD="${REDIS_PASSWORD}" \
-t ${{ secrets.ECR_REPOSITORY_NAME }}:latest \
--load .
- name: Tag Docker image
working-directory: ./backend
run: docker tag book-search-backend-service:latest 312093527157.dkr.ecr.us-east-2.amazonaws.com/book-search-backend-service:latest
- name: Push Docker image
run: docker push 312093527157.dkr.ecr.us-east-2.amazonaws.com/book-search-backend-service:latest
- name: Update the ECS Service
run: aws ecs update-service --cluster ecs-cluster-fast-api--cluster --service rest-api-load-balancer-service --force-new-deployment --region us-east-2