43 lines
1.7 KiB
Bash
Executable file
43 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# deploy-lcl.sh — build go-bananas, push it to the local registry, and deploy it to
|
|
# the lcl k3s cluster, then verify it is live through the TLS edge.
|
|
#
|
|
# Thin wrapper around `make deploy-lcl` that adds the two things that actually go
|
|
# wrong locally: talking to the cluster, and pulling a stale cached image.
|
|
#
|
|
# ./hack/deploy-lcl.sh
|
|
# KUBECONFIG=/etc/rancher/k3s/k3s.yaml ./hack/deploy-lcl.sh
|
|
# LCL_TAG=v1.2.3 ./hack/deploy-lcl.sh
|
|
#
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
LCL_REGISTRY="${LCL_REGISTRY:-localhost:5000}"
|
|
LCL_NAMESPACE="${LCL_NAMESPACE:-go-insane-lcl}"
|
|
|
|
# Prefer an explicit KUBECONFIG; otherwise try the direct k3s config if the current
|
|
# context cannot reach a node. The default `local` context routes through a Rancher
|
|
# proxy that can 502, and a deploy against it fails with a confusing transport error
|
|
# rather than a real one.
|
|
if [ -z "${KUBECONFIG:-}" ]; then
|
|
if ! timeout 10 kubectl get nodes >/dev/null 2>&1 && [ -r /etc/rancher/k3s/k3s.yaml ]; then
|
|
echo "note: current kube context cannot reach a node; using /etc/rancher/k3s/k3s.yaml" >&2
|
|
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
|
fi
|
|
fi
|
|
|
|
echo "=== preflight ==="
|
|
timeout 6 curl -sf "${LCL_REGISTRY}/v2/" >/dev/null || {
|
|
echo "error: no registry answering at ${LCL_REGISTRY}/v2 — start it before deploying" >&2
|
|
exit 1
|
|
}
|
|
kubectl get nodes >/dev/null 2>&1 || {
|
|
echo "error: cannot reach the cluster (KUBECONFIG=${KUBECONFIG:-<default>})" >&2
|
|
exit 1
|
|
}
|
|
echo "registry OK (${LCL_REGISTRY}) ; cluster OK ($(kubectl config current-context 2>/dev/null || echo "$KUBECONFIG"))"
|
|
|
|
echo "=== build + push + deploy + verify ==="
|
|
exec make deploy-lcl LCL_NAMESPACE="$LCL_NAMESPACE"
|