|
| 1 | +#!/bin/bash |
| 2 | +# ============================================================================= |
| 3 | +# Master orchestration script for EFK offline deployment with Harbor |
| 4 | +# ============================================================================= |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | +source "${SCRIPT_DIR}/scripts/common.sh" |
| 9 | +load_env |
| 10 | + |
| 11 | +usage() { |
| 12 | + echo "Usage: $0 <command>" |
| 13 | + echo "" |
| 14 | + echo "Commands:" |
| 15 | + echo " prepare Download all artifacts for offline use (run with internet)" |
| 16 | + echo " install Full offline installation (Ingress + Harbor + EFK)" |
| 17 | + echo " ingress Install nginx ingress controller" |
| 18 | + echo " harbor Install Harbor registry only" |
| 19 | + echo " push Load images, retag, and push to Harbor" |
| 20 | + echo " efk Install EFK stack from Harbor" |
| 21 | + echo " verify Verify the deployment is working" |
| 22 | + echo " cleanup Remove EFK stack (keeps Harbor)" |
| 23 | + echo " cleanup-all Remove everything including Harbor" |
| 24 | + echo " status Show deployment status" |
| 25 | + echo "" |
| 26 | + echo "Typical workflow:" |
| 27 | + echo " 1. $0 prepare # On internet-connected machine" |
| 28 | + echo " 2. # Transfer artifacts/ to air-gapped environment" |
| 29 | + echo " 3. $0 install # On air-gapped machine" |
| 30 | + echo "" |
| 31 | + echo "Configuration: .env" |
| 32 | + exit 1 |
| 33 | +} |
| 34 | + |
| 35 | +# ---- Commands --------------------------------------------------------------- |
| 36 | + |
| 37 | +cmd_prepare() { |
| 38 | + print_header "Preparing Offline Artifacts" |
| 39 | + bash "${PROJECT_ROOT}/artifacts/download-all.sh" |
| 40 | +} |
| 41 | + |
| 42 | +cmd_ingress() { |
| 43 | + print_header "Installing Ingress Controller" |
| 44 | + bash "${PROJECT_ROOT}/scripts/install-ingress.sh" |
| 45 | +} |
| 46 | + |
| 47 | +cmd_harbor() { |
| 48 | + print_header "Installing Harbor" |
| 49 | + bash "${PROJECT_ROOT}/scripts/install-harbor.sh" |
| 50 | +} |
| 51 | + |
| 52 | +cmd_push() { |
| 53 | + print_header "Pushing Content to Harbor" |
| 54 | + |
| 55 | + print_step "Pushing container images..." |
| 56 | + bash "${PROJECT_ROOT}/scripts/retag-and-push-images.sh" |
| 57 | + |
| 58 | + echo "" |
| 59 | + |
| 60 | + print_step "Pushing Helm charts..." |
| 61 | + bash "${PROJECT_ROOT}/scripts/upload-charts-to-harbor.sh" |
| 62 | +} |
| 63 | + |
| 64 | +cmd_efk() { |
| 65 | + print_header "Installing EFK from Harbor" |
| 66 | + bash "${PROJECT_ROOT}/scripts/offline-install.sh" |
| 67 | +} |
| 68 | + |
| 69 | +cmd_install() { |
| 70 | + print_header "Full Offline Installation" |
| 71 | + echo "" |
| 72 | + print_info "This will: Ingress -> Harbor -> Push images/charts -> Install EFK" |
| 73 | + echo "" |
| 74 | + |
| 75 | + # Step 0: Install Ingress Controller |
| 76 | + cmd_ingress |
| 77 | + echo "" |
| 78 | + |
| 79 | + # Step 1: Install Harbor |
| 80 | + cmd_harbor |
| 81 | + echo "" |
| 82 | + |
| 83 | + # Step 2: Push content to Harbor |
| 84 | + cmd_push |
| 85 | + echo "" |
| 86 | + |
| 87 | + # Step 3: Install EFK |
| 88 | + cmd_efk |
| 89 | + echo "" |
| 90 | + |
| 91 | + # Step 4: Verify |
| 92 | + cmd_verify |
| 93 | +} |
| 94 | + |
| 95 | +cmd_verify() { |
| 96 | + print_header "Verifying Deployment" |
| 97 | + bash "${PROJECT_ROOT}/scripts/verify-deployment.sh" |
| 98 | +} |
| 99 | + |
| 100 | +cmd_status() { |
| 101 | + print_header "Deployment Status" |
| 102 | + |
| 103 | + echo "" |
| 104 | + print_step "Harbor namespace:" |
| 105 | + kubectl get pods -n "${HARBOR_NAMESPACE}" 2>/dev/null || echo " Harbor not installed" |
| 106 | + |
| 107 | + echo "" |
| 108 | + print_step "EFK namespace:" |
| 109 | + kubectl get pods -n "${EFK_NAMESPACE}" 2>/dev/null || echo " EFK not installed" |
| 110 | + |
| 111 | + echo "" |
| 112 | + print_step "Helm releases:" |
| 113 | + helm list -n "${HARBOR_NAMESPACE}" 2>/dev/null || true |
| 114 | + helm list -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 115 | + |
| 116 | + echo "" |
| 117 | + print_step "Ingress:" |
| 118 | + kubectl get ingress -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 119 | +} |
| 120 | + |
| 121 | +cmd_cleanup() { |
| 122 | + print_warning "Cleaning up EFK stack..." |
| 123 | + |
| 124 | + helm uninstall log-processor -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 125 | + helm uninstall log-generator -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 126 | + helm uninstall filebeat -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 127 | + helm uninstall kibana -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 128 | + helm uninstall elasticsearch -n "${EFK_NAMESPACE}" 2>/dev/null || true |
| 129 | + |
| 130 | + kubectl delete jobs -n "${EFK_NAMESPACE}" -l app=log-processor 2>/dev/null || true |
| 131 | + kubectl delete jobs -n "${EFK_NAMESPACE}" -l app=kibana-dashboard-importer 2>/dev/null || true |
| 132 | + kubectl delete namespace "${EFK_NAMESPACE}" 2>/dev/null || true |
| 133 | + |
| 134 | + print_success "EFK cleanup complete" |
| 135 | +} |
| 136 | + |
| 137 | +cmd_cleanup_all() { |
| 138 | + cmd_cleanup |
| 139 | + |
| 140 | + print_warning "Cleaning up Harbor..." |
| 141 | + helm uninstall harbor -n "${HARBOR_NAMESPACE}" 2>/dev/null || true |
| 142 | + kubectl delete namespace "${HARBOR_NAMESPACE}" 2>/dev/null || true |
| 143 | + |
| 144 | + print_warning "Cleaning up Ingress Controller..." |
| 145 | + helm uninstall ingress-nginx -n "${INGRESS_NAMESPACE}" 2>/dev/null || true |
| 146 | + kubectl delete namespace "${INGRESS_NAMESPACE}" 2>/dev/null || true |
| 147 | + |
| 148 | + print_success "Full cleanup complete" |
| 149 | +} |
| 150 | + |
| 151 | +# ---- Main ------------------------------------------------------------------- |
| 152 | + |
| 153 | +case "${1:-}" in |
| 154 | +prepare) cmd_prepare ;; |
| 155 | +install) cmd_install ;; |
| 156 | +ingress) cmd_ingress ;; |
| 157 | +harbor) cmd_harbor ;; |
| 158 | +push) cmd_push ;; |
| 159 | +efk) cmd_efk ;; |
| 160 | +verify) cmd_verify ;; |
| 161 | +cleanup) cmd_cleanup ;; |
| 162 | +cleanup-all) cmd_cleanup_all ;; |
| 163 | +status) cmd_status ;; |
| 164 | +*) usage ;; |
| 165 | +esac |
0 commit comments