Add Docker Healthcheck to both containers.

Solution for #890
Based on https://github.com/GoogleContainerTools/distroless/issues/183#issuecomment-823181507
This commit is contained in:
GAS85 2024-05-07 20:52:22 +02:00
parent fbb17d66aa
commit 387d52c2fc
2 changed files with 20 additions and 0 deletions

View file

@ -43,6 +43,11 @@ RUN chmod +x /app/api
LABEL Name=homebox Version=0.0.1 LABEL Name=homebox Version=0.0.1
LABEL org.opencontainers.image.source="https://github.com/hay-kot/homebox" LABEL org.opencontainers.image.source="https://github.com/hay-kot/homebox"
EXPOSE 7745 EXPOSE 7745
HEALTHCHECK --interval=30s \
--timeout=5s \
--start-period=5s \
--retries=3 \
CMD [ "/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:7745" ]
WORKDIR /app WORKDIR /app
VOLUME [ "/data" ] VOLUME [ "/data" ]

View file

@ -13,6 +13,7 @@ FROM golang:alpine AS builder
ARG BUILD_TIME ARG BUILD_TIME
ARG COMMIT ARG COMMIT
ARG VERSION ARG VERSION
ARG BUSYBOX_VERSION=1.31.0-i686-uclibc
RUN apk update && \ RUN apk update && \
apk upgrade && \ apk upgrade && \
apk add --update git build-base gcc g++ apk add --update git build-base gcc g++
@ -30,6 +31,14 @@ RUN CGO_ENABLED=0 GOOS=linux go build \
# create a directory so that we can copy it in the next stage # create a directory so that we can copy it in the next stage
mkdir /data mkdir /data
# Downloading Wget
ADD https://busybox.net/downloads/binaries/$BUSYBOX_VERSION/busybox_WGET /wget
RUN chmod a+x /wget
FROM gcr.io/distroless/java
COPY --from=builder /wget /usr/bin/wget
# Production Stage # Production Stage
FROM gcr.io/distroless/static FROM gcr.io/distroless/static
@ -41,10 +50,16 @@ ENV HBOX_STORAGE_SQLITE_URL=/data/homebox.db?_fk=1
# change the ownership to the low-privileged user # change the ownership to the low-privileged user
COPY --from=builder --chown=nonroot /go/bin/api /app COPY --from=builder --chown=nonroot /go/bin/api /app
COPY --from=builder --chown=nonroot /data /data COPY --from=builder --chown=nonroot /data /data
COPY --from=builder --chown=nonroot /wget /usr/bin/wget
LABEL Name=homebox Version=0.0.1 LABEL Name=homebox Version=0.0.1
LABEL org.opencontainers.image.source="https://github.com/hay-kot/homebox" LABEL org.opencontainers.image.source="https://github.com/hay-kot/homebox"
EXPOSE 7745 EXPOSE 7745
HEALTHCHECK --interval=30s \
--timeout=5s \
--start-period=5s \
--retries=3 \
CMD [ "/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:7745" ]
VOLUME [ "/data" ] VOLUME [ "/data" ]
# Drop root and run as low-privileged user # Drop root and run as low-privileged user