Skip to content

Commit

Permalink
Add HealthController and configure Dockerfile for health check
Browse files Browse the repository at this point in the history
  • Loading branch information
0GiS0 committed Feb 4, 2024
1 parent abfb2f4 commit 4bbc756
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Controllers/HealthController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Mvc;

namespace tour_of_heroes_api.Controllers{

[Route("api/[controller]")]
[ApiController]
public class HealthController : ControllerBase
{
// GET: api/Health
[HttpGet]
public IActionResult Get()
{
return Ok("Healthy");
}
}
}
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ WORKDIR /app
EXPOSE 5000

ENV ASPNETCORE_URLS=http://+:5000
ENV OTEL_SERVICE_NAME=tour-of-heroes-api

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
Expand Down Expand Up @@ -36,4 +37,13 @@ RUN dotnet publish "tour-of-heroes-api.csproj" -c Release -o /app/publish -r $(c
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# Install curl
USER root
RUN apt-get update && apt-get install -y curl
USER appuser

HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost:5000/api/health || exit 1

ENTRYPOINT ["dotnet", "tour-of-heroes-api.dll"]

0 comments on commit 4bbc756

Please sign in to comment.