From c309ef04f2bdb99f725e3912c4dc45c98f29079f Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 19 Jun 2018 23:52:48 +0200 Subject: [PATCH] Add healthcheck to manuels --- Dockerfile | 2 ++ healthcheck.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 healthcheck.py diff --git a/Dockerfile b/Dockerfile index af8008b..1b2887e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,8 @@ COPY . ./ RUN chmod +x bash/run-prod.sh CMD bash/run-prod.sh +HEALTHCHECK CMD ["pipenv", "run", "python", "healthcheck.py"] + ENV DATABASE_URL postgres://postgresql:postgresql@db:5432/manuels ENV SECRET_KEY '' ENV MAILGUN_ACCESS_KEY '' diff --git a/healthcheck.py b/healthcheck.py new file mode 100644 index 0000000..3fef69b --- /dev/null +++ b/healthcheck.py @@ -0,0 +1,15 @@ +import os +import sys + +import requests + + +def main(): + port = os.getenv('PORT', 8000) + res = requests.get(f'http://localhost:{port}/') + if res.status_code >= 400: + sys.exit(1) + + +if __name__ == '__main__': + main()