#!/bin/sh set -eu APP_DIR="$1" PORT="$2" DB_PATH="${DJANGO_DB_PATH:-$APP_DIR/db/db.sqlite3}" DUMP_SRC="$APP_DIR/dumps/example.json" cd "$APP_DIR" mkdir -p logs static "$(dirname "$DB_PATH")" python manage.py migrate should_load_fixture=0 if [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ] && [ -f "$DUMP_SRC" ]; then if [ ! -s "$DB_PATH" ]; then should_load_fixture=1 else entity_conf_count="$(python manage.py shell -c ' from django.db import connection table = "spid_cie_oidc_entity_federationentityconfiguration" with connection.cursor() as cursor: tables = connection.introspection.table_names(cursor) if table not in tables: print(0) else: cursor.execute(f"SELECT COUNT(*) FROM {table}") print(cursor.fetchone()[0]) ')" if [ "${entity_conf_count:-0}" = "0" ]; then should_load_fixture=1 fi fi fi if [ "$should_load_fixture" = "1" ]; then TMP_DUMP="$(mktemp /tmp/visione-fixture.XXXXXX.json)" python /app/scripts/rewrite_dumps.py "$DUMP_SRC" "$TMP_DUMP" python manage.py loaddata --format=json "$TMP_DUMP" rm -f "$TMP_DUMP" fi python manage.py collectstatic --noinput if grep -aEq '127\.0\.0\.1|provider:8002' "$DB_PATH" \ && [ -n "${DJANGO_ALLOWED_HOSTS:-}" ] \ && [ "${DJANGO_ALLOWED_HOSTS:-*}" != "*" ]; then echo "Refusing to start: bootstrap data still contains internal/local URLs" >&2 exit 1 fi exec python manage.py runserver 0.0.0.0:"$PORT"