diff --git a/start.sh b/start.sh index f575418..3f5ce38 100644 --- a/start.sh +++ b/start.sh @@ -1,29 +1,88 @@ -#!/usr/bin/env bash -set -euo pipefail + +#!/bin/bash +set -e + +cd /home/container + +echo "======================================" +echo "GooDrive" +echo "======================================" + +# -------------------------------------- +# Mise à jour du projet +# -------------------------------------- + +if [ ! -d ".git" ]; then + echo "Dépôt Git absent → clonage..." + + git clone https://gitea.louismazin.ovh/LouisMazin/GooDrive.git /tmp/goodrive + + cp -a /tmp/goodrive/. /home/container/ + rm -rf /tmp/goodrive +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 -# Lors du premier démarrage, laisser à la base le temps de devenir disponible. -tries=0 -until python manage.py migrate --noinput; do - tries=$((tries+1)) - if ((tries >= 30)); then - echo "Impossible d'appliquer les migrations après 30 tentatives." >&2 - exit 1 - fi - sleep 2 -done + +python3 manage.py check + +echo "Démarrage Django sur :1035" + +python3 manage.py migrate --noinput + python manage.py ensure_admin -python manage.py runserver 0.0.0.0:1029 & -backend_pid=$! +python3 manage.py runserver 0.0.0.0:1035 & +BACKEND_PID=$! + +# -------------------------------------- +# Frontend +# -------------------------------------- + cd /home/container/frontend -export VITE_API_PROXY_TARGET="${VITE_API_PROXY_TARGET:-http://127.0.0.1:1029}" -npm run dev -- --host 0.0.0.0 --port 1028 & -frontend_pid=$! + +echo "Installation des dépendances frontend..." +npm ci + + +echo "Build React..." + +npm run build + +echo "Démarrage frontend sur :1034" + +npm run preview -- --host 0.0.0.0 --port 1034 & +FRONTEND_PID=$! + +# -------------------------------------- +# Arrêt propre +# -------------------------------------- cleanup() { - kill "$backend_pid" "$frontend_pid" 2>/dev/null || true - wait "$backend_pid" "$frontend_pid" 2>/dev/null || true + 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 EXIT SIGINT SIGTERM -wait -n "$backend_pid" "$frontend_pid" + +trap cleanup SIGTERM SIGINT EXIT + +echo "======================================" +echo " Frontend : :1034" +echo " Backend : :1035" +echo "======================================" + +wait -n "$BACKEND_PID" "$FRONTEND_PID" \ No newline at end of file