From a564822e26d117028d46fdbbea6f4ec18c172194 Mon Sep 17 00:00:00 2001
From: edgd1er <edgd1er@hotmail.com>
Date: Tue, 26 Oct 2021 22:56:47 +0200
Subject: [PATCH] add healthcheck with netcap checking  port

---
 .dockerignore                            |  8 ++++++++
 .gitignore                               |  5 ++++-
 docker/docker-py3-kms-minimal/Dockerfile | 15 +++++++++++----
 docker/docker-py3-kms/Dockerfile         | 10 ++++++----
 4 files changed, 29 insertions(+), 9 deletions(-)
 create mode 100644 .dockerignore

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..54d0d69
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,8 @@
+log/
+.idea
+.github
+*.db
+*.yml
+*.md
+*.sh
+Makefile
diff --git a/.gitignore b/.gitignore
index a149ec6..874f86a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -129,4 +129,7 @@ dmypy.json
 .pyre/
 
 # Helm
-charts/*/*.tgz
\ No newline at end of file
+charts/*/*.tgz
+/.idea/
+docker-compose-*.yml
+*.sh
diff --git a/docker/docker-py3-kms-minimal/Dockerfile b/docker/docker-py3-kms-minimal/Dockerfile
index ecb2668..e4cd8ed 100644
--- a/docker/docker-py3-kms-minimal/Dockerfile
+++ b/docker/docker-py3-kms-minimal/Dockerfile
@@ -24,12 +24,17 @@ RUN apk add --no-cache --update \
 	python3-tkinter \
 	sqlite-libs \
 	py3-pip \
-	tzdata \
+	tzdata  \
+  netcat-openbsd \
 	build-base python3-dev && \
   pip3 install --no-cache peewee tzlocal pytz wheel && \
   apk del git build-base python3-dev && \
+  && addgroup power_users  \
+  && adduser -S py-kms -G users -s /bin/bash \
+  && usermod -a -G power_users py-kms \
+  && chown py-kms:users /home/py-kms \
   # Fix undefined timezone, in case the user did not mount the /etc/localtime
-  ln -sf /usr/share/zoneinfo/UTC /etc/localtime
+  && ln -sf /usr/share/zoneinfo/UTC /etc/localtime
 
 WORKDIR /home/py-kms
 
@@ -37,5 +42,7 @@ EXPOSE ${PORT}/tcp
 
 COPY docker/entrypoint.py /usr/bin/entrypoint.py
 RUN chmod a+x /usr/bin/entrypoint.py
-ENTRYPOINT ["/usr/bin/python3", "/usr/bin/entrypoint.py"]
-#CMD["/usr/bin/start.py"]
+HEALTHCHECK --interval=5m --timeout=3s --start-period=10s --retries=4 CMD echo | nc -t localhost ${PORT} || exit 1
+
+ENTRYPOINT ["/usr/bin/python3", "-u","/usr/bin/entrypoint.py"]
+CMD["/usr/bin/start.py"]
diff --git a/docker/docker-py3-kms/Dockerfile b/docker/docker-py3-kms/Dockerfile
index 629d5b0..c4221ac 100644
--- a/docker/docker-py3-kms/Dockerfile
+++ b/docker/docker-py3-kms/Dockerfile
@@ -16,8 +16,7 @@ ENV LOGFILE STDOUT
 ENV LOGSIZE ""
 ENV TZ America/Chicago
 
-COPY ./py-kms /home/py-kms
-
+COPY py-kms /home/py-kms/
 #hadolint ignore=DL3013,DL3018
 RUN apk add --no-cache --update \
     bash \
@@ -34,6 +33,7 @@ RUN apk add --no-cache --update \
     duplicity \
     tzdata \
     shadow \
+    netcat-openbsd \
     && git clone --branch master --depth 1 https://github.com/coleifer/sqlite-web.git /tmp/sqlite_web \
     && mv /tmp/sqlite_web/sqlite_web /home/  \
     && rm -rf /tmp/sqlite_web \
@@ -54,8 +54,10 @@ RUN chmod 755 /usr/bin/entrypoint.py
 
 WORKDIR /home/py-kms
 #USER py-kms
-EXPOSE 1688/tcp
+EXPOSE ${PORT}/tcp
 EXPOSE 8080
 
-ENTRYPOINT [ "/usr/bin/python3", "/usr/bin/entrypoint.py" ]
+HEALTHCHECK --interval=5m --timeout=3s --start-period=10s --retries=4 CMD echo | nc -t localhost ${PORT} || exit 1
+
+ENTRYPOINT [ "/usr/bin/python3","-u","/usr/bin/entrypoint.py" ]
 CMD ["/usr/bin/start.py"]