Add a /health endpoint for container health checks #267

Open
opened 2025-12-04 16:58:12 +01:00 by simon · 1 comment
Owner

Problem

Mila has no endpoint that tells a container orchestrator whether the app answers requests. The coop-cloud recipe's health check is commented out (bin/mv eval "IO.puts(:ok)" boots a separate VM every interval and does not check the running app), and the runtime image has neither curl nor wget. The recipe can only check that port 4001 is open, which misses an app that accepts connections but no longer answers.

Proposal

  • A plug in MvWeb.Endpoint, placed before Plug.RequestId and Plug.Telemetry, that answers GET /health (and HEAD) with 200 and the body ok and halts. It runs before the session, the router and the request logger, so a check every 30 s writes nothing to the log.

  • No database query: when the database is down, restarting the app does not help, and Swarm would only put the app into a restart loop. The database has its own health check.

  • No authentication, no information in the response (no version, no commit).

  • Document the endpoint and a check without extra tools in the README (production section):

    healthcheck:
      test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/4001 && printf 'GET /health HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && head -1 <&3 | grep -q ' 200 '"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 5m
    
  • Add the same check to docker-compose.prod.yml.

The coop-cloud recipe sets PHX_SERVER: "true" for the whole container. Then the bin/mv eval steps of docker-entrypoint.sh (seeds, admin user) also start the web server, so port 4001 answers before the app has finished starting. The recipe should drop that variable (bin/server sets it itself); once a release with /health exists, it switches from the port check to the check above.

Acceptance criteria

  • GET /health returns 200 with ok without a session, also when the request has no Host matching PHX_HOST; it writes no request log line.
  • A test pins that /health answers without touching the database (e.g. with the repo checked out but unused) and that the response contains no version information.
  • The check above passes against the production image once the app is up, and fails while the entrypoint still runs migrations and seeds.
  • README and docker-compose.prod.yml show the health check.
## Problem Mila has no endpoint that tells a container orchestrator whether the app answers requests. The coop-cloud recipe's health check is commented out (`bin/mv eval "IO.puts(:ok)"` boots a separate VM every interval and does not check the running app), and the runtime image has neither `curl` nor `wget`. The recipe can only check that port 4001 is open, which misses an app that accepts connections but no longer answers. ## Proposal - A plug in `MvWeb.Endpoint`, placed before `Plug.RequestId` and `Plug.Telemetry`, that answers `GET /health` (and `HEAD`) with `200` and the body `ok` and halts. It runs before the session, the router and the request logger, so a check every 30 s writes nothing to the log. - No database query: when the database is down, restarting the app does not help, and Swarm would only put the app into a restart loop. The database has its own health check. - No authentication, no information in the response (no version, no commit). - Document the endpoint and a check without extra tools in the README (production section): healthcheck: test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/4001 && printf 'GET /health HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && head -1 <&3 | grep -q ' 200 '"] interval: 30s timeout: 5s retries: 3 start_period: 5m - Add the same check to `docker-compose.prod.yml`. ## Related, outside this repository The coop-cloud recipe sets `PHX_SERVER: "true"` for the whole container. Then the `bin/mv eval` steps of `docker-entrypoint.sh` (seeds, admin user) also start the web server, so port 4001 answers before the app has finished starting. The recipe should drop that variable (`bin/server` sets it itself); once a release with `/health` exists, it switches from the port check to the check above. ## Acceptance criteria - `GET /health` returns `200` with `ok` without a session, also when the request has no `Host` matching `PHX_HOST`; it writes no request log line. - A test pins that `/health` answers without touching the database (e.g. with the repo checked out but unused) and that the response contains no version information. - The check above passes against the production image once the app is up, and fails while the entrypoint still runs migrations and seeds. - README and `docker-compose.prod.yml` show the health check.
Author
Owner
No description provided.
simon changed title from Improve compatibility with cloud deployments to Add a /health endpoint for container health checks 2026-11-13 16:38:49 +01:00
Sign in to join this conversation.
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
local-it/mitgliederverwaltung#267
No description provided.