-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (44 loc) · 1.47 KB
/
deploy-backend.yml
File metadata and controls
54 lines (44 loc) · 1.47 KB
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
name: Deploy Backend
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- "backend/**"
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::413576439231:role/GitHubActionsCodeChallengeGeneratorRole
aws-region: us-east-1
- name: Login to ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Build image
run: |
docker build -t ccg-backend ./backend
- name: Tag image
run: |
docker tag ccg-backend:latest \
413576439231.dkr.ecr.us-east-1.amazonaws.com/ccg-backend:latest
- name: Push image
run: |
docker push \
413576439231.dkr.ecr.us-east-1.amazonaws.com/ccg-backend:latest
- name: Deploy on EC2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 413576439231.dkr.ecr.us-east-1.amazonaws.com
docker pull 413576439231.dkr.ecr.us-east-1.amazonaws.com/ccg-backend:latest
docker rm -f ccg-backend || true
/usr/local/bin/ccg-backend-run.sh