-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (103 loc) · 3.63 KB
/
Copy pathdeploy-stage.yml
File metadata and controls
135 lines (103 loc) · 3.63 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Deploy to EC2 (stage)
on:
push:
branches:
- stage
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
# BUILD FRONTEND
- name: Build Frontend
env:
NEXT_PUBLIC_API_BASE_URL: https://api.autospace.space
BASE_URL_API: https://api.autospace.space
NEXT_PUBLIC_API_URL : https://api.autospace.space
NEXT_PUBLIC_R2_PUBLIC_BASE_URL : https://pub-ff3db0610a93483399825b1ebf0d5e7d.r2.dev
NEXT_PUBLIC_GOOGLE_CLIENT_ID : 1045346971721-nkrtqj1a7on5038ao84n1s4do7muf3si.apps.googleusercontent.com
run: |
cd nextjs-autospace
pnpm install
pnpm build
# PACKAGE EVERYTHING NEEDED
- name: Compress Frontend
run: |
cd nextjs-autospace
tar -czf frontend.tar.gz .next public
# SSH SETUP
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
# UPLOAD BUILD
- name: Upload to EC2
run: |
scp -i ~/.ssh/id_ed25519 nextjs-autospace/frontend.tar.gz ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:~/frontend/
# DEPLOY EVERYTHING
- name: Deploy to EC2
run: |
ssh -i ~/.ssh/id_ed25519 ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
set -e
export CI=true
echo " Backend Deploy..."
cd ~/autospace
git fetch origin
git reset --hard origin/stage
cd nodejs-autospace/api-gateway
pnpm install
pnpm build
pm2 restart api-gateway || pm2 start dist/index.js --name api-gateway
#Auth service
cd ~/auth-service/autospace
git fetch origin
git reset --hard origin/stage
cd nodejs-autospace/auth-service
pnpm install
pnpm build
pm2 restart auth-service || pm2 start dist/server.js --name auth-service
#Resource service
cd ~/resource-service/autospace
git fetch origin
git reset --hard origin/stage
cd nodejs-autospace/resource-service
pnpm install
pnpm build
pm2 restart resource-service || pm2 start dist/server.js --name resource-service
#Booking service
cd ~/booking-service
git fetch origin
git reset --hard origin/stage
cd nodejs-autospace/booking-service
pnpm install
pnpm build
pm2 restart booking-service || pm2 start dist/server.js --name booking-service
echo " Clean frontend..."
rm -rf ~/frontend/app
mkdir -p ~/frontend/app
echo " Extract frontend..."
cd ~/frontend
tar -xzf frontend.tar.gz -C app
rm frontend.tar.gz
echo " Fix standalone runtime (IMPORTANT)"
cd ~/frontend/app/.next/standalone/nextjs-autospace
mkdir -p .next
cp -r ~/frontend/app/.next/static .next/
cp -r ~/frontend/app/.next/server .next/
cp ~/frontend/app/.next/BUILD_ID .next/
cp -r ~/frontend/app/public ./public
echo " Restart frontend"
pm2 delete frontend || true
PORT=3000 pm2 start server.js --name frontend
pm2 save
echo " DEPLOY DONE"
EOF