#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT"

ENV_FILE="${1:-infra/docker/.env.production}"

if [[ ! -f "$ENV_FILE" ]]; then
  echo "Missing $ENV_FILE — copy infra/docker/.env.production.example first."
  exit 1
fi

if [[ ! -f apps/api/data/secrets/install.env ]]; then
  python3 apps/api/scripts/bootstrap_install.py
fi

docker compose \
  -f infra/docker/docker-compose.prod.yml \
  --env-file "$ENV_FILE" \
  up -d --build

echo "Production deploy complete."
