-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (73 loc) · 2.56 KB
/
Copy pathcd.yml
File metadata and controls
84 lines (73 loc) · 2.56 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
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
82
83
84
name: Continuous Deployment
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: cd-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
DEPLOY_PATH: /var/www/proxy
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 24
- name: Install dependencies
run: npm ci
- name: Apply migrations && Generate Prisma client
env:
POSTGRES_URL: ${{ secrets.POSTGRES_URL }}
run: npm run db:migrate:deploy -w apps/backend && npm run db:generate -w apps/backend
- name: Build backend and web application
run: npm run build -w apps/backend && npm run build -w apps/web
- name: Check SSH connection
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
- name: Create target directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
script: |
sudo mkdir -p ${{ env.DEPLOY_PATH }}
sudo chown -R ${{ secrets.AWS_EC2_USERNAME }}:${{ secrets.AWS_EC2_USERNAME }} ${{ env.DEPLOY_PATH }}
- name: Deploy to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
source: ".,!.git,!node_modules"
target: ${{ env.DEPLOY_PATH }}
strip_components: 1
overwrite: true
- name: Install staging deps, Prisma client, and start backend and web applications (PM2)
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
script: |
set -e
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
cd ${{ env.DEPLOY_PATH }}
npm ci
npm run db:generate -w apps/backend
pm2 delete all 2>/dev/null || true
pm2 start ecosystem.config.js --env staging