diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..572bb7b --- /dev/null +++ b/deploy.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Deployment-Script für 1Panel/Python-Runtime. +# Im Container/auf dem Server im Projektverzeichnis ausführen: +# ./deploy.sh +# +# Optional: +# DEPLOY_REMOTE=origin DEPLOY_BRANCH=main ./deploy.sh +# SKIP_PIP=1 ./deploy.sh +# SKIP_COLLECTSTATIC=1 ./deploy.sh +# DEPLOY_RESTART_CMD="..." ./deploy.sh + +cd "$(dirname "$0")" + +REMOTE="${DEPLOY_REMOTE:-origin}" +BRANCH="${DEPLOY_BRANCH:-$(git branch --show-current 2>/dev/null || echo main)}" + +if [[ -x ".venv/bin/python" ]]; then + PY=".venv/bin/python" +elif command -v python3 >/dev/null 2>&1; then + PY="python3" +elif command -v python >/dev/null 2>&1; then + PY="python" +else + echo "Fehler: python/python3 wurde nicht gefunden." >&2 + exit 1 +fi + +echo "==> Deploy $(pwd)" +echo "==> Python: $($PY --version)" +echo "==> Git Pull: ${REMOTE}/${BRANCH}" +git fetch "$REMOTE" "$BRANCH" +git pull --ff-only "$REMOTE" "$BRANCH" + +if [[ "${SKIP_PIP:-0}" != "1" ]]; then + echo "==> Dependencies installieren/aktualisieren" + "$PY" -m pip install -r requirements.txt +fi + +echo "==> Django Checks" +"$PY" manage.py check + +echo "==> Datenbank-Migrationen" +"$PY" manage.py migrate --noinput + +if [[ "${SKIP_COLLECTSTATIC:-0}" != "1" ]]; then + echo "==> Static Files sammeln" + "$PY" manage.py collectstatic --noinput +fi + +if [[ -n "${DEPLOY_RESTART_CMD:-}" ]]; then + echo "==> Runtime neu starten" + bash -lc "$DEPLOY_RESTART_CMD" +else + echo "==> Fertig. Bitte die Python Runtime in 1Panel neu starten, falls sie nicht automatisch reloadet." +fi