From 7e9426ac8c3fea49f99681132595b352197a675f Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Mon, 17 Aug 2020 20:46:53 +0200
Subject: [PATCH] Add healthcheck to the image

This patch adds a healthcheck to the image in order to make sure that
things work properly during runtime and the image restarts when for
whatever reason the connection to the backend DNS container breaks.
---
 Dockerfile | 4 ++++
 README.md  | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/Dockerfile b/Dockerfile
index 04b522e..2b6a27b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,6 +17,10 @@ USER doh
 
 ENTRYPOINT ["entrypoint"]
 
+ENV DOH_HEALTHCHECK_DOMAIN="ci-test.dns.shivering-isles.com"
+
+HEALTHCHECK CMD curl "http://localhost:8053/dns-query?name=${DOH_HEALTHCHECK_DOMAIN}&type=A" | grep "127.0.0.123"
+
 EXPOSE 8053
 
 CMD ["./dns-over-https/doh-server/doh-server"]
diff --git a/README.md b/README.md
index 3ac29a5..ec1f1b6 100644
--- a/README.md
+++ b/README.md
@@ -42,3 +42,10 @@ As alternative for enterprise setups, you can provide a [`policy.json`](https://
 ```
 
 *Don't forget to replace `<your dns host>` with an appropriated value. For example: dns.shivering-isles.com*
+
+Healthcheck
+---
+
+The image contains a health check to make sure no defect container is running. This health check points by default to `ci-test.dns.shivering-isles.com` which is also used for CI in this repository. The domain returns the IP address `127.0.0.123` as A record.
+
+You can configure an own domain using the `DOH_HEALTHCHECK_DOMAIN` environment variable. But make sure this domain returns the mentioned `127.0.0.123` as A record.
-- 
GitLab