Skip to content

Commit 5aebe50

Browse files
RustyRoryclaude
andcommitted
feat(deploy): configure vps-monitor deployment
- deployment/docker-compose.yml: lucky7-front (8081) + lucky7-back (4001), shared mongo - frontend Dockerfile: add NEXT_PUBLIC_BACKEND_URL build arg - socket.ts: parse backend URL to extract origin and socket.io path for reverse proxy support - deploy-staging.yml: replace SSH with vps-monitor API Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 60d1260 commit 5aebe50

4 files changed

Lines changed: 52 additions & 60 deletions

File tree

.github/workflows/deploy-staging.yml

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -116,61 +116,18 @@ jobs:
116116
needs: [lint, test-unit, test-e2e]
117117

118118
steps:
119-
- name: Checkout code
120-
uses: actions/checkout@v4
121-
122-
- name: Deploy via SSH
123-
uses: appleboy/ssh-action@v1.0.3
124-
with:
125-
host: ${{ secrets.VPS_HOST }}
126-
username: ${{ secrets.VPS_USER }}
127-
key: ${{ secrets.VPS_SSH_KEY }}
128-
port: 22
129-
command_timeout: 30m
130-
script: |
131-
set -e
132-
echo "🚀 Déploiement Lucky7 — staging"
133-
134-
REPO_DIR="/var/www/Lucky7"
135-
COMPOSE_FILE="/var/www/docker-compose.yml"
136-
137-
# ── Cloner ou mettre à jour le repo ──────────────────────────
138-
if [ ! -d "$REPO_DIR/.git" ]; then
139-
echo "📥 Premier déploiement — clonage du repo..."
140-
git clone https://github.com/${{ github.repository }}.git "$REPO_DIR"
141-
git -C "$REPO_DIR" checkout staging
142-
else
143-
echo "🔄 Mise à jour du code..."
144-
git -C "$REPO_DIR" fetch origin staging
145-
git -C "$REPO_DIR" reset --hard origin/staging
146-
fi
147-
echo "✅ Code à jour"
148-
149-
# ── Vérifier que le .env backend existe ───────────────────────
150-
ENV_FILE="$REPO_DIR/lucky7-app/backend/.env"
151-
if [ ! -f "$ENV_FILE" ]; then
152-
echo "❌ Fichier .env manquant : $ENV_FILE"
153-
echo " Créez-le manuellement sur le VPS avant de déployer."
154-
exit 1
155-
fi
156-
echo "✅ Fichier .env backend trouvé"
157-
158-
# ── Rebuild et restart uniquement les services Lucky7 ─────────
159-
echo "🔨 Build des images..."
160-
docker-compose -f "$COMPOSE_FILE" build lucky7-back lucky7-front
161-
162-
echo "🔄 Redémarrage des containers..."
163-
docker-compose -f "$COMPOSE_FILE" up -d --remove-orphans lucky7-back lucky7-front
164-
165-
echo "✅ Containers démarrés"
166-
167-
# ── Nettoyage des images obsolètes ────────────────────────────
168-
docker image prune -f
169-
170-
# ── Vérification finale ───────────────────────────────────────
171-
echo ""
172-
echo "📊 État des containers Lucky7 :"
173-
docker ps --filter "name=lucky7-" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
174-
175-
echo ""
176-
echo "🎉 Déploiement terminé !"
119+
- name: Trigger update via vps-monitor
120+
run: |
121+
curl -sf -c cookies.txt \
122+
-X POST "${{ secrets.VPS_MONITOR_URL }}/auth/login" \
123+
-H "Content-Type: application/json" \
124+
-d '{"username":"${{ secrets.VPS_MONITOR_USER }}","password":"${{ secrets.VPS_MONITOR_PASS }}"}' \
125+
| grep -q '"ok":true' || { echo "Échec login vps-monitor"; exit 1; }
126+
127+
curl -sf -b cookies.txt \
128+
-X POST "${{ secrets.VPS_MONITOR_URL }}/api/deploy/update" \
129+
-H "Content-Type: application/json" \
130+
-d '{"name":"Lucky7"}' \
131+
| grep -q '"ok":true' || { echo "Échec update vps-monitor"; exit 1; }
132+
133+
echo "Déploiement déclenché : http://78.138.58.95/Lucky7/"

deployment/docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
lucky7-front:
3+
build:
4+
context: ../lucky7-app/frontend
5+
args:
6+
NEXT_BASE_PATH: /Lucky7
7+
NEXT_PUBLIC_BACKEND_URL: http://78.138.58.95/Lucky7-api
8+
restart: unless-stopped
9+
ports:
10+
- "127.0.0.1:8081:3000"
11+
depends_on:
12+
- lucky7-back
13+
14+
lucky7-back:
15+
build:
16+
context: ../lucky7-app/backend
17+
restart: unless-stopped
18+
ports:
19+
- "127.0.0.1:4001:4000"
20+
environment:
21+
NODE_ENV: production
22+
PORT: "4000"
23+
HOST: lucky7-back
24+
MONGO_URI: mongodb://mongo:27017/lucky7

lucky7-app/frontend/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ FROM node:20-alpine AS builder
33

44
WORKDIR /usr/src/app
55

6-
ARG NEXT_BASE_PATH="/lucky7"
6+
ARG NEXT_BASE_PATH="/Lucky7"
77
ENV NEXT_BASE_PATH=$NEXT_BASE_PATH
88

9+
ARG NEXT_PUBLIC_BACKEND_URL="http://localhost:4000"
10+
ENV NEXT_PUBLIC_BACKEND_URL=$NEXT_PUBLIC_BACKEND_URL
11+
912
COPY package*.json ./
1013
RUN npm install
1114

lucky7-app/frontend/src/lib/socket.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ let socket: Socket | null = null;
77

88
export function getSocket(): Socket {
99
if (!socket) {
10-
socket = io(BACKEND_URL, { autoConnect: false });
10+
const url = new URL(BACKEND_URL);
11+
const hasPath = url.pathname && url.pathname !== '/';
12+
// Quand le backend est derrière un reverse proxy avec un préfixe (ex: /Lucky7-api),
13+
// socket.io-client interprète ce préfixe comme un namespace, pas un path.
14+
// On extrait donc l'origine et on construit le path socket.io manuellement.
15+
socket = io(url.origin, {
16+
path: hasPath ? url.pathname.replace(/\/$/, '') + '/socket.io' : '/socket.io',
17+
autoConnect: false,
18+
});
1119
}
1220
return socket;
1321
}

0 commit comments

Comments
 (0)