From b8d801a3641757f53fc6bc4811b4d62e03598341 Mon Sep 17 00:00:00 2001
From: Jan Hartig <jan.hartig@ptb.de>
Date: Mon, 21 Aug 2023 16:41:59 +0200
Subject: [PATCH] Add healthcheck

---
 Dockerfile | 3 +++
 routes.py  | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 78eca95..9a0ac4a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -51,6 +51,9 @@ RUN pip install --upgrade pip && \
 # define the port number the container should expose
 EXPOSE 8000
 
+HEALTHCHECK --interval=10s --timeout=3s \
+  CMD curl -s -o /dev/null -f http://localhost:8000/health || exit 1
+
 # upload folder
 VOLUME /opt/app/uploads
 
diff --git a/routes.py b/routes.py
index 1167e81..389deac 100644
--- a/routes.py
+++ b/routes.py
@@ -73,7 +73,7 @@ def upload(language: str):
             return process_file()
         else:
             if form.email.data:
-                form.email.data = form.email.data[:-len(current_app.config["MAIL_DOMAIN"])]
+                form.email.data = form.email.data[: -len(current_app.config["MAIL_DOMAIN"])]
 
     if language != current_app.config["DEFAULT_LANGUAGE"]:
         form.email.label.text = current_app.config["LOCALISATIONS"]["email"]["label"][language]
@@ -94,3 +94,8 @@ def set_language(language):
         abort(404)
 
     request.language = language
+
+
+@current_app.route("/health")
+def health():
+    return "", 204
-- 
GitLab