#!/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 if [[ -d "locale" ]]; then if ! command -v msgfmt >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1 && [[ "$(id -u)" == "0" ]]; then echo "==> msgfmt/gettext fehlt, installiere gettext" apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gettext else echo "==> msgfmt/gettext fehlt und kann nicht automatisch installiert werden" fi fi if command -v msgfmt >/dev/null 2>&1; then echo "==> Übersetzungen kompilieren" "$PY" manage.py compilemessages else echo "==> Übersetzungen überspringen: msgfmt/gettext ist nicht installiert" fi 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