mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 17:44:33 +00:00
- Ensure cluster exists before attempting to patch the image in `init_prole-db.sh`. - Introduce function to apply hostNetwork patch for OpenBao in `init_openbao.sh`.
132 lines
3.1 KiB
Bash
Executable File
132 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# init_supabase.sh
|
|
# Purpose:
|
|
# - Deploy Supabase in Kubernetes and connect it to the CNPG Postgres cluster.
|
|
|
|
# Initialize SCRIPT_DIR
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
ACTION=${1:-}
|
|
|
|
# Load env
|
|
if [[ -n "${PROLE_HOME:-}" && -f "$PROLE_HOME/env.sh" ]]; then
|
|
set --
|
|
# shellcheck disable=SC1090
|
|
source "$PROLE_HOME/env.sh"
|
|
elif [[ -f "$HOME/.prole/env.sh" ]]; then
|
|
set --
|
|
# shellcheck disable=SC1090
|
|
source "$HOME/.prole/env.sh"
|
|
fi
|
|
|
|
NAMESPACE=${NAMESPACE:-default}
|
|
CNPG_CLUSTER_NAME=${CNPG_CLUSTER_NAME:-prole-db}
|
|
|
|
# Support both PROLE_HOME/k8s and sibling k8s directory
|
|
if [[ -d "$SCRIPT_DIR/../k8s/prole" ]]; then
|
|
SUPABASE_MANIFEST_DIR="$SCRIPT_DIR/../k8s/prole"
|
|
elif [[ -n "${PROLE_HOME:-}" && -d "$PROLE_HOME/k8s/prole" ]]; then
|
|
SUPABASE_MANIFEST_DIR="$PROLE_HOME/k8s/prole"
|
|
else
|
|
SUPABASE_MANIFEST_DIR="$SCRIPT_DIR/../k8s/prole"
|
|
fi
|
|
|
|
SUPABASE_FILES=(
|
|
"$SUPABASE_MANIFEST_DIR/supabase-configmap.yaml"
|
|
"$SUPABASE_MANIFEST_DIR/supabase-deployment.yaml"
|
|
"$SUPABASE_MANIFEST_DIR/supabase-service.yaml"
|
|
)
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $0 [start|stop|restart|status]
|
|
|
|
Actions:
|
|
start Apply Supabase manifests
|
|
stop Delete Supabase manifests
|
|
restart Re-apply Supabase manifests
|
|
status Show Supabase resources
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
ensure_tools() {
|
|
for t in kubectl; do
|
|
command -v "$t" >/dev/null || { echo "Missing required tool: $t" >&2; exit 1; }
|
|
done
|
|
}
|
|
|
|
ensure_namespace() {
|
|
if ! kubectl get namespace "$NAMESPACE" >/dev/null 2>&1; then
|
|
echo "Creating namespace '$NAMESPACE' ..."
|
|
kubectl create namespace "$NAMESPACE" >/dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
|
|
ensure_prereqs() {
|
|
ensure_namespace
|
|
if ! kubectl get cluster "$CNPG_CLUSTER_NAME" -n "$NAMESPACE" >/dev/null 2>&1; then
|
|
echo "ERROR: CNPG cluster '$CNPG_CLUSTER_NAME' not found in namespace '$NAMESPACE'." >&2
|
|
exit 1
|
|
fi
|
|
if ! kubectl get secret prole-db-user -n "$NAMESPACE" >/dev/null 2>&1; then
|
|
echo "ERROR: Secret 'prole-db-user' not found in namespace '$NAMESPACE'." >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
apply_manifests() {
|
|
for f in "${SUPABASE_FILES[@]}"; do
|
|
if [[ -f "$f" ]]; then
|
|
kubectl apply -n "$NAMESPACE" -f "$f"
|
|
else
|
|
echo "ERROR: Missing manifest: $f" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
delete_manifests() {
|
|
for f in "${SUPABASE_FILES[@]}"; do
|
|
if [[ -f "$f" ]]; then
|
|
kubectl delete -n "$NAMESPACE" -f "$f" --ignore-not-found
|
|
fi
|
|
done
|
|
}
|
|
|
|
status() {
|
|
ensure_tools
|
|
echo "Supabase status in namespace '$NAMESPACE':"
|
|
kubectl get deploy supabase -n "$NAMESPACE" || true
|
|
kubectl get svc supabase -n "$NAMESPACE" || true
|
|
}
|
|
|
|
case "$ACTION" in
|
|
start)
|
|
ensure_tools
|
|
ensure_prereqs
|
|
echo "Applying Supabase manifests in namespace '$NAMESPACE'..."
|
|
apply_manifests
|
|
;;
|
|
stop)
|
|
ensure_tools
|
|
echo "Deleting Supabase manifests from namespace '$NAMESPACE'..."
|
|
delete_manifests
|
|
;;
|
|
restart)
|
|
ensure_tools
|
|
ensure_prereqs
|
|
echo "Re-applying Supabase manifests in namespace '$NAMESPACE'..."
|
|
apply_manifests
|
|
;;
|
|
status)
|
|
status
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|