add isolated live development deployments
This commit is contained in:
55
dev/stop.sh
Executable file
55
dev/stop.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
||||
REPO_ROOT=$(cd -- "$SCRIPT_DIR/.." && pwd)
|
||||
default_instance=$(basename -- "$REPO_ROOT" | tr '[:upper:]_' '[:lower:]-')
|
||||
instance=${1:-$default_instance}
|
||||
|
||||
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
|
||||
|
||||
namespace=${DEV_NAMESPACE:-vibes}
|
||||
shared_root=${DEV_SHARED_ROOT:-/data/live}
|
||||
destination="$shared_root/$instance"
|
||||
state_dir="$shared_root/.hello-dev-state"
|
||||
pid_file="$state_dir/$instance.pid"
|
||||
log_file="$state_dir/$instance.log"
|
||||
label="dev.mancave.link/instance=$instance"
|
||||
|
||||
if [[ $shared_root != /* || $shared_root == / ]]; then
|
||||
echo "DEV_SHARED_ROOT must be an absolute directory below /: $shared_root" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -f $pid_file ]]; then
|
||||
sync_pid=$(<"$pid_file")
|
||||
process_command=""
|
||||
if [[ $sync_pid =~ ^[0-9]+$ && -r /proc/$sync_pid/cmdline ]]; then
|
||||
process_command=$(tr '\0' ' ' <"/proc/$sync_pid/cmdline")
|
||||
fi
|
||||
if [[ $process_command == *"start.sh __sync $instance "* ]]; then
|
||||
kill "$sync_pid"
|
||||
for _ in {1..20}; do
|
||||
kill -0 "$sync_pid" 2>/dev/null || break
|
||||
sleep 0.1
|
||||
done
|
||||
kill -9 "$sync_pid" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
kubectl delete all,ingress,configmap,secret,pvc \
|
||||
--namespace "$namespace" \
|
||||
--selector "$label" \
|
||||
--ignore-not-found=true \
|
||||
--wait=true
|
||||
|
||||
if [[ -d $destination ]]; then
|
||||
find "$destination" -depth -delete
|
||||
fi
|
||||
rm -f -- "$pid_file" "$log_file"
|
||||
rmdir -- "$state_dir" 2>/dev/null || true
|
||||
|
||||
echo "Development instance '$instance' was permanently removed"
|
||||
Reference in New Issue
Block a user