From 98a09c32f89db8dc662ced8078ec78ce380fc601 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:18:36 +1100 Subject: [PATCH] Add a healthcheck endpoint (#468) The purpose of this endpoint is to respond only with http code 200, to be used by services such as Docker to check if the server is still running. --- build/Dockerfile | 3 +++ .../Controllers/V1.1/HealthCheckController.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gaseous-server/Controllers/V1.1/HealthCheckController.cs diff --git a/build/Dockerfile b/build/Dockerfile index 58959e9..4b0e943 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -32,5 +32,8 @@ ENV INDOCKER=1 WORKDIR /App COPY --from=build-env /App/out . +# Configure healthcheck +HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 CMD curl --fail http://localhost:80/healthCheck || exit 1 + # start gaseous-server ENTRYPOINT ["dotnet", "gaseous-server.dll"] diff --git a/gaseous-server/Controllers/V1.1/HealthCheckController.cs b/gaseous-server/Controllers/V1.1/HealthCheckController.cs new file mode 100644 index 0000000..a3df2f1 --- /dev/null +++ b/gaseous-server/Controllers/V1.1/HealthCheckController.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using Asp.Versioning; + +namespace gaseous_server.Controllers.v1_1 +{ + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("1.1")] + [ApiController] + public class HealthCheckController : ControllerBase + { + [MapToApiVersion("1.1")] + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult Healthcheck() + { + return Ok(); + } + } +} \ No newline at end of file