mount dev sources directly from workspace PVC

This commit is contained in:
2026-07-21 21:31:09 +00:00
parent 872529b3d9
commit 3c32319603
4 changed files with 16 additions and 116 deletions

View File

@@ -31,14 +31,14 @@ instance can be supplied explicitly:
./dev/start.sh feature-one feature-one.control.k.mancave.link
```
Edits anywhere under `src/` are mirrored into the running NGINX pod. Stop an
instance and permanently remove its Kubernetes resources, sync process, and
shared files with:
Each subtree must live below the PVC mount at `/home/node`. Its `src/` directory
is mounted directly into NGINX, so edits are visible immediately. Stop an
instance and permanently remove all of its labeled Kubernetes resources with:
```bash
./dev/stop.sh hello
```
The scripts use namespace `vibes`, PVC `control-vibes-control-data`, and domain
`control.k.mancave.link` by default. Override them with `DEV_NAMESPACE`,
`DEV_PVC`, `DEV_SHARED_ROOT`, `DEV_PVC_SUBPATH_ROOT`, or `DEV_DOMAIN`.
The scripts use namespace `vibes`, PVC `control-vibes-control-data`, PVC mount
root `/home/node`, and domain `control.k.mancave.link` by default. Override them
with `DEV_NAMESPACE`, `DEV_PVC`, `DEV_PVC_MOUNT_ROOT`, or `DEV_DOMAIN`.

View File

@@ -13,73 +13,27 @@ validate_instance() {
fi
}
sync_tree() {
local source_dir=$1
local destination=$2
mkdir -p -- "$destination"
find "$destination" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +
cp -a -- "$source_dir/." "$destination/"
}
source_signature() {
local source_dir=$1
find "$source_dir" -printf '%P\0%y\0%s\0%T@\0%l\0' | sort -z | sha256sum
}
is_sync_process() {
local pid=$1
local instance=$2
local command
[[ $pid =~ ^[0-9]+$ && -r /proc/$pid/cmdline ]] || return 1
command=$(tr '\0' ' ' <"/proc/$pid/cmdline")
[[ $command == *"start.sh __sync $instance "* ]]
}
if [[ ${1:-} == "__sync" ]]; then
instance=${2:?missing instance}
source_dir=${3:?missing source directory}
destination=${4:?missing destination}
validate_instance "$instance"
previous_signature=$(source_signature "$source_dir")
while true; do
sleep 1
current_signature=$(source_signature "$source_dir")
if [[ $current_signature != "$previous_signature" ]]; then
sync_tree "$source_dir" "$destination"
previous_signature=$current_signature
fi
done
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}
shared_root=${DEV_SHARED_ROOT:-/data/live}
pvc_subpath_root=${DEV_PVC_SUBPATH_ROOT:-live}
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="$REPO_ROOT/src"
destination="$shared_root/$instance"
state_dir="$shared_root/.hello-dev-state"
pid_file="$state_dir/$instance.pid"
log_file="$state_dir/$instance.log"
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 [[ $shared_root != /* || $shared_root == / ]]; then
echo "DEV_SHARED_ROOT must be an absolute directory below /: $shared_root" >&2
exit 2
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
@@ -87,38 +41,16 @@ if [[ ! $host =~ ^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$ ]]; then
exit 2
fi
mkdir -p -- "$state_dir"
if [[ -f $pid_file ]]; then
old_pid=$(<"$pid_file")
if is_sync_process "$old_pid" "$instance"; then
kill "$old_pid"
wait "$old_pid" 2>/dev/null || true
fi
rm -f -- "$pid_file"
fi
sync_tree "$source_dir" "$destination"
nohup "$SCRIPT_DIR/start.sh" __sync "$instance" "$source_dir" "$destination" \
>"$log_file" 2>&1 &
sync_pid=$!
printf '%s\n' "$sync_pid" >"$pid_file"
cleanup_failed_start() {
kill "$sync_pid" 2>/dev/null || true
rm -f -- "$pid_file"
}
trap cleanup_failed_start ERR
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_root/$instance" \
--set-string "sharedVolume.subPath=$pvc_subpath" \
| kubectl apply --namespace "$namespace" -f -
kubectl rollout status "deployment/$release" --namespace "$namespace" --timeout=120s
trap - ERR
echo "Development instance '$instance' is live at http://$host"

View File

@@ -12,44 +12,12 @@ if [[ ${#instance} -gt 42 || ! $instance =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]];
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 \
kubectl delete deployment,service,ingress \
--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"

View File

@@ -7,6 +7,6 @@
</head>
<body>
<h1>Hello, world!!</h1>
<p>Served by NGINX on Minikube from the shared src mount.</p>
<p>Served by NGINX on Minikube from the direct PVC src mount.</p>
</body>
</html>