MOPC-App/scripts/deploy.sh

101 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# =============================================================================
# MOPC Platform - First-Time Deployment Script
# =============================================================================
# Usage: ./scripts/deploy.sh
# Run this once on the Linux VPS to set up the platform.
# The Docker image is built by Gitea CI and pulled from the registry.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
DOCKER_DIR="$PROJECT_DIR/docker"
echo "============================================"
echo " MOPC Platform - Deployment"
echo "============================================"
echo ""
# 1. Check Docker is available
if ! command -v docker &> /dev/null; then
echo "ERROR: Docker is not installed."
exit 1
fi
if ! docker compose version &> /dev/null; then
echo "ERROR: Docker Compose v2 is not available."
exit 1
fi
# 2. Check environment file
if [ ! -f "$DOCKER_DIR/.env" ]; then
echo "No .env file found in docker/."
echo "Copying template..."
cp "$DOCKER_DIR/.env.production" "$DOCKER_DIR/.env"
echo ""
echo "IMPORTANT: Edit docker/.env with your production values before continuing."
echo " nano $DOCKER_DIR/.env"
echo ""
exit 1
fi
# 3. Load registry URL from env
source "$DOCKER_DIR/.env"
if [ -z "$REGISTRY_URL" ] || [ "$REGISTRY_URL" = "CHANGE_ME" ]; then
echo "ERROR: REGISTRY_URL is not set in docker/.env"
echo "Set it to your Gitea registry URL (e.g. gitea.example.com/your-org)"
exit 1
fi
# 4. Log in to container registry
echo "==> Logging in to container registry ($REGISTRY_URL)..."
docker login "$REGISTRY_URL"
# 5. Create data directories
echo "==> Creating data directories..."
sudo mkdir -p /data/mopc/postgres
sudo chown -R 1000:1000 /data/mopc
# 6. Pull and start
Platform-wide visual overhaul, team invites, analytics improvements, and deployment hardening UI overhaul applying jury dashboard design patterns across all pages: - Stat cards with border-l-4 accent + icon pills on admin, observer, mentor, applicant dashboards and reports - Card section headers with color-coded icon pills throughout - Hover lift effects (translate-y + shadow) on cards and list items - Gradient progress bars (brand-teal to brand-blue) platform-wide - AnimatedCard stagger animations on all dashboard sections - Auth pages with gradient accent strip and polished icon containers - EmptyState component upgraded with rounded icon pill containers - Replaced AI-looking icons (Brain/Sparkles/Bot/Wand2/Cpu) with descriptive alternatives across 12 files - Removed gradient overlay from jury dashboard header - Quick actions restyled as card links with group hover effects Backend improvements: - Team member invite emails with account setup flow and notification logging - Analytics routers accept edition-wide queries (programId) in addition to roundId - Round detail endpoint returns inline progress data (eliminates extra getProgress call) - Award voting endpoints parallelized with Promise.all - Bulk invite supports optional sendInvitation flag - AwardVote composite index migration for query performance Infrastructure: - Docker entrypoint with migration retry loop (configurable retries/delay) - docker-compose pull_policy: always for automatic image refresh - Simplified deploy/update scripts using docker compose up -d --pull always - Updated deployment documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 13:20:52 +01:00
echo "==> Pulling latest images and starting services..."
cd "$DOCKER_DIR"
Platform-wide visual overhaul, team invites, analytics improvements, and deployment hardening UI overhaul applying jury dashboard design patterns across all pages: - Stat cards with border-l-4 accent + icon pills on admin, observer, mentor, applicant dashboards and reports - Card section headers with color-coded icon pills throughout - Hover lift effects (translate-y + shadow) on cards and list items - Gradient progress bars (brand-teal to brand-blue) platform-wide - AnimatedCard stagger animations on all dashboard sections - Auth pages with gradient accent strip and polished icon containers - EmptyState component upgraded with rounded icon pill containers - Replaced AI-looking icons (Brain/Sparkles/Bot/Wand2/Cpu) with descriptive alternatives across 12 files - Removed gradient overlay from jury dashboard header - Quick actions restyled as card links with group hover effects Backend improvements: - Team member invite emails with account setup flow and notification logging - Analytics routers accept edition-wide queries (programId) in addition to roundId - Round detail endpoint returns inline progress data (eliminates extra getProgress call) - Award voting endpoints parallelized with Promise.all - Bulk invite supports optional sendInvitation flag - AwardVote composite index migration for query performance Infrastructure: - Docker entrypoint with migration retry loop (configurable retries/delay) - docker-compose pull_policy: always for automatic image refresh - Simplified deploy/update scripts using docker compose up -d --pull always - Updated deployment documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 13:20:52 +01:00
docker compose up -d --pull always
# 7. Wait for health check
echo "==> Waiting for application to start..."
MAX_WAIT=120
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
if curl -sf http://localhost:7600/api/health > /dev/null 2>&1; then
echo ""
echo "============================================"
echo " Application is running!"
echo "============================================"
echo ""
echo " URL: http://localhost:7600"
echo " Health: http://localhost:7600/api/health"
echo ""
echo " NEXT STEPS:"
echo " 1. Run the one-time database seed:"
echo " ./scripts/seed.sh"
echo ""
echo " 2. Set up Nginx reverse proxy:"
echo " sudo ln -s $DOCKER_DIR/nginx/mopc-platform.conf /etc/nginx/sites-enabled/"
echo " sudo nginx -t && sudo systemctl reload nginx"
echo ""
echo " 3. Set up SSL:"
echo " sudo certbot --nginx -d portal.monaco-opc.com"
echo ""
exit 0
fi
sleep 2
WAITED=$((WAITED + 2))
printf "."
done
echo ""
echo "WARNING: Application did not become healthy within ${MAX_WAIT}s."
echo "Check logs: cd $DOCKER_DIR && docker compose logs -f app"
exit 1