From 72c260e122b0329584e067fc8d99b9100b821db0 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 4 Jan 2026 10:56:03 -0600 Subject: [PATCH] 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. --- lib/towerops/application.ex | 2 +- lib/towerops_web/controllers/health_controller.ex | 9 +++++++++ lib/towerops_web/router.ex | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/towerops_web/controllers/health_controller.ex diff --git a/lib/towerops/application.ex b/lib/towerops/application.ex index a7eca3c7..4351d605 100644 --- a/lib/towerops/application.ex +++ b/lib/towerops/application.ex @@ -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 diff --git a/lib/towerops_web/controllers/health_controller.ex b/lib/towerops_web/controllers/health_controller.ex new file mode 100644 index 00000000..3df50ca9 --- /dev/null +++ b/lib/towerops_web/controllers/health_controller.ex @@ -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 diff --git a/lib/towerops_web/router.ex b/lib/towerops_web/router.ex index 5b6719b7..80c59658 100644 --- a/lib/towerops_web/router.ex +++ b/lib/towerops_web/router.ex @@ -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