-
Notifications
You must be signed in to change notification settings - Fork 3
74 lines (56 loc) · 1.79 KB
/
CD.yaml
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
name: CD
on:
push:
branches:
- dev
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install pnpm
run: npm install pnpm -g
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies and build
run: |
pnpm install
pnpm build
- name: Deploy to Ubuntu server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
# NVM setup
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install pnpm pm2
npm install -g pnpm
npm install -g pm2
# move to directory and pull latest changes
cd ../var/www/harmony
git pull origin dev
# Install dependencies
pnpm install
# Delete existing .env
rm apps/server/.env
rm apps/client/.env
# Add envs
echo "${{ secrets.SERVER_ENV }}" >> apps/server/.env
echo "${{ secrets.CLIENT_ENV }}" >> apps/client/.env
# Build
pnpm build
# Start second instance
pm2 start apps/server/ecosystem.config.js --only harmony-api2 --env production
sleep 5
# Restart first instance
pm2 restart apps/server/ecosystem.config.js --env production || pm2 start apps/server/ecosystem.config.js --env production
sleep 5
# Stop second instance
pm2 stop harmony-api2
echo "Deployment Success"