Add /health endpoint for Kubernetes probes

Create HealthController that returns 200 OK for health checks.
Route is outside browser pipeline to avoid SSL redirect and
authentication requirements.
This commit is contained in:
Graham McIntire 2026-01-04 10:56:03 -06:00
parent aed28de923
commit 72c260e122
No known key found for this signature in database
3 changed files with 15 additions and 1 deletions

View file

@ -8,7 +8,7 @@ defmodule Towerops.Application do
@impl true
def start(_type, _args) do
# Run migrations on startup (Ecto handles locking for concurrent runs)
unless Application.get_env(:towerops, Towerops.Repo)[:database] == "towerops_test" do
if Application.get_env(:towerops, Towerops.Repo)[:database] != "towerops_test" do
Towerops.Release.migrate()
end

View file

@ -0,0 +1,9 @@
defmodule ToweropsWeb.HealthController do
use ToweropsWeb, :controller
def index(conn, _params) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "ok")
end
end

View file

@ -18,6 +18,11 @@ defmodule ToweropsWeb.Router do
plug :accepts, ["json"]
end
# Health check endpoint for Kubernetes probes (no authentication required)
scope "/", ToweropsWeb do
get "/health", HealthController, :index
end
scope "/", ToweropsWeb do
pipe_through :browser