From 5636d924743526570d68d02080c0e82fe392ff38 Mon Sep 17 00:00:00 2001 From: Mirko Milovanovic Date: Sat, 15 Feb 2025 14:12:34 +0100 Subject: [PATCH] feat: add health check and heartbeat endpoint to Docker setup --- Dockerfile | 8 +++++++- utils/PostHandler.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0833ae..c433f14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,16 @@ FROM python:3.13.1-slim-bookworm COPY requirements.txt /app/requirements.txt RUN pip install --no-cache-dir -r /app/requirements.txt +# Install curl +RUN apt-get update && apt-get install -y curl + # Copy the application COPY main.py /app COPY utils/ /app/utils WORKDIR /app # Run the application -CMD ["python", "main.py"] \ No newline at end of file +CMD ["python", "main.py"] + +# Healthcheck +HEALTHCHECK --interval=5s --timeout=10s --retries=5 CMD curl -f http://localhost/heartbeat || exit 1 \ No newline at end of file diff --git a/utils/PostHandler.py b/utils/PostHandler.py index a4e6694..49a1966 100644 --- a/utils/PostHandler.py +++ b/utils/PostHandler.py @@ -24,6 +24,11 @@ class Handler(BaseHTTPRequestHandler): self.wfile.write(b'404 Not Found') def do_GET(self): - self.send_response(404) - self.end_headers() - self.wfile.write(b'404 Not Found') \ No newline at end of file + if self.path == '/heartbeat': + self.send_response(200) + self.end_headers() + self.wfile.write(b'Heartbeat OK') + else: + self.send_response(404) + self.end_headers() + self.wfile.write(b'404 Not Found') \ No newline at end of file