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

63 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
ARTIFACT_DIR="/opt/api-artifacts"
CURRENT_LINK="$ARTIFACT_DIR/current"
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
log_error "No current deployment found"
exit 1
fi
CURRENT_TARGET=$(readlink "$CURRENT_LINK")
if [ "$CURRENT_TARGET" = "blue" ]; then
PREVIOUS_SLOT="green"
else
PREVIOUS_SLOT="blue"
fi
PREVIOUS_LINK="$ARTIFACT_DIR/$PREVIOUS_SLOT"
if [ ! -L "$PREVIOUS_LINK" ]; then
log_error "No previous deployment found to rollback to"
exit 1
fi
PREVIOUS_BUILD=$(readlink "$PREVIOUS_LINK")
log_warn "ROLLBACK: Reverting from $CURRENT_TARGET to $PREVIOUS_SLOT"
log_info "Previous build: $PREVIOUS_BUILD"
read -p "Continue with rollback? (yes/no): " -r
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
log_warn "Rollback cancelled"
exit 0
fi
log_info "Switching current symlink to $PREVIOUS_SLOT"
ln -sfn "$PREVIOUS_SLOT" "$CURRENT_LINK"
log_info "Reloading systemd service..."
systemctl reload-or-restart "$SERVICE_NAME"
sleep 5
if "$ARTIFACT_DIR/scripts/health-check.sh"; then
log_info "Rollback successful!"
log_info "Active deployment: $PREVIOUS_SLOT ($PREVIOUS_BUILD)"
else
log_error "Health check failed after rollback - manual intervention required"
exit 1
fi