From 1e31043fb3c180c6ce8183d027677d1b9dbe0bf3 Mon Sep 17 00:00:00 2001
From: Marco Kilchhofer <marco@kilchhofer.info>
Date: Fri, 22 Jan 2021 08:18:38 +0100
Subject: [PATCH] Improve shutdown behavior (on kubernetes)

---
 docker/Dockerfile.j2           | 10 +++-------
 docker/amd64/Dockerfile        |  3 ++-
 docker/amd64/Dockerfile.alpine |  3 ++-
 docker/arm64/Dockerfile        |  3 ++-
 docker/armv6/Dockerfile        |  3 ++-
 docker/armv7/Dockerfile        |  3 ++-
 docker/armv7/Dockerfile.alpine |  6 +++---
 7 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/docker/Dockerfile.j2 b/docker/Dockerfile.j2
index d247d41c..42ea2209 100644
--- a/docker/Dockerfile.j2
+++ b/docker/Dockerfile.j2
@@ -204,6 +204,7 @@ RUN [ "cross-build-start" ]
 RUN apk add --no-cache \
         openssl \
         curl \
+        dumb-init \
 {%   if "sqlite" in features %}
         sqlite \
 {%   endif %}
@@ -220,14 +221,12 @@ RUN apt-get update && apt-get install -y \
     openssl \
     ca-certificates \
     curl \
+    dumb-init \
     sqlite3 \
     libmariadb-dev-compat \
     libpq5 \
     && rm -rf /var/lib/apt/lists/*
 {% endif %}
-{% if "alpine" in target_file and "armv7" in target_file %}
-RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/community catatonit
-{% endif %}
 
 RUN mkdir /data
 {% if "amd64" not in target_file %}
@@ -256,8 +255,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
-{% if "alpine" in target_file and "armv7" in target_file %}
-CMD ["catatonit", "/start.sh"]
-{% else %}
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 CMD ["/start.sh"]
-{% endif %}
diff --git a/docker/amd64/Dockerfile b/docker/amd64/Dockerfile
index 75ee4dde..0d57ce48 100644
--- a/docker/amd64/Dockerfile
+++ b/docker/amd64/Dockerfile
@@ -78,6 +78,7 @@ RUN apt-get update && apt-get install -y \
     openssl \
     ca-certificates \
     curl \
+    dumb-init \
     sqlite3 \
     libmariadb-dev-compat \
     libpq5 \
@@ -101,5 +102,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 CMD ["/start.sh"]
-
diff --git a/docker/amd64/Dockerfile.alpine b/docker/amd64/Dockerfile.alpine
index 3ede25b5..3831c35a 100644
--- a/docker/amd64/Dockerfile.alpine
+++ b/docker/amd64/Dockerfile.alpine
@@ -74,6 +74,7 @@ ENV SSL_CERT_DIR=/etc/ssl/certs
 RUN apk add --no-cache \
         openssl \
         curl \
+        dumb-init \
         sqlite \
         postgresql-libs \
         ca-certificates
@@ -96,5 +97,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 CMD ["/start.sh"]
-
diff --git a/docker/arm64/Dockerfile b/docker/arm64/Dockerfile
index 6a7c0bb1..f1cb1625 100644
--- a/docker/arm64/Dockerfile
+++ b/docker/arm64/Dockerfile
@@ -121,6 +121,7 @@ RUN apt-get update && apt-get install -y \
     openssl \
     ca-certificates \
     curl \
+    dumb-init \
     sqlite3 \
     libmariadb-dev-compat \
     libpq5 \
@@ -147,5 +148,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 CMD ["/start.sh"]
-
diff --git a/docker/armv6/Dockerfile b/docker/armv6/Dockerfile
index 33c74f57..fd859988 100644
--- a/docker/armv6/Dockerfile
+++ b/docker/armv6/Dockerfile
@@ -121,6 +121,7 @@ RUN apt-get update && apt-get install -y \
     openssl \
     ca-certificates \
     curl \
+    dumb-init \
     sqlite3 \
     libmariadb-dev-compat \
     libpq5 \
@@ -147,5 +148,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 CMD ["/start.sh"]
-
diff --git a/docker/armv7/Dockerfile b/docker/armv7/Dockerfile
index 65827f29..bdd21c50 100644
--- a/docker/armv7/Dockerfile
+++ b/docker/armv7/Dockerfile
@@ -121,6 +121,7 @@ RUN apt-get update && apt-get install -y \
     openssl \
     ca-certificates \
     curl \
+    dumb-init \
     sqlite3 \
     libmariadb-dev-compat \
     libpq5 \
@@ -147,5 +148,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 CMD ["/start.sh"]
-
diff --git a/docker/armv7/Dockerfile.alpine b/docker/armv7/Dockerfile.alpine
index 047ff966..3ac38ce6 100644
--- a/docker/armv7/Dockerfile.alpine
+++ b/docker/armv7/Dockerfile.alpine
@@ -77,9 +77,9 @@ RUN [ "cross-build-start" ]
 RUN apk add --no-cache \
         openssl \
         curl \
+        dumb-init \
         sqlite \
         ca-certificates
-RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/community catatonit
 
 RUN mkdir /data
 
@@ -102,5 +102,5 @@ HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
 
 # Configures the startup!
 WORKDIR /
-CMD ["catatonit", "/start.sh"]
-
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
+CMD ["/start.sh"]