#!/bin/sh set -e # /tmp/devpkgs is a writable site-packages directory for dev bind-mount installs. # It's added to PYTHONPATH so packages installed here are importable. DEVPKGS=/tmp/devpkgs mkdir -p "$DEVPKGS" export PYTHONPATH="$DEVPKGS${PYTHONPATH:+:$PYTHONPATH}" # Install the muse package if the dev volume mount is present. # Copy to /tmp first so setuptools can write egg-info without hitting the # read-only bind-mount. if [ -f /muse/pyproject.toml ]; then echo "Muse volume detected — installing muse..." mkdir -p /tmp/muse-install tar -C /muse --exclude='./.muse' -cf - . | tar -xf - -C /tmp/muse-install pip install /tmp/muse-install --target "$DEVPKGS" --no-deps --quiet 2>/dev/null || true rm -rf /tmp/muse-install fi # Install the muse_contracts package if the dev volume mount is present. # Provides shared cross-repo type contracts (IssueRecord, ProposalRecord, etc.). # Copy to /tmp first so setuptools can write egg-info without hitting the # read-only bind-mount. if [ -f /src/contracts/pyproject.toml ]; then echo "Contracts volume detected — installing muse_contracts..." cp -r /src/contracts /tmp/muse-contracts-install pip install /tmp/muse-contracts-install --target "$DEVPKGS" --no-deps --quiet 2>/dev/null || true rm -rf /tmp/muse-contracts-install fi # If a command was passed (e.g., "alembic upgrade head" from the deploy script), # run it directly without starting the server. if [ $# -gt 0 ]; then exec "$@" fi # Blue-green deploys run migrations as a one-off before starting the new slot, # so the new container starts clean without re-running them. # Set SKIP_MIGRATIONS=1 in the new container to skip this step. if [ "${SKIP_MIGRATIONS:-0}" = "1" ]; then echo "SKIP_MIGRATIONS=1 — skipping alembic (already run by deploy script)" else echo "Running database migrations..." alembic upgrade head fi echo "Starting MuseHub..." if [ -f /tls/localhost.crt ] && [ -f /tls/localhost.key ]; then echo "TLS cert found — starting uvicorn with HTTPS" exec uvicorn musehub.main:app \ --host 0.0.0.0 \ --port 1337 \ --proxy-headers \ --ssl-certfile /tls/localhost.crt \ --ssl-keyfile /tls/localhost.key \ --workers "${UVICORN_WORKERS:-4}" else echo "No TLS cert — starting uvicorn with HTTP/1.1 cleartext" exec uvicorn musehub.main:app \ --host 0.0.0.0 \ --port 1337 \ --proxy-headers \ --workers "${UVICORN_WORKERS:-4}" fi