-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (102 loc) · 3.8 KB
/
Copy pathdeploy-web.yml
File metadata and controls
113 lines (102 loc) · 3.8 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
name: 🚀 Build & Deploy Nuxt web to VPS
on:
push:
branches: [main]
paths:
- 'web/**'
- '.github/workflows/deploy-web.yml'
workflow_dispatch:
concurrency:
group: nightforge-web-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-deploy:
name: 🏗️ Build & Deploy
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
web
- name: ⚙️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: 📦 Install dependencies
run: npm ci
working-directory: ./web
- name: 📝 Setup environment file
run: |
cd web
cp .env.example .env || touch .env
echo "NODE_ENV=production" >> .env
- name: 🛠️ Build Nitro (SSR)
run: npm run pwa:icons && npm run build
working-directory: ./web
env:
NITRO_PRESET: node-server
NODE_ENV: production
NUXT_PUBLIC_API_BASE: ${{ secrets.NUXT_PUBLIC_API_BASE || 'https://api.nightforge.dibodev.fr' }}
- name: 🧹 Prepare server directory on VPS
if: github.event_name != 'pull_request'
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
set -e
WEB_ROOT="/var/www/nightforge.dibodev.fr"
DEPLOY_USER="${{ secrets.SSH_USERNAME }}"
sudo mkdir -p "$WEB_ROOT/html" "$WEB_ROOT/server"
sudo rm -rf "$WEB_ROOT/server"
sudo mkdir -p "$WEB_ROOT/server"
sudo chown -R "$DEPLOY_USER:$DEPLOY_USER" "$WEB_ROOT"
- name: 📤 Deploy web assets
if: github.event_name != 'pull_request'
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: 'web/.output/public/'
target: '/var/www/nightforge.dibodev.fr/html'
strip_components: 3
- name: 📤 Deploy Nitro server
if: github.event_name != 'pull_request'
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: 'web/.output/server/'
target: '/var/www/nightforge.dibodev.fr/server'
strip_components: 3
tar_dereference: true
overwrite: true
- name: 🛠️ Start Nitro server (pm2)
if: github.event_name != 'pull_request'
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
WEB_ROOT="/var/www/nightforge.dibodev.fr"
# Nitro serves `public/` assets from ../public relative to server/ — symlink html → public.
ln -sfn "$WEB_ROOT/html" "$WEB_ROOT/public"
cd "$WEB_ROOT/server"
command -v node || {
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
}
command -v pm2 || npm install -g pm2
pm2 describe nightforge.dibodev.fr > /dev/null 2>&1 && pm2 delete nightforge.dibodev.fr || true
PORT=5620 pm2 start index.mjs --name nightforge.dibodev.fr --env production
pm2 save
sudo nginx -t && sudo systemctl reload nginx