Backend: - routes_auth: POST /v1/auth/dev-login — bypass Azure AD (disabled in production), creates admin in DB and sets JWT cookie; takes email + full_name - routes_auth: use settings.frontend_callback_url instead of parsing CORS origins for SSO post-login redirect — configurable per environment - config: add frontend_callback_url setting - dependencies: fix get_current_admin — was querying _id as string (ObjectId bug) and filtering is_active:True (never set by SSO flow) Frontend: - Login.tsx: dev login form shown in non-production builds below SSO button - api.ts: use import.meta.env.BASE_URL so API paths work under any subpath prefix - main.tsx: pass BASE_URL as BrowserRouter basename for correct SPA routing - vite.config.ts: read VITE_BASE_PATH env var to set Vite base (default /) - nginx.conf: serve app at /cost-tracker/ prefix, proxy API routes internally - Dockerfile: accept VITE_BASE_PATH build arg, copy build to /cost-tracker/ subdir Infra: - docker-compose.yml: API host port 8003 (8001 taken by ppt-tool on optical-dev) - infra/deploy/apache-cost-tracker.conf: Apache include for optical-dev routing - infra/deploy/deploy.sh: one-shot deploy script (clone/pull, build, Apache config) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
3 KiB
Bash
Executable file
80 lines
3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Deploy ai-cost-tracker to optical-dev
|
|
# Usage: ./infra/deploy/deploy.sh
|
|
# Run from your local machine — requires SSH alias "optical-dev" configured
|
|
|
|
set -euo pipefail
|
|
|
|
SERVER="optical-dev"
|
|
REMOTE_DIR="/opt/ai-cost-tracker"
|
|
COMPOSE="docker compose -f infra/docker-compose.yml"
|
|
APACHE_CONF_SRC="$REMOTE_DIR/infra/deploy/apache-cost-tracker.conf"
|
|
APACHE_CONF_DST="/etc/apache2/conf-available/cost-tracker.conf"
|
|
|
|
echo "==> Deploying ai-cost-tracker to $SERVER:$REMOTE_DIR"
|
|
|
|
# ── Clone or pull ──────────────────────────────────────────────────────────────
|
|
ssh "$SERVER" bash <<EOF
|
|
set -e
|
|
if [ ! -d "$REMOTE_DIR/.git" ]; then
|
|
echo " Cloning repo..."
|
|
sudo mkdir -p "$REMOTE_DIR"
|
|
sudo chown \$(whoami) "$REMOTE_DIR"
|
|
git clone git@bitbucket.org:zlalani/ai-cost-tracker.git "$REMOTE_DIR"
|
|
else
|
|
echo " Pulling latest..."
|
|
cd "$REMOTE_DIR" && git pull origin main
|
|
fi
|
|
EOF
|
|
|
|
# ── Check .env ─────────────────────────────────────────────────────────────────
|
|
echo "==> Checking .env..."
|
|
ssh "$SERVER" bash <<'EOF'
|
|
set -e
|
|
if [ ! -f /opt/ai-cost-tracker/.env ]; then
|
|
echo ""
|
|
echo "ERROR: /opt/ai-cost-tracker/.env not found!"
|
|
echo "Copy .env.example and fill in values:"
|
|
echo " cp /opt/ai-cost-tracker/.env.example /opt/ai-cost-tracker/.env"
|
|
echo " nano /opt/ai-cost-tracker/.env"
|
|
exit 1
|
|
fi
|
|
echo " .env found OK"
|
|
EOF
|
|
|
|
# ── Build and start containers ─────────────────────────────────────────────────
|
|
echo "==> Building and starting containers..."
|
|
ssh "$SERVER" bash <<EOF
|
|
set -e
|
|
cd "$REMOTE_DIR"
|
|
$COMPOSE build --no-cache
|
|
$COMPOSE up -d
|
|
echo " Containers:"
|
|
$COMPOSE ps
|
|
EOF
|
|
|
|
# ── Apache config ──────────────────────────────────────────────────────────────
|
|
echo "==> Configuring Apache..."
|
|
ssh "$SERVER" bash <<EOF
|
|
set -e
|
|
if [ ! -f "$APACHE_CONF_DST" ]; then
|
|
echo " Installing Apache include..."
|
|
sudo cp "$APACHE_CONF_SRC" "$APACHE_CONF_DST"
|
|
sudo a2enconf cost-tracker
|
|
sudo apache2ctl graceful
|
|
echo " Apache reloaded"
|
|
else
|
|
echo " Apache conf already present — reloading to pick up any changes"
|
|
sudo cp "$APACHE_CONF_SRC" "$APACHE_CONF_DST"
|
|
sudo apache2ctl graceful
|
|
fi
|
|
EOF
|
|
|
|
echo ""
|
|
echo "Done! App running at: https://optical-dev.oliver.solutions/cost-tracker/"
|
|
echo "API health: https://optical-dev.oliver.solutions/cost-tracker/v1/health"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Create workspace/team/project in admin UI"
|
|
echo " 2. Generate an API key"
|
|
echo " 3. Set COST_TRACKER_* env vars in other projects"
|