219 lines
6.4 KiB
Bash
Executable File
219 lines
6.4 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Deployment Configuration
|
|
# Centralized configuration for The Order deployment automation
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors for output
|
|
readonly RED='\033[0;31m'
|
|
readonly GREEN='\033[0;32m'
|
|
readonly YELLOW='\033[1;33m'
|
|
readonly BLUE='\033[0;34m'
|
|
readonly MAGENTA='\033[0;35m'
|
|
readonly CYAN='\033[0;36m'
|
|
readonly NC='\033[0m' # No Color
|
|
|
|
# Project configuration
|
|
readonly PROJECT_NAME="the-order"
|
|
readonly PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
readonly SCRIPTS_DIR="${PROJECT_ROOT}/scripts"
|
|
readonly INFRA_DIR="${PROJECT_ROOT}/infra"
|
|
readonly TERRAFORM_DIR="${INFRA_DIR}/terraform"
|
|
readonly K8S_DIR="${INFRA_DIR}/k8s"
|
|
readonly PROXMOX_WORKSPACE_ROOT="$(cd "${PROJECT_ROOT}/.." && pwd)"
|
|
|
|
# Load shared Sankofa / Proxmox network inventory when available.
|
|
if [ -f "${PROXMOX_WORKSPACE_ROOT}/config/ip-addresses.conf" ]; then
|
|
# shellcheck source=/dev/null
|
|
source "${PROXMOX_WORKSPACE_ROOT}/config/ip-addresses.conf"
|
|
fi
|
|
|
|
# Environment abbreviation mapping
|
|
get_env_abbrev() {
|
|
case "${ENVIRONMENT:-dev}" in
|
|
dev) echo "dev" ;;
|
|
stage) echo "stg" ;;
|
|
prod) echo "prd" ;;
|
|
mgmt) echo "mgmt" ;;
|
|
*) echo "dev" ;;
|
|
esac
|
|
}
|
|
|
|
readonly ENV_SHORT=$(get_env_abbrev)
|
|
readonly NAME_PREFIX="sankofa-${ENV_SHORT}"
|
|
|
|
# Environment configuration
|
|
readonly ENVIRONMENT="${ENVIRONMENT:-dev}"
|
|
readonly NAMESPACE="the-order-${ENVIRONMENT}"
|
|
|
|
# Local image / artifact configuration
|
|
readonly IMAGE_REGISTRY="${IMAGE_REGISTRY:-theorder}"
|
|
readonly IMAGE_TAG="${IMAGE_TAG:-latest}"
|
|
|
|
# Services
|
|
readonly SERVICES=("identity" "intake" "finance" "dataroom")
|
|
readonly APPS=("portal-public" "portal-internal")
|
|
|
|
# Service ports
|
|
declare -A SERVICE_PORTS=(
|
|
["identity"]="4002"
|
|
["intake"]="4001"
|
|
["finance"]="4003"
|
|
["dataroom"]="4004"
|
|
["portal-public"]="3000"
|
|
["portal-internal"]="3001"
|
|
)
|
|
|
|
# Logging
|
|
readonly LOG_DIR="${PROJECT_ROOT}/logs"
|
|
readonly LOG_FILE="${LOG_DIR}/deployment-$(date +%Y%m%d-%H%M%S).log"
|
|
|
|
# Deployment state
|
|
readonly STATE_DIR="${PROJECT_ROOT}/.deployment"
|
|
readonly STATE_FILE="${STATE_DIR}/${ENVIRONMENT}.state"
|
|
readonly ARTIFACTS_DIR="${STATE_DIR}/artifacts"
|
|
|
|
# Sankofa Phoenix / Proxmox deployment topology
|
|
readonly PROXMOX_HOST="${PROXMOX_HOST:-${PROXMOX_HOST_R630_01:-192.168.11.11}}"
|
|
readonly PROXMOX_SSH_USER="${PROXMOX_SSH_USER:-root}"
|
|
readonly SSH_OPTS="${SSH_OPTS:--o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new}"
|
|
|
|
resolve_host_for_vmid() {
|
|
local vmid="$1"
|
|
local host
|
|
local candidates=(
|
|
"${PROXMOX_HOST_R630_01:-192.168.11.11}"
|
|
"${PROXMOX_HOST_R630_02:-192.168.11.12}"
|
|
"${PROXMOX_HOST_R630_03:-192.168.11.13}"
|
|
"${PROXMOX_HOST_R630_04:-192.168.11.14}"
|
|
)
|
|
|
|
if command -v ssh >/dev/null 2>&1; then
|
|
for host in "${candidates[@]}"; do
|
|
if ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=accept-new \
|
|
"${PROXMOX_SSH_USER}@${host}" "pct status ${vmid}" >/dev/null 2>&1; then
|
|
echo "${host}"
|
|
return 0
|
|
fi
|
|
done
|
|
fi
|
|
|
|
case "${vmid}" in
|
|
10090|10091|10092|10210) echo "${PROXMOX_HOST_R630_04:-192.168.11.14}" ;;
|
|
*) echo "${PROXMOX_HOST}" ;;
|
|
esac
|
|
}
|
|
|
|
readonly ORDER_PORTAL_PUBLIC_VMID="${ORDER_PORTAL_PUBLIC_VMID:-10090}"
|
|
readonly ORDER_PORTAL_PUBLIC_HOST="${ORDER_PORTAL_PUBLIC_HOST:-$(resolve_host_for_vmid "${ORDER_PORTAL_PUBLIC_VMID}")}"
|
|
readonly ORDER_PORTAL_PUBLIC_IP="${ORDER_PORTAL_PUBLIC_IP:-192.168.11.36}"
|
|
readonly ORDER_PORTAL_PUBLIC_PORT="${ORDER_PORTAL_PUBLIC_PORT:-3000}"
|
|
readonly ORDER_PORTAL_PUBLIC_APP_DIR="${ORDER_PORTAL_PUBLIC_APP_DIR:-/opt/the-order/portal-public}"
|
|
readonly ORDER_PORTAL_PUBLIC_SERVICE="${ORDER_PORTAL_PUBLIC_SERVICE:-the-order-portal-public}"
|
|
|
|
readonly ORDER_HAPROXY_VMID="${ORDER_HAPROXY_VMID:-10210}"
|
|
readonly ORDER_HAPROXY_HOST="${ORDER_HAPROXY_HOST:-$(resolve_host_for_vmid "${ORDER_HAPROXY_VMID}")}"
|
|
readonly ORDER_HAPROXY_IP="${ORDER_HAPROXY_IP:-${IP_ORDER_HAPROXY:-192.168.11.39}}"
|
|
readonly ORDER_HAPROXY_BACKEND_HOST="${ORDER_HAPROXY_BACKEND_HOST:-${ORDER_PORTAL_PUBLIC_IP}}"
|
|
readonly ORDER_HAPROXY_BACKEND_PORT="${ORDER_HAPROXY_BACKEND_PORT:-${ORDER_PORTAL_PUBLIC_PORT}}"
|
|
|
|
readonly THE_ORDER_PUBLIC_URL="${THE_ORDER_PUBLIC_URL:-https://the-order.sankofa.nexus}"
|
|
readonly THE_ORDER_WWW_URL="${THE_ORDER_WWW_URL:-https://www.the-order.sankofa.nexus}"
|
|
readonly SANKOFA_PHOENIX_URL="${SANKOFA_PHOENIX_URL:-https://phoenix.sankofa.nexus}"
|
|
readonly SANKOFA_PORTAL_URL="${SANKOFA_PORTAL_URL:-https://portal.sankofa.nexus}"
|
|
|
|
# Create necessary directories
|
|
mkdir -p "${LOG_DIR}"
|
|
mkdir -p "${STATE_DIR}"
|
|
mkdir -p "${ARTIFACTS_DIR}"
|
|
|
|
# Logging functions
|
|
log_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $*" | tee -a "${LOG_FILE}"
|
|
}
|
|
|
|
log_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $*" | tee -a "${LOG_FILE}"
|
|
}
|
|
|
|
log_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $*" | tee -a "${LOG_FILE}"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $*" | tee -a "${LOG_FILE}"
|
|
}
|
|
|
|
log_step() {
|
|
echo -e "${CYAN}[STEP]${NC} $*" | tee -a "${LOG_FILE}"
|
|
}
|
|
|
|
# Error handling
|
|
error_exit() {
|
|
log_error "$1"
|
|
exit "${2:-1}"
|
|
}
|
|
|
|
# Validation functions
|
|
check_command() {
|
|
if ! command -v "$1" &> /dev/null; then
|
|
error_exit "$1 is not installed. Please install it first."
|
|
fi
|
|
}
|
|
|
|
check_prerequisites() {
|
|
log_info "Checking prerequisites..."
|
|
check_command "node"
|
|
check_command "pnpm"
|
|
check_command "docker"
|
|
check_command "git"
|
|
check_command "jq"
|
|
check_command "ssh"
|
|
check_command "scp"
|
|
check_command "tar"
|
|
log_success "All prerequisites met"
|
|
}
|
|
|
|
check_proxmox_access() {
|
|
local hosts=("${PROXMOX_HOST}" "${ORDER_PORTAL_PUBLIC_HOST}" "${ORDER_HAPROXY_HOST}")
|
|
local unique_hosts=()
|
|
local host
|
|
|
|
for host in "${hosts[@]}"; do
|
|
[[ -z "${host}" ]] && continue
|
|
if [[ " ${unique_hosts[*]} " != *" ${host} "* ]]; then
|
|
unique_hosts+=("${host}")
|
|
fi
|
|
done
|
|
|
|
for host in "${unique_hosts[@]}"; do
|
|
log_info "Checking Proxmox access at ${PROXMOX_SSH_USER}@${host}..."
|
|
ssh ${SSH_OPTS} "${PROXMOX_SSH_USER}@${host}" "echo ok" >/dev/null \
|
|
|| error_exit "Failed to reach Proxmox host ${host} over SSH"
|
|
done
|
|
|
|
log_success "Proxmox SSH access verified"
|
|
}
|
|
|
|
# State management
|
|
save_state() {
|
|
local phase="$1"
|
|
local step="$2"
|
|
echo "{\"phase\":\"${phase}\",\"step\":\"${step}\",\"timestamp\":\"$(date -Iseconds)\"}" > "${STATE_FILE}"
|
|
}
|
|
|
|
load_state() {
|
|
if [ -f "${STATE_FILE}" ]; then
|
|
cat "${STATE_FILE}"
|
|
else
|
|
echo "{\"phase\":\"none\",\"step\":\"none\"}"
|
|
fi
|
|
}
|
|
|
|
# Export functions
|
|
export -f log_info log_success log_warning log_error log_step error_exit
|
|
export -f check_command check_prerequisites check_proxmox_access
|
|
export -f save_state load_state
|