added a healthcheck

This commit is contained in:
Kieran Eglin 2024-04-02 11:47:25 -07:00
parent b5d6db4ad2
commit c89511d24d
No known key found for this signature in database
GPG key ID: 193984967FCF432D
4 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,9 @@
defmodule PinchflatWeb.HealthController do
use PinchflatWeb, :controller
def check(conn, _params) do
conn
|> put_status(:ok)
|> json(%{status: "ok"})
end
end

View file

@ -47,6 +47,13 @@ defmodule PinchflatWeb.Router do
get "/media/:uuid/stream", MediaItems.MediaItemController, :stream
end
# No auth or CSRF protection for the health check endpoint
scope "/", PinchflatWeb do
pipe_through :api
get "/healthcheck", HealthController, :check
end
scope "/dev" do
pipe_through :browser

View file

@ -113,5 +113,8 @@ COPY --from=builder /app/_build/${MIX_ENV}/rel/pinchflat ./
# above and adding an entrypoint. See https://github.com/krallin/tini for details
# ENTRYPOINT ["/tini", "--"]
HEALTHCHECK --interval=120s --start-period=10s \
CMD curl --fail http://localhost:${PORT}/healthcheck || exit 1
# Start the app
CMD ["/app/bin/docker_start"]

View file

@ -0,0 +1,10 @@
defmodule PinchflatWeb.HealthControllerTest do
use PinchflatWeb.ConnCase
describe "GET /healthcheck" do
test "returns ok", %{conn: conn} do
conn = get(conn, "/healthcheck")
assert json_response(conn, 200) == %{"status" => "ok"}
end
end
end