mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 12:03:59 +00:00
- Standardized naming from "Prole" to "Knoe" in README, scripts, and deployment files for consistency. - Refined ingress configuration to adjust class and annotations based on mode. - Enhanced deploy.sh to handle public APP endpoint status for specific hosts.
105 lines
3.7 KiB
Bash
Executable File
105 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
CONFIG_PATH="${PROLE_DEPLOY_CFG:-${ROOT_DIR}/conf/gke.cfg}"
|
|
|
|
if [[ -x "${ROOT_DIR}/.venv/bin/python3" ]]; then
|
|
PYTHON_BIN="${ROOT_DIR}/.venv/bin/python3"
|
|
elif [[ -x "${ROOT_DIR}/bin/python3" ]]; then
|
|
PYTHON_BIN="${ROOT_DIR}/bin/python3"
|
|
else
|
|
PYTHON_BIN="${PYTHON:-python3}"
|
|
fi
|
|
|
|
"${PYTHON_BIN}" -m prole.deploy_pipeline --config "${CONFIG_PATH}" "$@"
|
|
|
|
# Post-deploy summary
|
|
echo ""
|
|
echo "Public Endpoints:"
|
|
"${PYTHON_BIN}" - "${CONFIG_PATH}" <<'PY'
|
|
import sys
|
|
import subprocess
|
|
import json
|
|
import configparser
|
|
import time
|
|
|
|
def get_config(path):
|
|
c = configparser.ConfigParser()
|
|
c.read(path)
|
|
# Check [Global] then [env_setup] then [init_cluster] for contexts
|
|
g = c["Global"] if "Global" in c else {}
|
|
e = c["env_setup"] if "env_setup" in c else {}
|
|
i = c["init_cluster"] if "init_cluster" in c else {}
|
|
|
|
app_ctx = g.get("APP_CLUSTER_KUBECONTEXT") or e.get("APP_CLUSTER_KUBECONTEXT") or i.get("app_cluster_kubecontext", "")
|
|
db_ctx = g.get("DB_CLUSTER_KUBECONTEXT") or e.get("DB_CLUSTER_KUBECONTEXT") or i.get("db_cluster_kubecontext", "")
|
|
return app_ctx, db_ctx
|
|
|
|
def get_ip(host, ctx):
|
|
if not ctx: return "pending"
|
|
# Try Ingress first
|
|
try:
|
|
out = subprocess.check_output(["kubectl", "--context", ctx, "get", "ingress", "-A", "-o", "json"], stderr=subprocess.DEVNULL, text=True)
|
|
items = json.loads(out).get("items", [])
|
|
for item in items:
|
|
for rule in item.get("spec", {}).get("rules", []):
|
|
if rule.get("host") == host:
|
|
ing = item.get("status", {}).get("loadBalancer", {}).get("ingress", [])
|
|
if ing:
|
|
val = ing[0].get("ip") or ing[0].get("hostname")
|
|
if val: return val
|
|
except: pass
|
|
|
|
# Public APP endpoints must be sourced from Ingress status
|
|
if host in ["api.knoe.dev", "git.knoe.dev", "svc.knoe.dev", "api.0.knoe.dev", "db.0.knoe.dev"]:
|
|
return "pending"
|
|
|
|
# Try Service fallback
|
|
try:
|
|
svcs = []
|
|
if "git" in host: svcs = [("gitlab", "gitlab-nginx-ingress-controller")]
|
|
elif "api.knoe" in host or "svc.knoe" in host: svcs = [("knoe-system", "knoe-svc-kong-proxy")]
|
|
elif "0.knoe" in host: svcs = [("supabase", "kong"), ("supabase", "studio")]
|
|
|
|
for ns, name in svcs:
|
|
out = subprocess.check_output(["kubectl", "--context", ctx, "get", "svc", "-n", ns, name, "-o", "json"], stderr=subprocess.DEVNULL, text=True)
|
|
ing = json.loads(out).get("status", {}).get("loadBalancer", {}).get("ingress", [])
|
|
if ing:
|
|
val = ing[0].get("ip") or ing[0].get("hostname")
|
|
if val: return val
|
|
except: pass
|
|
return "pending"
|
|
|
|
app_ctx, db_ctx = get_config(sys.argv[1])
|
|
|
|
# Targets we want to wait for if they are pending
|
|
wait_hosts = ["api.0.knoe.dev", "db.0.knoe.dev"]
|
|
timeout = 300 # 5 minutes
|
|
start = time.time()
|
|
|
|
while time.time() - start < timeout:
|
|
pending = False
|
|
for h in wait_hosts:
|
|
if get_ip(h, app_ctx) == "pending":
|
|
pending = True
|
|
break
|
|
if not pending:
|
|
break
|
|
time.sleep(10)
|
|
|
|
endpoints = [
|
|
("api.knoe.dev", "knoe-svc-kong", "APP", app_ctx),
|
|
("git.knoe.dev", "GitLab", "APP", app_ctx),
|
|
("db.0.knoe.dev", "Supabase Studio", "APP", app_ctx),
|
|
("api.0.knoe.dev", "Supabase Kong", "APP", app_ctx),
|
|
("svc.knoe.dev", "Grafana", "APP", app_ctx),
|
|
]
|
|
|
|
print(f"{'hostname':<20} {'service':<20} {'cluster':<10} {'external IP':<15}")
|
|
print("-" * 70)
|
|
for host, svc, clus, ctx in endpoints:
|
|
ip = get_ip(host, ctx)
|
|
print(f"{host:<20} {svc:<20} {clus:<10} {ip:<15}")
|
|
PY
|