diff --git a/Dockerfile b/Dockerfile index b06467d..3f7f7cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ COPY backend/templates ./backend/templates # Store DB config in a docker-friendly location (/config), override via DB_CONFIG_PATH env if needed COPY backend/config /config COPY backend/requirements.txt ./requirements.txt +COPY backend/entrypoint.sh ./entrypoint.sh # Frontend aus Build-Stage übernehmen COPY --from=frontend-build /app/frontend/dist ./frontend/dist @@ -26,9 +27,12 @@ COPY --from=frontend-build /app/frontend/dist ./frontend/dist # Python-Abhängigkeiten installieren RUN pip install --no-cache-dir -r requirements.txt +# Entrypoint ausführbar machen +RUN chmod +x /app/entrypoint.sh + # Flask starten WORKDIR /app/backend ENV PYTHONPATH=/app/backend ENV DB_CONFIG_PATH=/config/db_config.json EXPOSE 5000 -CMD ["python", "app.py"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh new file mode 100644 index 0000000..10dfcf4 --- /dev/null +++ b/backend/entrypoint.sh @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +RETRY_INTERVAL=3 + +# If no db_config.json exists yet, skip the wait (first-run setup mode). +python - <<'EOF' +import sys, os +config_path = os.environ.get("DB_CONFIG_PATH", "/config/db_config.json") +if not os.path.exists(config_path): + sys.exit(1) +EOF +DB_CONFIGURED=$? + +if [ "$DB_CONFIGURED" -eq 1 ]; then + echo "[entrypoint] Keine DB-Konfiguration gefunden – starte im Setup-Modus." +else + echo "[entrypoint] DB-Konfiguration gefunden – warte auf MariaDB..." + while true; do + python - <<'EOF' +import sys +from util.db_config import load_config, test_connection +config = load_config() +sys.exit(0 if config and test_connection(config) else 1) +EOF + if [ $? -eq 0 ]; then + echo "[entrypoint] MariaDB erreichbar – starte Flask." + break + fi + echo "[entrypoint] MariaDB noch nicht bereit – neuer Versuch in ${RETRY_INTERVAL}s..." + sleep "$RETRY_INTERVAL" + done +fi + +exec python app.py