Add entrypoint.sh: wait for MariaDB before starting Flask
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+5
-1
@@ -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
|
# Store DB config in a docker-friendly location (/config), override via DB_CONFIG_PATH env if needed
|
||||||
COPY backend/config /config
|
COPY backend/config /config
|
||||||
COPY backend/requirements.txt ./requirements.txt
|
COPY backend/requirements.txt ./requirements.txt
|
||||||
|
COPY backend/entrypoint.sh ./entrypoint.sh
|
||||||
|
|
||||||
# Frontend aus Build-Stage übernehmen
|
# Frontend aus Build-Stage übernehmen
|
||||||
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
|
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
|
# Python-Abhängigkeiten installieren
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Entrypoint ausführbar machen
|
||||||
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
# Flask starten
|
# Flask starten
|
||||||
WORKDIR /app/backend
|
WORKDIR /app/backend
|
||||||
ENV PYTHONPATH=/app/backend
|
ENV PYTHONPATH=/app/backend
|
||||||
ENV DB_CONFIG_PATH=/config/db_config.json
|
ENV DB_CONFIG_PATH=/config/db_config.json
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
CMD ["python", "app.py"]
|
ENTRYPOINT ["/app/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
|
||||||
Reference in New Issue
Block a user