From 8a4189ad7437f540c2dc4d0c3ce8194562436b9c Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 15 Jun 2025 15:11:45 -0500 Subject: [PATCH] distroless --- Dockerfile | 5 ++- app.json | 22 +++++++---- lib/aprs_web/controllers/page_controller.ex | 42 ++++++++++++++++++++- lib/aprs_web/router.ex | 1 + 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 13fdfeb..d78a235 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,7 +48,8 @@ RUN mix compile COPY config/runtime.exs config/ COPY rel rel -RUN mix release +RUN mix release && \ + chmod +x /app/_build/prod/rel/aprs/bin/server /app/_build/prod/rel/aprs/bin/aprs # Final distroless stage FROM ${RUNNER_IMAGE} @@ -78,5 +79,5 @@ LABEL org.opencontainers.image.vendor="APRS.me" \ security.nonroot="true" # Run the server -ENTRYPOINT ["/app/bin/aprs"] +ENTRYPOINT ["/app/bin/server"] EXPOSE $PORT diff --git a/app.json b/app.json index 1d1254b..3128e66 100644 --- a/app.json +++ b/app.json @@ -7,17 +7,23 @@ "postdeploy": "" } }, - "checks": { + "healthchecks": { "web": [ { - "type": "http", - "name": "web-health", - "path": "/health", - "attempts": 3, - "timeout": 5, - "wait": 10, - "initial_delay": 10 + "type": "startup", + "name": "web process check", + "description": "Checking web process startup", + "path": "/ready", + "attempts": 5, + "timeout": 10, + "wait": 5, + "initial_delay": 15 } ] + }, + "formation": { + "web": { + "quantity": 1 + } } } diff --git a/lib/aprs_web/controllers/page_controller.ex b/lib/aprs_web/controllers/page_controller.ex index a0d7536..57ee42d 100644 --- a/lib/aprs_web/controllers/page_controller.ex +++ b/lib/aprs_web/controllers/page_controller.ex @@ -14,6 +14,46 @@ defmodule AprsWeb.PageController do end def health(conn, _params) do - json(conn, %{status: "ok", version: Application.spec(:aprs, :vsn)}) + # Check database connection + db_healthy = + try do + Aprs.Repo.query!("SELECT 1") + true + rescue + _ -> false + end + + # Get application version + version = :aprs |> Application.spec(:vsn) |> List.to_string() + + if db_healthy do + json(conn, %{ + status: "ok", + version: version, + database: "connected", + timestamp: DateTime.utc_now() + }) + else + conn + |> put_status(503) + |> json(%{ + status: "error", + version: version, + database: "disconnected", + timestamp: DateTime.utc_now() + }) + end + end + + def ready(conn, _params) do + # Simple readiness check without database dependency + # This is faster for startup health checks + version = :aprs |> Application.spec(:vsn) |> List.to_string() + + json(conn, %{ + status: "ready", + version: version, + timestamp: DateTime.utc_now() + }) end end diff --git a/lib/aprs_web/router.ex b/lib/aprs_web/router.ex index 737bc67..d2a034d 100644 --- a/lib/aprs_web/router.ex +++ b/lib/aprs_web/router.ex @@ -20,6 +20,7 @@ defmodule AprsWeb.Router do scope "/", AprsWeb do pipe_through :api get "/health", PageController, :health + get "/ready", PageController, :ready end scope "/", AprsWeb do