- deploy.sh copies static/ to /var/www/html/solventum-image-metadata/ - Apache Alias serves CSS/JS directly from disk - ProxyPass exclusion prevents static requests going to Docker - Updated apache config with full working example Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
92 lines
2.6 KiB
Bash
Executable file
92 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Solventum Image Metadata — Idempotent Deployment Script
|
|
# Usage: ./deploy.sh
|
|
#
|
|
# First run:
|
|
# cd /opt/oliver-metadata-tool
|
|
# cp .env.example .env # edit with your secrets
|
|
# chmod +x deploy.sh
|
|
# ./deploy.sh
|
|
#
|
|
# Subsequent updates:
|
|
# cd /opt/oliver-metadata-tool && ./deploy.sh
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
COMPOSE_PROJECT="solventum-image-metadata"
|
|
|
|
# Use sudo for docker if current user can't access docker socket
|
|
DOCKER_CMD="docker"
|
|
if ! docker info > /dev/null 2>&1; then
|
|
DOCKER_CMD="sudo docker"
|
|
fi
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
echo "=== Solventum Image Metadata — Deploy ==="
|
|
echo "Directory: $SCRIPT_DIR"
|
|
echo ""
|
|
|
|
# 1. Pull latest code from Bitbucket (runs as current user — needs SSH key)
|
|
echo ">>> Pulling latest code..."
|
|
git pull
|
|
|
|
# 2. Check .env exists (first-run guard)
|
|
if [ ! -f .env ]; then
|
|
echo ""
|
|
echo "ERROR: .env file not found!"
|
|
echo ""
|
|
echo " cp .env.example .env"
|
|
echo " Then edit .env with your secrets (AZURE_CLIENT_SECRET, SECRET_KEY, etc.)"
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
# 3. Build Docker image (uses layer cache, picks up code changes via COPY . .)
|
|
echo ">>> Building Docker image..."
|
|
$DOCKER_CMD compose -p "$COMPOSE_PROJECT" build
|
|
|
|
# 4. Start or restart containers (idempotent — creates if missing, restarts if running)
|
|
echo ">>> Starting containers..."
|
|
$DOCKER_CMD compose -p "$COMPOSE_PROJECT" up -d
|
|
|
|
# 5. Wait for health check
|
|
# Database auto-initializes on first container startup:
|
|
# - Tables created via CREATE TABLE IF NOT EXISTS
|
|
# - Migrations run in-code (check-before-act pattern)
|
|
# - Superadmin created if SUPERADMIN_EMAIL is set
|
|
echo ">>> Waiting for app to be healthy..."
|
|
HEALTHY=false
|
|
for i in $(seq 1 20); do
|
|
if curl -sf http://127.0.0.1:5001/login > /dev/null 2>&1; then
|
|
echo ">>> App is healthy!"
|
|
HEALTHY=true
|
|
break
|
|
fi
|
|
echo " Waiting... ($i/20)"
|
|
sleep 3
|
|
done
|
|
|
|
if [ "$HEALTHY" = false ]; then
|
|
echo ""
|
|
echo "WARNING: App may not be healthy after 60 seconds."
|
|
echo "Check logs:"
|
|
echo " $DOCKER_CMD compose -p $COMPOSE_PROJECT logs --tail 50"
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
# 6. Deploy static files for Apache to serve directly
|
|
WEB_DIR="/var/www/html/solventum-image-metadata"
|
|
echo ">>> Deploying static files to $WEB_DIR..."
|
|
sudo rm -rf "$WEB_DIR/static"
|
|
sudo mkdir -p "$WEB_DIR"
|
|
sudo cp -r "$SCRIPT_DIR/static" "$WEB_DIR/static"
|
|
sudo chown -R www-data:www-data "$WEB_DIR"
|
|
|
|
echo ""
|
|
echo "=== Deploy complete ==="
|
|
echo "URL: https://ai-sandbox.oliver.solutions/solventum-image-metadata/"
|
|
echo ""
|
|
$DOCKER_CMD compose -p "$COMPOSE_PROJECT" ps
|