#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) REPO_ROOT=$(cd -- "$SCRIPT_DIR/.." && pwd) validate_instance() { local instance=$1 if [[ ${#instance} -gt 42 || ! $instance =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]]; then echo "instance must be 1-42 lowercase letters, digits, or internal hyphens: $instance" >&2 exit 2 fi } default_instance=$(basename -- "$REPO_ROOT" | tr '[:upper:]_' '[:lower:]-') instance=${1:-$default_instance} validate_instance "$instance" namespace=${DEV_NAMESPACE:-vibes} pvc=${DEV_PVC:-control-vibes-control-data} pvc_mount_root=${DEV_PVC_MOUNT_ROOT:-/home/node} domain=${DEV_DOMAIN:-control.k.mancave.link} host=${2:-$instance.$domain} release="hello-dev-$instance" source_dir=$(realpath -- "$REPO_ROOT/src") pvc_mount_root=$(realpath -- "$pvc_mount_root") if [[ ! -d $source_dir ]]; then echo "source directory does not exist: $source_dir" >&2 exit 1 fi if [[ $source_dir != "$pvc_mount_root/"* ]]; then echo "source directory is outside the PVC mount at $pvc_mount_root: $source_dir" >&2 exit 1 fi if [[ ! $host =~ ^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$ ]]; then echo "invalid hostname: $host" >&2 exit 2 fi pvc_subpath=${source_dir#"$pvc_mount_root/"} helm template "$release" "$SCRIPT_DIR/helm" \ --namespace "$namespace" \ --set-string "instance=$instance" \ --set-string "ingress.host=$host" \ --set-string "sharedVolume.claimName=$pvc" \ --set-string "sharedVolume.subPath=$pvc_subpath" \ | kubectl apply --namespace "$namespace" -f - kubectl rollout status "deployment/$release" --namespace "$namespace" --timeout=120s echo "Development instance '$instance' is live at http://$host"