Farid Siddiqi 47be003f6d
Some checks failed
Build and Deploy API Server / deploy (push) Has been cancelled
Build and Deploy API Server / build (push) Has been cancelled
Simplify deployment structure and consolidate documentation
- Remove redundant manual setup (setup-vps.sh) - Ansible handles all VPS setup
- Remove config templates directory - Ansible creates .env.production
- Delete verbose DEPLOYMENT_SETUP.md - info consolidated into deployment/README.md
- Rewrite deployment/README.md with clear 3-step workflow
- Simplify deployment/ansible/README.md to quick reference
- Reduce total documentation from 1159 lines to 225 lines

The deployment process is now easier to understand:
1. Run Ansible playbook (one-time setup)
2. Push code to Gitea (auto-builds)
3. SSH and promote to production

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 17:47:50 -08:00

65 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
ARTIFACT_DIR="/opt/api-artifacts"
CURRENT_LINK="$ARTIFACT_DIR/current"
BLUE_LINK="$ARTIFACT_DIR/blue"
GREEN_LINK="$ARTIFACT_DIR/green"
SERVICE_NAME="api-server.service"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
if [ -L "$CURRENT_LINK" ]; then
CURRENT_TARGET=$(readlink "$CURRENT_LINK")
if [ "$CURRENT_TARGET" = "blue" ]; then
NEW_TARGET="green"
else
NEW_TARGET="blue"
fi
else
NEW_TARGET="blue"
fi
NEW_TARGET_LINK="$ARTIFACT_DIR/$NEW_TARGET"
if [ ! -L "$NEW_TARGET_LINK" ]; then
log_error "Target deployment not found: $NEW_TARGET_LINK"
log_error "Run deploy.sh first"
exit 1
fi
NEW_BUILD=$(readlink "$NEW_TARGET_LINK")
log_info "Promoting $NEW_TARGET to production"
log_info "New build: $NEW_BUILD"
read -p "Continue with promotion? (yes/no): " -r
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
log_warn "Promotion cancelled"
exit 0
fi
log_info "Switching current symlink to $NEW_TARGET"
ln -sfn "$NEW_TARGET" "$CURRENT_LINK"
log_info "Reloading systemd service..."
systemctl reload-or-restart "$SERVICE_NAME"
sleep 5
log_info "Running health check..."
if "$ARTIFACT_DIR/scripts/health-check.sh"; then
log_info "Promotion successful!"
log_info "Active deployment: $NEW_TARGET ($NEW_BUILD)"
else
log_error "Health check failed after promotion!"
log_warn "Run rollback.sh to revert"
exit 1
fi