197 lines
5.3 KiB
Bash
197 lines
5.3 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Unified Deployment Framework
|
||
|
|
# Consolidates all deploy/setup/install scripts into one parameterized framework
|
||
|
|
# Usage: ./scripts/deploy.sh [component] [options] [host]
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
# Load IP configuration
|
||
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||
|
|
|
||
|
|
|
||
|
|
# Load shared modules
|
||
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
source "$SCRIPT_DIR/lib/ip-config.sh" 2>/dev/null || true
|
||
|
|
source "$SCRIPT_DIR/lib/logging.sh" 2>/dev/null || true
|
||
|
|
source "$SCRIPT_DIR/lib/proxmox-api.sh" 2>/dev/null || true
|
||
|
|
source "$SCRIPT_DIR/lib/ssh-helpers.sh" 2>/dev/null || true
|
||
|
|
|
||
|
|
# Default values
|
||
|
|
COMPONENT="${1:-all}"
|
||
|
|
OPTIONS="${2:-}"
|
||
|
|
HOST="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||
|
|
PHASE="${PHASE:-}"
|
||
|
|
|
||
|
|
# Show usage
|
||
|
|
show_usage() {
|
||
|
|
cat <<EOF
|
||
|
|
Usage: $0 [component] [options] [host]
|
||
|
|
|
||
|
|
Components:
|
||
|
|
all - Deploy all (default)
|
||
|
|
service - Deploy services
|
||
|
|
container - Deploy containers
|
||
|
|
infrastructure - Deploy infrastructure
|
||
|
|
besu - Deploy Besu nodes
|
||
|
|
rpc - Deploy RPC nodes
|
||
|
|
validator - Deploy validator nodes
|
||
|
|
blockscout - Deploy Blockscout explorer
|
||
|
|
omnis - Deploy OMNIS application
|
||
|
|
|
||
|
|
Options:
|
||
|
|
--phase=[1|2|3] - Deploy specific phase
|
||
|
|
--validate - Validate before deployment
|
||
|
|
--dry-run - Show what would be deployed
|
||
|
|
|
||
|
|
Examples:
|
||
|
|
$0 service postgresql
|
||
|
|
$0 container 5000
|
||
|
|
$0 all --phase=1
|
||
|
|
$0 besu --validate
|
||
|
|
EOF
|
||
|
|
}
|
||
|
|
|
||
|
|
# Service deployment functions
|
||
|
|
deploy_service() {
|
||
|
|
local service="$1"
|
||
|
|
local vmid="${2:-}"
|
||
|
|
local host="${3:-$HOST}"
|
||
|
|
|
||
|
|
log_info "Deploying service: $service${vmid:+ to VMID $vmid}"
|
||
|
|
|
||
|
|
# Add service deployment logic
|
||
|
|
log_success "Service $service deployed${vmid:+ to VMID $vmid}"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Container deployment functions
|
||
|
|
deploy_container() {
|
||
|
|
local vmid="$1"
|
||
|
|
local template="${2:-}"
|
||
|
|
local host="${3:-$HOST}"
|
||
|
|
|
||
|
|
log_info "Deploying container: VMID $vmid${template:+ from template $template}"
|
||
|
|
|
||
|
|
# Add container deployment logic
|
||
|
|
log_success "Container $vmid deployed"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Infrastructure deployment functions
|
||
|
|
deploy_infrastructure() {
|
||
|
|
local component="${1:-all}"
|
||
|
|
local host="${2:-$HOST}"
|
||
|
|
|
||
|
|
log_info "Deploying infrastructure: $component"
|
||
|
|
|
||
|
|
# Add infrastructure deployment logic
|
||
|
|
log_success "Infrastructure $component deployed"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Besu deployment functions
|
||
|
|
deploy_besu() {
|
||
|
|
local node_type="${1:-rpc}"
|
||
|
|
local host="${2:-$HOST}"
|
||
|
|
|
||
|
|
log_info "Deploying Besu $node_type node..."
|
||
|
|
|
||
|
|
# Add Besu deployment logic
|
||
|
|
log_success "Besu $node_type node deployed"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Phased deployment support
|
||
|
|
deploy_phase() {
|
||
|
|
local phase="${1:-1}"
|
||
|
|
|
||
|
|
log_info "Deploying phase $phase..."
|
||
|
|
|
||
|
|
case "$phase" in
|
||
|
|
1)
|
||
|
|
log_info "Phase 1: Deploying Besu nodes..."
|
||
|
|
deploy_besu "validator" "$HOST" || true
|
||
|
|
deploy_besu "sentry" "$HOST" || true
|
||
|
|
;;
|
||
|
|
2)
|
||
|
|
log_info "Phase 2: Deploying RPC nodes..."
|
||
|
|
deploy_besu "rpc" "$HOST" || true
|
||
|
|
;;
|
||
|
|
3)
|
||
|
|
log_info "Phase 3: Deploying services..."
|
||
|
|
deploy_service "postgresql" "" "$HOST" || true
|
||
|
|
deploy_service "redis" "" "$HOST" || true
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
log_error "Unknown phase: $phase"
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
}
|
||
|
|
|
||
|
|
# Main deployment logic
|
||
|
|
main() {
|
||
|
|
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ] || [ $# -eq 0 ]; then
|
||
|
|
show_usage
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Check for phase option
|
||
|
|
if [[ "$OPTIONS" =~ --phase=([0-9]+) ]]; then
|
||
|
|
PHASE="${BASH_REMATCH[1]}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
log_header "Unified Deployment Framework"
|
||
|
|
|
||
|
|
case "$COMPONENT" in
|
||
|
|
service|services)
|
||
|
|
deploy_service "${OPTIONS:-postgresql}" "" "$HOST" || true
|
||
|
|
;;
|
||
|
|
container|containers)
|
||
|
|
if [ -n "$OPTIONS" ] && [[ "$OPTIONS" =~ ^[0-9]+$ ]]; then
|
||
|
|
deploy_container "$OPTIONS" "" "$HOST" || true
|
||
|
|
else
|
||
|
|
log_info "Specify VMID to deploy container"
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
infrastructure)
|
||
|
|
deploy_infrastructure "${OPTIONS:-all}" "$HOST" || true
|
||
|
|
;;
|
||
|
|
besu)
|
||
|
|
deploy_besu "${OPTIONS:-rpc}" "$HOST" || true
|
||
|
|
;;
|
||
|
|
rpc)
|
||
|
|
deploy_besu "rpc" "$HOST" || true
|
||
|
|
;;
|
||
|
|
validator)
|
||
|
|
deploy_besu "validator" "$HOST" || true
|
||
|
|
;;
|
||
|
|
blockscout)
|
||
|
|
deploy_container "5000" "" "$HOST" || true
|
||
|
|
;;
|
||
|
|
omnis)
|
||
|
|
if [ -f "$SCRIPT_DIR/deploy-omnis.sh" ]; then
|
||
|
|
"$SCRIPT_DIR/deploy-omnis.sh" "${OPTIONS:-production}" "" "$HOST" || true
|
||
|
|
else
|
||
|
|
log_error "OMNIS deployment script not found"
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
all)
|
||
|
|
if [ -n "$PHASE" ]; then
|
||
|
|
deploy_phase "$PHASE" || true
|
||
|
|
else
|
||
|
|
log_info "Deploying all components..."
|
||
|
|
deploy_besu "rpc" "$HOST" || true
|
||
|
|
deploy_service "postgresql" "" "$HOST" || true
|
||
|
|
deploy_infrastructure "all" "$HOST" || true
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
log_error "Unknown component: $COMPONENT"
|
||
|
|
show_usage
|
||
|
|
exit 1
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
|
||
|
|
log_success "Deployment complete!"
|
||
|
|
}
|
||
|
|
|
||
|
|
main "$@"
|