-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (128 loc) · 4.4 KB
/
Copy pathdeploy-web.yml
File metadata and controls
142 lines (128 loc) · 4.4 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
136
137
138
139
140
141
142
# Deploy Nuxt 4 frontend (web/) to the VPS — Nitro node-server + PM2.
# Required secrets: see deploy README or repo configuration message.
name: Deploy web (Nuxt)
on:
push:
branches: [main]
paths:
- 'web/**'
- '.github/workflows/deploy-web.yml'
pull_request:
branches: [main]
paths:
- 'web/**'
workflow_dispatch:
concurrency:
group: goupixdex-web-${{ github.ref }}
cancel-in-progress: true
jobs:
build-pr:
name: Build (PR — sans déploiement)
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
defaults:
run:
working-directory: web
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: npm
cache-dependency-path: web/package-lock.json
- name: Install & build
env:
NUXT_PUBLIC_API_BASE: https://example.com
NUXT_PUBLIC_SITE_URL: https://example.com
run: |
npm ci
npm run build
deploy:
name: Build & deploy
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
runs-on: ubuntu-latest
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
defaults:
run:
working-directory: web
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: npm
cache-dependency-path: web/package-lock.json
- name: Install dependencies
run: npm ci
- name: Write production .env (build)
env:
NUXT_PUBLIC_API_BASE: ${{ secrets.NUXT_PUBLIC_API_BASE }}
NUXT_PUBLIC_SITE_URL: ${{ secrets.NUXT_PUBLIC_SITE_URL }}
NUXT_PUBLIC_GITHUB_REPO: ${{ github.repository }}
NUXT_PUBLIC_DESKTOP_RELEASE_CHANNEL: latest
run: |
{
echo "NODE_ENV=production"
echo "NUXT_PUBLIC_API_BASE=${NUXT_PUBLIC_API_BASE}"
echo "NUXT_PUBLIC_SITE_URL=${NUXT_PUBLIC_SITE_URL}"
echo "NUXT_PUBLIC_GITHUB_REPO=${NUXT_PUBLIC_GITHUB_REPO}"
echo "NUXT_PUBLIC_DESKTOP_RELEASE_CHANNEL=${NUXT_PUBLIC_DESKTOP_RELEASE_CHANNEL}"
} > .env
- name: Build Nuxt (Nitro)
env:
NUXT_BUILD_COMMIT: ${{ github.sha }}
run: npm run build
- name: Pack .output
working-directory: ${{ github.workspace }}
run: tar -czf nuxt-output.tar.gz -C web .output
- name: Upload bundle to VPS
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: nuxt-output.tar.gz
target: ${{ secrets.DEPLOY_WEB_DIR }}
- name: Extract, PM2 & Nginx
uses: appleboy/ssh-action@v1.0.3
env:
DEPLOY_WEB_DIR: ${{ secrets.DEPLOY_WEB_DIR }}
WEB_PM2_APP_NAME: ${{ secrets.WEB_PM2_APP_NAME }}
WEB_APP_PORT: ${{ secrets.WEB_APP_PORT }}
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: DEPLOY_WEB_DIR,WEB_PM2_APP_NAME,WEB_APP_PORT
script_stop: true
script: |
set -euo pipefail
DEPLOY="${DEPLOY_WEB_DIR%/}"
APP_NAME="${WEB_PM2_APP_NAME:-goupixdex-web}"
WEB_PORT="${WEB_APP_PORT:-3000}"
mkdir -p "$DEPLOY"
tar -xzf "$DEPLOY/nuxt-output.tar.gz" -C "$DEPLOY"
rm -f "$DEPLOY/nuxt-output.tar.gz"
if ! command -v node >/dev/null 2>&1; then
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
if ! command -v pm2 >/dev/null 2>&1; then
sudo npm install -g pm2
fi
cd "$DEPLOY/.output"
pm2 describe "$APP_NAME" >/dev/null 2>&1 && pm2 delete "$APP_NAME" || true
PORT="$WEB_PORT" HOST=127.0.0.1 NODE_ENV=production pm2 start server/index.mjs --name "$APP_NAME"
pm2 save
pm2 list
sudo nginx -t
sudo systemctl reload nginx