Skip to content

Commit a1d1c8c

Browse files
committed
feat: test vps monitoring view
1 parent b9e50b2 commit a1d1c8c

5 files changed

Lines changed: 51 additions & 7 deletions

File tree

.github/workflows/deploy-api.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Déploie l’API FastAPI (dossier api/) sur le VPS — venv + systemd + Nginx reload.
22
# La base MariaDB peut être distante (ex. o2switch) : DATABASE_URL dans les secrets.
3+
# Sur le VPS : installe xvfb + xauth et lance Uvicorn sous xvfb-run (Chromium fenêtré si VINTED_BROWSER_HEADLESS=false).
4+
# Secret optionnel VINTED_BROWSER_HEADLESS : absent → true (historique) ; false → moins flaggé par Vinted sur Xvfb.
35

46
name: Deploy API (FastAPI)
57

@@ -76,6 +78,8 @@ jobs:
7678
CORS_ORIGINS: ${{ secrets.CORS_ORIGINS }}
7779
# Optionnel : chemin Chrome/Chromium si différent de /usr/bin/chromium
7880
VINTED_CHROME_EXECUTABLE: ${{ secrets.VINTED_CHROME_EXECUTABLE }}
81+
# Optionnel : false = Chromium « fenêtré » sur Xvfb (souvent moins flaggé par Vinted) ; défaut true
82+
VINTED_BROWSER_HEADLESS: ${{ secrets.VINTED_BROWSER_HEADLESS }}
7983
run: |
8084
set -euo pipefail
8185
f=api/.env
@@ -97,7 +101,7 @@ jobs:
97101
echo "VINTED_EMAIL_OR_USERNAME=${VINTED_EMAIL_OR_USERNAME:-}"
98102
echo "VINTED_PASSWORD=${VINTED_PASSWORD:-}"
99103
echo "CORS_ORIGINS=${CORS_ORIGINS:-*}"
100-
echo "VINTED_BROWSER_HEADLESS=true"
104+
echo "VINTED_BROWSER_HEADLESS=${VINTED_BROWSER_HEADLESS:-true}"
101105
echo "VINTED_CHROME_EXECUTABLE=${CHROME_PATH}"
102106
} > "$f"
103107
@@ -140,7 +144,7 @@ jobs:
140144
APP_ROOT="$TARGET/api"
141145
sudo chown -R "$USER:$USER" "$APP_ROOT" || true
142146
sudo apt-get update -y
143-
sudo apt-get install -y python3-venv python3-pip chromium fonts-liberation
147+
sudo apt-get install -y python3-venv python3-pip chromium fonts-liberation xvfb xauth
144148
if [ ! -x "$APP_ROOT/.venv/bin/python" ]; then
145149
python3 -m venv "$APP_ROOT/.venv"
146150
fi
@@ -162,7 +166,8 @@ jobs:
162166
User=${DEPLOY_USER}
163167
WorkingDirectory=${APP_ROOT}
164168
EnvironmentFile=${APP_ROOT}/.env
165-
ExecStart=${APP_ROOT}/.venv/bin/uvicorn main:app --host 127.0.0.1 --port ${PORT} --workers 2 --proxy-headers
169+
# Affichage virtuel : Chromium avec VINTED_BROWSER_HEADLESS=false a besoin d'un DISPLAY (xauth requis pour xvfb-run).
170+
ExecStart=/usr/bin/xvfb-run -a --server-args="-screen 0 1920x1080x24" ${APP_ROOT}/.venv/bin/uvicorn main:app --host 127.0.0.1 --port ${PORT} --workers 2 --proxy-headers
166171
Restart=always
167172
RestartSec=5
168173

api/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
FROM python:3.12-slim-bookworm
22

3+
# Chromium + Xvfb : publication Vinted (nodriver) sans configuration manuelle dans le conteneur.
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
chromium \
6+
xvfb \
7+
xauth \
8+
fonts-liberation \
9+
ca-certificates \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
ENV VINTED_CHROME_EXECUTABLE=/usr/bin/chromium
13+
314
WORKDIR /app
415

516
COPY requirements.txt .

api/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ api/
4343

4444
- Python **3.10+**
4545
- MariaDB or MySQL (local or Docker)
46-
- Optional: `POKE_WALLET_API_KEY`, `GROQ_API_KEY`, Chrome for real Vinted runs
46+
- Optional: `POKE_WALLET_API_KEY`, `GROQ_API_KEY`, **Chromium** for Vinted (voir ci-dessous)
47+
48+
### Vinted (Chromium) et Xvfb
49+
50+
La publication Vinted lance **Chromium** via **nodriver**. Sur une machine **sans écran** (VPS, conteneur, CI), `VINTED_BROWSER_HEADLESS=false` exige un **DISPLAY** : le dépôt prévoit **Xvfb** pour ne rien configurer à la main.
51+
52+
| Environnement | Comportement |
53+
|----------------|---------------|
54+
| **Docker Compose** (`api/`) | L’image installe **chromium**, **xvfb**, **xauth** ; la commande de service enveloppe **uvicorn** avec **`xvfb-run`**. Aucune étape manuelle. |
55+
| **Déploiement GitHub → VPS** (`.github/workflows/deploy-api.yml`) | `apt install` inclut **xvfb** et **xauth** ; l’unité **systemd** lance Uvicorn sous **`xvfb-run`**. |
56+
| **Linux sans Docker** (venv + systemd maison) | Installez `xvfb` et `xauth` (`apt install xvfb xauth`), puis lancez l’API avec : `xvfb-run -a --server-args="-screen 0 1920x1080x24" uvicorn …` si `VINTED_BROWSER_HEADLESS=false`. |
57+
| **Windows (dev)** | Pas besoin d’Xvfb ; utilisez `VINTED_BROWSER_HEADLESS=false` avec un bureau local, ou `run_dev.py` si vous utilisez `--reload` avec Vinted. |
58+
59+
**GitHub Actions (secret optionnel)** : `VINTED_BROWSER_HEADLESS` — si absent ou vide, la valeur générée sur le VPS reste **`true`** (comportement historique). Mettez **`false`** pour un Chromium fenêtré sur Xvfb (souvent moins refusé par Vinted que le headless intégré). **Cloudflare / IP hébergeur** peuvent quand même bloquer des requêtes : un `curl` en **403** depuis le VPS alors qu’un navigateur répond **200** est possible.
60+
61+
Variables utiles dans `.env` / `.env.example` : `VINTED_BROWSER_HEADLESS`, `VINTED_CHROME_EXECUTABLE` (souvent `/usr/bin/chromium` sous Linux).
4762

4863
## Install
4964

@@ -142,12 +157,17 @@ From `api/`:
142157
docker compose up --build
143158
```
144159

145-
- API: port **8000** (migrations run on startup)
160+
- API: port **8000** (migrations + seed conditionnel au démarrage, puis **uvicorn** sous **`xvfb-run`** pour Vinted)
146161
- MariaDB: **3306**
147162
- phpMyAdmin: **8080**
163+
- L’image inclut **Chromium**, **Xvfb** et **xauth** ; les variables `VINTED_*` et **Supabase** peuvent être définies dans un fichier **`.env`** à côté de `docker-compose.yml` (substitution `${…}` — voir [Compose env files](https://docs.docker.com/compose/environment-variables/set-environment-variables/)).
148164

149165
Create a user after startup: `docker compose exec api python seeders/user_seeder.py` (with env vars set), or use `POST /users` and `POST /auth/login`.
150166

167+
### Déploiement API (GitHub → VPS)
168+
169+
Le workflow **Deploy API** installe **xvfb** et **xauth**, écrit l’unité **systemd** avec **`ExecStart=/usr/bin/xvfb-run … uvicorn`**, et peut fixer **`VINTED_BROWSER_HEADLESS`** via le secret du même nom (défaut **`true`** si le secret est absent). Aucune installation manuelle de Xvfb sur le VPS n’est nécessaire après un déploiement via cette CI.
170+
151171
## Limitations
152172

153173
- Vinted UI and anti-bot policies may break automation; local runs that trigger publication need valid Vinted credentials.

api/docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ services:
3939
POKE_WALLET_PROXY_SECRET: ${POKE_WALLET_PROXY_SECRET:-}
4040
POKE_WALLET_USER_AGENT: "${POKE_WALLET_USER_AGENT:-GoupixDex/1.0 (+https://goupixdex.dibodev.fr)}"
4141
GROQ_API_KEY: ${GROQ_API_KEY:-}
42+
SUPABASE_URL: ${SUPABASE_URL:-}
43+
SUPABASE_API_KEY: ${SUPABASE_API_KEY:-}
44+
SUPABASE_STORAGE_BUCKET: ${SUPABASE_STORAGE_BUCKET:-GoupixDex}
45+
VINTED_EMAIL_OR_USERNAME: ${VINTED_EMAIL_OR_USERNAME:-}
46+
VINTED_PASSWORD: ${VINTED_PASSWORD:-}
47+
VINTED_BROWSER_HEADLESS: ${VINTED_BROWSER_HEADLESS:-false}
48+
VINTED_CHROME_EXECUTABLE: ${VINTED_CHROME_EXECUTABLE:-/usr/bin/chromium}
4249
volumes:
4350
- .:/app
4451
depends_on:
@@ -47,6 +54,7 @@ services:
4754
command: >
4855
sh -c "python migrations/run_migrations.py &&
4956
python seeders/conditional_seed.py &&
57+
xvfb-run -a --server-args='-screen 0 1920x1080x24'
5058
uvicorn main:app --host 0.0.0.0 --port 8000 --reload"
5159
5260
phpmyadmin:

todo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
ajouter un input si l'ocr détecte mauvaise carte pour aider un peu pokewallter à remplir le formulaire create articles avec les infos de la bonne carte
44

5-
app.goupixdex
65

7-
goupixdex à la racine landing qui présente le saas goupix dex avec cta pour faire sa demande d'accès avec un email
6+
7+
Une fois connecté (navigateur visible, ou connexion manuelle une fois), réutiliser le même profil Chrome (répertoire utilisateur) avec cookies / session sauvegardés, et n’utiliser le headless que pour des actions déjà authentifiées — si Vinted ne challenge plus la session. C’est l’approche la plus courante pour les automations « semi-légitimes » côté outil interne.

0 commit comments

Comments
 (0)