0.28.4 — nomos healthcheck via binary subcommand (distroless has no wget)
The nomos runtime image is gcr.io/distroless/static (no shell/wget), so the wget-based healthcheck (D5) could never run — nomos showed docker-unhealthy despite serving /healthz fine. Add a 'nomos healthcheck' subcommand that self-probes NOMOS_LISTEN/healthz (exit 0 on 200), and point the compose healthcheck at ["/nomos", "healthcheck"].
This commit is contained in:
@@ -183,8 +183,30 @@ func main() {
|
|||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
slog.Info("nomos: shutting down")
|
slog.Info("nomos: shutting down")
|
||||||
srv.Shutdown(context.Background())
|
srv.Shutdown(context.Background())
|
||||||
clientPool.closeAll()
|
clientPool.closeAll()
|
||||||
|
|
||||||
|
case "healthcheck":
|
||||||
|
// Self-probe for Docker healthcheck. The nomos runtime image is
|
||||||
|
// distroless (no shell/wget), so the container can't run wget — the
|
||||||
|
// binary probes its own /healthz instead. Exit 0 on 200, 1 otherwise.
|
||||||
|
addr := os.Getenv("NOMOS_LISTEN")
|
||||||
|
if addr == "" {
|
||||||
|
addr = ":8092"
|
||||||
|
}
|
||||||
|
host := addr
|
||||||
|
if strings.HasPrefix(host, ":") {
|
||||||
|
host = "127.0.0.1" + host
|
||||||
|
}
|
||||||
|
client := &http.Client{Timeout: 3 * time.Second}
|
||||||
|
resp, err := client.Get("http://" + strings.TrimPrefix(host, "http://") + "/healthz")
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "unknown command: %s\n", os.Args[1])
|
fmt.Fprintf(os.Stderr, "unknown command: %s\n", os.Args[1])
|
||||||
|
|||||||
@@ -233,8 +233,10 @@ services:
|
|||||||
stop_grace_period: 10s
|
stop_grace_period: 10s
|
||||||
mem_limit: 512m
|
mem_limit: 512m
|
||||||
cpus: 1.0
|
cpus: 1.0
|
||||||
|
# nomos runs on a distroless image (no shell/wget), so the healthcheck
|
||||||
|
# uses the binary's own `healthcheck` subcommand to self-probe /healthz.
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:8092/healthz"]
|
test: ["CMD", "/nomos", "healthcheck"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|||||||
Reference in New Issue
Block a user