fuckeduppdp/misc/bootstrap-k8s-imageless.sh

44 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -e
#
# This file is used to deploy a PDP-11 from a container image without a baked-in disk image.
#
usage () {
echo "usage: $0 tag disk_filename"
exit 1
}
[[ $# -eq 2 ]] || usage
tag="$1"
disk_filename="$2"
cd "$(dirname $(dirname $0))"
[[ -f "$disk_filename" && -r "$disk_filename" ]] || { echo "$disk_filename does not exist, is not a regular file, or is not readable"; exit 1; }
[[ "$disk_filename" == *.gz ]] || { echo "$disk_filename does not appear to be a gzip-compressed disk image"; exit 1; }
sed "s!<TAG>!${tag}!" ./k8s/deployment.yaml.template > ./k8s/deployment.yaml
echo "Creating PVC..."
kubectl apply -f ./k8s/pvc.yaml
echo "Creating temporary pod..."
kubectl apply -f ./k8s/pod-tmp.yaml
echo "Waiting for temporary pod..."
while ! kubectl get pod pdp-tmp|grep -q Running; do sleep 1; done
echo "Checking for disk image..."
if ! kubectl exec -it pdp-tmp -- test -f /mnt/rq0.dsk &>/dev/null; then
echo "Uploading compressed disk image..."
kubectl exec pdp-tmp -- rm -f /mnt/rq0.dsk.gz
kubectl cp "$disk_filename" pdp-tmp:/mnt/rq0.dsk.gz
echo "Extracting disk image..."
kubectl exec pdp-tmp -- gzip -d /mnt/rq0.dsk.gz
fi
echo "Removing temporary pod..."
kubectl delete -f ./k8s/pod-tmp.yaml
echo "Creating PDP deployment..."
kubectl apply -f ./k8s/deployment.yaml
echo "Creating services..."
for i in ./k8s/svc-*.yaml; do kubectl apply -f "$i"; done
echo "Done! Optionally, run ./misc/configure-metallb.sh to put the services on an external IP."