From 72843036923bb94dcd7ea1ebd3ac11c6b9193ee0 Mon Sep 17 00:00:00 2001 From: scayac Date: Wed, 25 Mar 2026 14:50:55 +0100 Subject: [PATCH] Ajout conf pour serveur production --- frontend/README_FRONTEND.md | 27 ++++++++++++++++++++ frontend/requirements.txt | 1 + frontend/systemd/pysonnerie-frontend.service | 17 ++++++++++++ frontend/wsgi.py | 4 +++ 4 files changed, 49 insertions(+) create mode 100644 frontend/systemd/pysonnerie-frontend.service create mode 100644 frontend/wsgi.py diff --git a/frontend/README_FRONTEND.md b/frontend/README_FRONTEND.md index 1186fed..44e1163 100644 --- a/frontend/README_FRONTEND.md +++ b/frontend/README_FRONTEND.md @@ -30,6 +30,33 @@ python run.py Application dispo sur `http://127.0.0.1:5000`. +## Production (Debian + systemd) + +Le frontend peut tourner en production avec Gunicorn et un service systemd. + +```bash +cd /opt/pySonnerie/frontend +python3 -m venv .venv +source .venv/bin/activate +pip install -r requirements.txt +``` + +Copier le service fourni: + +```bash +sudo cp systemd/pysonnerie-frontend.service /etc/systemd/system/ +``` + +Adapter au besoin les variables dans le fichier de service (`FRONTEND_SECRET_KEY`, `FRONTEND_BIND`) puis activer: + +```bash +sudo systemctl daemon-reload +sudo systemctl enable --now pysonnerie-frontend.service +sudo systemctl status pysonnerie-frontend.service +``` + +Le frontend sera alors servi par Gunicorn sur l'adresse definie par `FRONTEND_BIND` (par defaut `0.0.0.0:5000`). + ## Notes - Le frontend appelle le backend en HTTPS avec certificat autosigne (`verify=False`). diff --git a/frontend/requirements.txt b/frontend/requirements.txt index 76d9083..6171215 100644 --- a/frontend/requirements.txt +++ b/frontend/requirements.txt @@ -1,2 +1,3 @@ Flask==3.0.3 requests==2.32.3 +gunicorn==23.0.0 diff --git a/frontend/systemd/pysonnerie-frontend.service b/frontend/systemd/pysonnerie-frontend.service new file mode 100644 index 0000000..148014c --- /dev/null +++ b/frontend/systemd/pysonnerie-frontend.service @@ -0,0 +1,17 @@ +[Unit] +Description=pySonnerie Frontend Web UI +After=network.target + +[Service] +Type=simple +User=www-data +Group=www-data +WorkingDirectory=/opt/pySonnerie/frontend +Environment=FRONTEND_SECRET_KEY=change-me +Environment=FRONTEND_BIND=0.0.0.0:5000 +ExecStart=/opt/pySonnerie/frontend/.venv/bin/gunicorn --workers 2 --bind ${FRONTEND_BIND} wsgi:app +Restart=on-failure +RestartSec=3 + +[Install] +WantedBy=multi-user.target diff --git a/frontend/wsgi.py b/frontend/wsgi.py new file mode 100644 index 0000000..4d256fe --- /dev/null +++ b/frontend/wsgi.py @@ -0,0 +1,4 @@ +from app import create_app + + +app = create_app()