up() { echo "Deploying the homelab infrastructure..." docker run --rm --privileged multiarch/qemu-user-static --reset -p yes cat < /tmp/buildx-config.toml [registry."127.0.0.1:30500"] http = true [registry."localhost:30500"] http = true EOF docker buildx rm lab-builder 2>/dev/null || true docker buildx create --name lab-builder --driver docker-container --driver-opt network=host --config /tmp/buildx-config.toml --use docker buildx inspect --bootstrap cd bootstrap/cluster tofu init tofu apply -auto-approve cd ../platform tofu init tofu apply -auto-approve cd ../apps tofu init tofu apply -auto-approve cd ../.. until kubectl get deployment local-registry -n container-registry -o jsonpath='{.status.availableReplicas}' 2>/dev/null | grep -q '^[1-9]'; do echo "Waiting for local-registry pods to initialize..." sleep 5 done docker buildx build \ --network host \ --platform linux/amd64,linux/arm64 \ -t "127.0.0.1:30500/php-website:latest" \ -f apps/website/Dockerfile \ apps/website/ \ --push kubectl patch application php-web-app -n argocd --type merge -p '{"metadata":{"annotations":{"argocd.argoproj.io/refresh":"sync"}}}' echo "Deployment successfully completed!" } nuke() { echo "Brutally nuking the homelab infrastructure..." echo "--> Terminating local OpenTofu tasks..." killall tofu terraform 2>/dev/null || true echo "--> Eviscerating local Kubernetes components (Laptop)..." sudo kubeadm reset --force || true sudo systemctl stop containerd 2>/dev/null || true sudo killall containerd-shim-runc-v2 2>/dev/null || true sudo umount /var/lib/containerd/srun/* 2>/dev/null || true sudo rm -rf /var/lib/containerd/* /run/containerd/* sudo rm -rf /etc/kubernetes/ /var/lib/kubelet/ /var/lib/cni/ /etc/cni/net.d /home/jv/.kube/ sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X sudo ip link delete cilium_host 2>/dev/null || true sudo ip link delete cilium_net 2>/dev/null || true sudo ip link delete cilium_vxlan 2>/dev/null || true sudo systemctl start containerd echo "--> Eviscerating remote Kubernetes components (Raspberry Pi)..." ssh -o ConnectTimeout=5 jv@192.168.100.89 << 'EOF' 2>/dev/null || true # 1. Force reset kubeadm configurations sudo kubeadm reset --force || true # 2. Halt the container runtime engine to drop file descriptor and socket locks sudo systemctl stop containerd 2>/dev/null || true sudo killall containerd-shim-runc-v2 2>/dev/null || true # 3. Unmount any lingering ephemeral pod volumes, secrets, or token rings sudo umount -f /var/lib/kubelet/pods/*/*/*/* 2>/dev/null || true # 4. Completely wipe the cluster file configurations and runtime data tracks sudo rm -rf /etc/kubernetes/ /var/lib/kubelet/ /var/lib/cni/ /etc/cni/net.d sudo rm -rf /var/lib/containerd/* /run/containerd/* # 5. Reset network routing policies left over by the CNI sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X # 6. Bring the container engine back online with a completely clean state slate sudo systemctl start containerd EOF docker buildx rm lab-builder 2>/dev/null || true rm -f /tmp/buildx-config.toml || true echo "--> Deleting OpenTofu tracking state files..." rm -rf bootstrap/cluster/terraform.tfstate* rm -rf bootstrap/cluster/.terraform/ rm -rf bootstrap/cluster/.terraform.lock.hcl rm -rf bootstrap/platform/terraform.tfstate* rm -rf bootstrap/platform/.terraform/ rm -rf bootstrap/platform/.terraform.lock.hcl rm -rf bootstrap/apps/terraform.tfstate* rm -rf bootstrap/apps/.terraform/ rm -rf bootstrap/apps/.terraform.lock.hcl echo "Destruction complete! Your hardware is completely sanitized." } case "$1" in up) up ;; nuke) nuke ;; *) echo "Usage: $0 {up|nuke}" exit 1 ;; esac