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

75 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
ARTIFACT_DIR="/opt/api-artifacts"
BUILDS_DIR="$ARTIFACT_DIR/builds"
SCRIPTS_DIR="$ARTIFACT_DIR/scripts"
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 [ $# -ne 1 ]; then
log_error "Usage: $0 <commit-hash>"
exit 1
fi
COMMIT_HASH="$1"
BUILD_PATH="$BUILDS_DIR/$COMMIT_HASH"
if [ ! -d "$BUILD_PATH" ]; then
log_error "Build not found: $BUILD_PATH"
exit 1
fi
if [ ! -f "$BUILD_PATH/api-server" ]; then
log_error "Binary not found in build: $BUILD_PATH/api-server"
exit 1
fi
log_info "Starting deployment for commit: $COMMIT_HASH"
CURRENT_LINK="$ARTIFACT_DIR/current"
BLUE_LINK="$ARTIFACT_DIR/blue"
GREEN_LINK="$ARTIFACT_DIR/green"
if [ -L "$CURRENT_LINK" ]; then
CURRENT_TARGET=$(readlink "$CURRENT_LINK")
if [ "$CURRENT_TARGET" = "blue" ]; then
TARGET_SLOT="green"
INACTIVE_LINK="$GREEN_LINK"
else
TARGET_SLOT="blue"
INACTIVE_LINK="$BLUE_LINK"
fi
else
TARGET_SLOT="blue"
INACTIVE_LINK="$BLUE_LINK"
fi
log_info "Deploying to slot: $TARGET_SLOT"
ln -sfn "$BUILD_PATH" "$INACTIVE_LINK"
log_info "Symlink updated: $INACTIVE_LINK -> $BUILD_PATH"
log_info "Running database migrations..."
if ! "$SCRIPTS_DIR/migrate.sh" "$TARGET_SLOT"; then
log_error "Migration failed, aborting deployment"
exit 1
fi
log_info "Deployment staged to $TARGET_SLOT slot"
log_info "Build ready at: $BUILD_PATH"
log_info ""
log_info "To promote this deployment to production, run:"
log_info " sudo $SCRIPTS_DIR/promote.sh"
log_info ""
log_info "To test before promoting:"
log_info " Check $INACTIVE_LINK for manual verification"