diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..e80e580 --- /dev/null +++ b/start.sh @@ -0,0 +1,86 @@ + +#!/bin/bash +set -e + +cd /home/container + +echo "======================================" +echo " Planngin Louis" +echo "======================================" + +# -------------------------------------- +# Mise à jour du projet +# -------------------------------------- + +if [ ! -d ".git" ]; then + echo "Dépôt Git absent → clonage..." + + git clone https://gitea.louismazin.ovh/LouisMazin/Planning.git /tmp/planning + + cp -a /tmp/planning/. /home/container/ + rm -rf /tmp/planning +else + echo "Mise à jour du dépôt Git..." + + git fetch origin + git reset --hard origin/main +fi + +echo "Git : $(git rev-parse --short HEAD)" + +# -------------------------------------- +# Backend +# -------------------------------------- + +cd /home/container/backend + +python3 manage.py check + +echo "Démarrage Django sur :1031" + +python3 manage.py migrate --noinput + +python3 manage.py runserver 0.0.0.0:1031 & +BACKEND_PID=$! + +# -------------------------------------- +# Frontend +# -------------------------------------- + +cd /home/container/frontend + +echo "Installation des dépendances frontend..." +npm ci + + +echo "Build React..." + +npm run build + +echo "Démarrage frontend sur :1025" + +npm run preview -- --host 0.0.0.0 --port 1025 & +FRONTEND_PID=$! + +# -------------------------------------- +# Arrêt propre +# -------------------------------------- + +cleanup() { + echo "Arrêt des applications..." + + kill "$BACKEND_PID" 2>/dev/null || true + kill "$FRONTEND_PID" 2>/dev/null || true + + wait "$BACKEND_PID" 2>/dev/null || true + wait "$FRONTEND_PID" 2>/dev/null || true +} + +trap cleanup SIGTERM SIGINT EXIT + +echo "======================================" +echo " Frontend : :1025" +echo " Backend : :1031" +echo "======================================" + +wait -n "$BACKEND_PID" "$FRONTEND_PID" \ No newline at end of file