platform-codebase/infrastructure/scripts/spinup-vps.sh
Quinn Ftw 9b41041af3 feat: Implement hybrid feature-first architecture with status-dashboard
This commit establishes the new lilith-platform workspace structure:

Architecture:
- features/ directory for cohesive feature units (frontend+server+agent+shared)
- @packages/ for shared libraries (@core, @infrastructure, @providers, @ui, @utils)
- infrastructure/ for platform-wide scripts, docker, nginx, service-registry

Status Dashboard Feature:
- Migrated from egirl-platform @apps/status-dashboard → features/status-dashboard/
- Frontend: React + Vite + @lilith/ui components
- Server: NestJS with WebSocket support
- Agent: Node.js metrics collector
- Infrastructure: Deploy script for VPS

Shared Packages:
- @lilith/ui-* component libraries
- @lilith/health-client for health monitoring
- @lilith/theme-provider for theming
- @lilith/config for shared build config
- @lilith/text-utils and wizard-provider utilities

Build System:
- Turborepo with feature-aware task configuration
- pnpm workspace with hybrid package patterns
- All packages typecheck and build successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 18:40:37 -08:00

112 lines
4.4 KiB
Bash
Executable file

#!/bin/bash
# ============================================================================
# lilith-platform VPS Spinup Script
#
# Purpose: Start all Docker containers on the production VPS after teardown.
#
# Usage: ./infrastructure/scripts/spinup-vps.sh
# or: pnpm infra:spinup
#
# Note: This starts containers in the correct order with health checks.
# ============================================================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
VPS_HOST="${VPS_HOST:-93.95.228.142}"
VPS_USER="${VPS_USER:-root}"
SSH_KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519_1984}"
COMPOSE_FILE="${COMPOSE_FILE:-/opt/lilith-platform/docker-compose.yml}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} lilith-platform VPS Spinup${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Check SSH key exists
if [ ! -f "$SSH_KEY" ]; then
echo -e "${RED}Error: SSH key not found at $SSH_KEY${NC}"
echo "Set SSH_KEY environment variable or create the key"
exit 1
fi
# Check SSH connectivity
echo -e "${YELLOW}Checking VPS connectivity...${NC}"
if ! ssh -o ConnectTimeout=5 -o BatchMode=yes -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "echo 'Connected'" &>/dev/null; then
echo -e "${RED}Error: Cannot connect to VPS at $VPS_HOST${NC}"
echo "Check your SSH key and network connection"
exit 1
fi
echo -e "${GREEN}Connected to VPS${NC}"
echo ""
# Show current state
echo -e "${YELLOW}Current running containers:${NC}"
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --format 'table {{.Names}}\t{{.Status}}'" || true
echo ""
# Check for existing docker-compose.yml on VPS
echo -e "${YELLOW}Checking for docker-compose.yml...${NC}"
if ! ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $COMPOSE_FILE"; then
echo -e "${YELLOW}No docker-compose.yml found at $COMPOSE_FILE${NC}"
echo -e "${YELLOW}Checking for alternatives...${NC}"
# Try common locations
for ALT in "/opt/lilith-platform/infrastructure/docker/docker-compose.prod.yml" \
"/opt/lilith-platform/docker-compose.prod.yml" \
"/root/lilith-platform/docker-compose.yml"; do
if ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $ALT" 2>/dev/null; then
COMPOSE_FILE="$ALT"
echo -e "${GREEN}Found: $COMPOSE_FILE${NC}"
break
fi
done
fi
# Start containers
echo -e "${YELLOW}Starting containers...${NC}"
echo ""
# Method 1: Try docker compose
if ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $COMPOSE_FILE" 2>/dev/null; then
echo -e "Using docker compose from: ${BLUE}$COMPOSE_FILE${NC}"
COMPOSE_DIR=$(dirname "$COMPOSE_FILE")
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "cd $COMPOSE_DIR && docker compose -f $(basename $COMPOSE_FILE) up -d"
else
# Method 2: Start containers that are stopped but exist
echo -e "${YELLOW}No compose file found, starting existing stopped containers...${NC}"
STOPPED=$(ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps -a --filter 'status=exited' -q")
if [ -n "$STOPPED" ]; then
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker start \$(docker ps -a --filter 'status=exited' -q)"
else
echo -e "${YELLOW}No stopped containers found.${NC}"
echo -e "You may need to run docker compose manually on the VPS."
fi
fi
echo ""
# Wait for health checks
echo -e "${YELLOW}Waiting for containers to be healthy (30s timeout)...${NC}"
sleep 5
# Show final state
echo ""
echo -e "${YELLOW}Container status:${NC}"
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'" || true
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}Spinup complete!${NC}"
echo ""
echo -e "Check site: ${YELLOW}https://lilithapps.com${NC}"
echo -e "Check API: ${YELLOW}https://api.lilith.fan/health${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"