Report edge bootstrap failure stage
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-28 22:32:30 -06:00
parent 0b5bf06b35
commit 15e195e121
2 changed files with 37 additions and 1 deletions

View File

@ -210,6 +210,14 @@ enable_letsencrypt="${self.triggers.enable_letsencrypt}"
letsencrypt_email="${self.triggers.letsencrypt_email}"
letsencrypt_staging="${self.triggers.letsencrypt_staging}"
certbot_image="certbot/certbot:latest"
diagnostic_log="/tmp/homelab-edge-bootstrap-stage.log"
stage="initializing"
printf '%s\n' "$stage" | sudo tee "$diagnostic_log" >/dev/null
edge_stage() {
stage="$1"
printf '%s\n' "$stage" | sudo tee "$diagnostic_log" >/dev/null
}
trap 'rc=$?; printf "exit=%s stage=%s\\n" "$rc" "$stage" | sudo tee -a "$diagnostic_log" >/dev/null; exit "$rc"' EXIT
install_missing_packages() {
missing_packages=""
@ -224,9 +232,11 @@ install_missing_packages() {
fi
}
edge_stage packages
install_missing_packages ca-certificates curl openssl prometheus-node-exporter
sudo systemctl enable --now prometheus-node-exporter
edge_stage tailscale
if ! command -v tailscale >/dev/null 2>&1; then
curl -fsSL https://tailscale.com/install.sh | sudo sh
fi
@ -242,11 +252,13 @@ if ! tailscale ip -4 >/dev/null 2>&1; then
exit 1
fi
edge_stage backend-traefik
if ! curl -fsS --connect-timeout 10 -H "Host: $server_name" "http://$backend_host:$backend_port/" >/dev/null; then
echo "Warning: cannot reach Traefik backend http://$backend_host:$backend_port/ for $server_name from the edge host." >&2
echo "The edge proxy will still be deployed so independent routes such as /git/ can recover." >&2
fi
edge_stage backend-gitea
if ! curl -sS --connect-timeout 10 "http://$gitea_backend_host:$gitea_backend_port/git/" >/dev/null; then
echo "Cannot reach Gitea backend http://$gitea_backend_host:$gitea_backend_port/git/ from the edge host." >&2
echo "Check the Debian host Tailscale IP, Gitea container, and port publishing." >&2
@ -273,6 +285,7 @@ if ! curl -sS --connect-timeout 10 -o /dev/null -w '%%{http_code}' "http://$jean
echo "Check the Debian Jeannie API service before testing the public hostname." >&2
fi
edge_stage docker
if ! command -v docker >/dev/null 2>&1; then
if [ "$install_docker" = "true" ]; then
curl -fsSL https://get.docker.com | sudo sh
@ -416,6 +429,7 @@ cleanup_legacy_edge_containers() {
done
}
edge_stage compose
cd "$install_dir"
cleanup_legacy_edge_containers
sudo docker compose pull
@ -426,6 +440,7 @@ sudo docker compose up -d --remove-orphans
sudo docker compose start || true
sudo docker compose ps
edge_stage certificates
if [ "$enable_letsencrypt" = "true" ]; then
email_args="--register-unsafely-without-email"
if [ -n "$letsencrypt_email" ]; then
@ -479,9 +494,11 @@ if [ "$enable_letsencrypt" = "true" ]; then
check_edge_health -kfsS --connect-timeout 10 --resolve "$server_name:443:127.0.0.1" "https://$server_name/edge-health"
else
sudo systemctl disable --now homelab-edge-renew-certs.timer >/dev/null 2>&1 || true
edge_stage health
check_edge_health -kfsS --connect-timeout 10 \
--resolve "$server_name:443:127.0.0.1" "https://$server_name/edge-health"
fi
edge_stage complete
EOT
]
}

View File

@ -753,7 +753,12 @@ run_tofu_stack() {
adopt_apps_existing_resources
fi
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
tofu_apply_with_kubernetes_retry "${stack}" "${apply_args[@]}"
if ! tofu_apply_with_kubernetes_retry "${stack}" "${apply_args[@]}"; then
if [[ "${stack}" == "bootstrap/edge" ]]; then
edge_remote_failure_report || true
fi
return 1
fi
}
run_tofu_plan_stack() {
@ -8464,6 +8469,20 @@ edge_ssh_args() {
fi
}
edge_remote_failure_report() {
local edge_host="${TF_VAR_edge_ssh_host:-${TF_VAR_edge_host:-${LAB_EDGE_HOST:-}}}"
local edge_user="${TF_VAR_edge_user:-${LAB_EDGE_USER:-ubuntu}}"
if [[ -z "${edge_host}" ]]; then
return 0
fi
edge_ssh_args
echo "Remote edge bootstrap stage report:"
ssh "${EDGE_SSH_ARGS[@]}" "${edge_user}@${edge_host}" \
"sudo cat /tmp/homelab-edge-bootstrap-stage.log 2>/dev/null || true" \
2>/dev/null || echo "Unable to retrieve the remote edge stage report." >&2
}
edge_flush_caches() {
local edge_host="${TF_VAR_edge_ssh_host:-${TF_VAR_edge_host:-${LAB_EDGE_HOST:-}}}"
local edge_user="${TF_VAR_edge_user:-${LAB_EDGE_USER:-ubuntu}}"