This commit is contained in:
2026-10-03 20:24:37 +02:00
parent d603d8d574
commit 7094d05030
8 changed files with 581 additions and 135 deletions
+9 -9
View File
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
# Uruchomienie produkcyjne (gunicorn) ze stabilnym SECRET_KEY.
# Production startup (gunicorn) with a stable SECRET_KEY.
#
# Kolejność źródeł klucza:
# 1. zmienna środowiskowa SECRET_KEY (ma pierwszeństwo),
# 2. plik .secret_key obok skryptu (tworzony raz przy pierwszym starcie),
# 3. w przeciwnym razie generowany jest losowy klucz i zapisywany do .secret_key.
# Key resolution order:
# 1. SECRET_KEY environment variable (takes precedence),
# 2. .secret_key file next to this script (created once on first start),
# 3. otherwise a random key is generated and saved to .secret_key.
#
# Stabilny klucz ma znaczenie: podpisuje ciasteczka sesji, więc jego zmiana
# przy każdym restarcie wylogowałaby wszystkich użytkowników.
# A stable key matters: it signs the session cookies, so changing it
# on every restart would log out all users.
set -euo pipefail
cd "$(dirname "$0")"
@@ -20,12 +20,12 @@ if [ -z "${SECRET_KEY:-}" ]; then
SECRET_KEY="$(python3 -c 'import secrets; print(secrets.token_hex(32))')"
printf '%s' "$SECRET_KEY" > "$SECRET_FILE"
chmod 600 "$SECRET_FILE"
echo "Wygenerowano nowy SECRET_KEY, zapisano w $SECRET_FILE" >&2
echo "Generated a new SECRET_KEY, saved to $SECRET_FILE" >&2
fi
export SECRET_KEY
fi
# Migracje przed startem, żeby schemat był zgodny z kodem.
# Migrate before starting, so the schema matches the code.
if [ -x ".venv/bin/alembic" ]; then
.venv/bin/alembic upgrade head
elif command -v alembic >/dev/null 2>&1; then