added a healthcheck
This commit is contained in:
parent
b5d6db4ad2
commit
c89511d24d
4 changed files with 29 additions and 0 deletions
9
lib/pinchflat_web/controllers/health_controller.ex
Normal file
9
lib/pinchflat_web/controllers/health_controller.ex
Normal 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
|
||||||
|
|
@ -47,6 +47,13 @@ defmodule PinchflatWeb.Router do
|
||||||
get "/media/:uuid/stream", MediaItems.MediaItemController, :stream
|
get "/media/:uuid/stream", MediaItems.MediaItemController, :stream
|
||||||
end
|
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
|
scope "/dev" do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
# above and adding an entrypoint. See https://github.com/krallin/tini for details
|
||||||
# ENTRYPOINT ["/tini", "--"]
|
# ENTRYPOINT ["/tini", "--"]
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=120s --start-period=10s \
|
||||||
|
CMD curl --fail http://localhost:${PORT}/healthcheck || exit 1
|
||||||
|
|
||||||
# Start the app
|
# Start the app
|
||||||
CMD ["/app/bin/docker_start"]
|
CMD ["/app/bin/docker_start"]
|
||||||
|
|
|
||||||
10
test/pinchflat_web/controllers/health_controller_test.exs
Normal file
10
test/pinchflat_web/controllers/health_controller_test.exs
Normal 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
|
||||||
Loading…
Reference in a new issue