From eee83dacf790e708dc5253a76d0f81d8b33b7ffb Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Wed, 22 Nov 2023 08:59:08 +0100 Subject: [PATCH] Add proper health check --- Dockerfile | 9 +++------ healthcheck.sh | 7 +++++++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 healthcheck.sh diff --git a/Dockerfile b/Dockerfile index acc7a62..f0aa8a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,8 @@ COPY --from=builder /app/zurg . # RUN apk add --no-cache upx # RUN upx --brute zurg # Create a health check script that extracts the port from the config file -RUN echo $'#!/bin/sh\n\ -port=$(yaml read /app/config.yml port)\n\ -nc -z localhost $port || exit 1' > /app/healthcheck.sh && \ - chmod +x /app/healthcheck.sh +COPY ./healthcheck.sh /app/healthcheck.sh +RUN chmod +x /app/healthcheck.sh # Final stage FROM alpine:3 @@ -37,8 +35,7 @@ COPY --from=obfuscator /app/healthcheck.sh . COPY config.example.yml /app/config.yml # Install runtime dependencies and configure FUSE -RUN apk add --no-cache fuse3 netcat-openbsd yaml-cpp curl \ - && echo 'user_allow_other' >> /etc/fuse.conf +RUN apk add curl HEALTHCHECK --interval=60s --timeout=60s --start-period=10s --retries=10 CMD /app/healthcheck.sh diff --git a/healthcheck.sh b/healthcheck.sh new file mode 100644 index 0000000..56daf0d --- /dev/null +++ b/healthcheck.sh @@ -0,0 +1,7 @@ +#!/bin/sh +response=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:9999) +if [ "$response" -eq 200 ]; then + exit 0 +else + exit 1 +fi