From bfdf1a567eae753146919182ee0c7e7a4ab9ad70 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Wed, 23 Aug 2023 21:00:13 +0100 Subject: [PATCH] Add healthcheck to Dockerfiles Add healthcheck to hotspot. Add healthcheck to graalvm. Add the healthcheck script. --- Dockerfile | 11 ++++++++++- Dockerfile.azul | 11 ++++++++++- Dockerfile.azul.ci | 11 ++++++++++- Dockerfile.ci | 11 ++++++++++- Dockerfile.graalvm-jvm | 11 +++++++++++ Dockerfile.graalvm-jvm.ci | 11 +++++++++++ docker-healthcheck.sh | 6 ++++++ 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 docker-healthcheck.sh diff --git a/Dockerfile b/Dockerfile index 922e831..26146e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,17 @@ RUN --mount=type=cache,target=/root/.gradle/caches/ \ FROM eclipse-temurin:17-jre +RUN --mount=type=cache,target=/var/cache/apt/ \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + WORKDIR /app/ -COPY hotspot-entrypoint.sh / +COPY hotspot-entrypoint.sh docker-healthcheck.sh / COPY --from=build /app/build/libs/piped-1.0-all.jar /app/piped.jar @@ -19,4 +27,5 @@ COPY VERSION . EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /docker-healthcheck.sh ENTRYPOINT ["/hotspot-entrypoint.sh"] diff --git a/Dockerfile.azul b/Dockerfile.azul index b376720..bb9aca4 100644 --- a/Dockerfile.azul +++ b/Dockerfile.azul @@ -9,9 +9,17 @@ RUN --mount=type=cache,target=/root/.gradle/caches/ \ FROM azul/zulu-openjdk:17-jre-headless-latest +RUN --mount=type=cache,target=/var/cache/apt/ \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + WORKDIR /app/ -COPY hotspot-entrypoint.sh / +COPY hotspot-entrypoint.sh docker-healthcheck.sh / COPY --from=build /app/build/libs/piped-1.0-all.jar /app/piped.jar @@ -19,4 +27,5 @@ COPY VERSION . EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /docker-healthcheck.sh ENTRYPOINT ["/hotspot-entrypoint.sh"] diff --git a/Dockerfile.azul.ci b/Dockerfile.azul.ci index 6c7c24d..8c99e26 100644 --- a/Dockerfile.azul.ci +++ b/Dockerfile.azul.ci @@ -1,8 +1,16 @@ FROM azul/zulu-openjdk:17-jre-headless-latest +RUN --mount=type=cache,target=/var/cache/apt/ \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + WORKDIR /app/ -COPY hotspot-entrypoint.sh / +COPY hotspot-entrypoint.sh docker-healthcheck.sh / COPY ./piped.jar /app/piped.jar @@ -10,4 +18,5 @@ COPY VERSION . EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /docker-healthcheck.sh ENTRYPOINT ["/hotspot-entrypoint.sh"] diff --git a/Dockerfile.ci b/Dockerfile.ci index 94acf71..adc4949 100644 --- a/Dockerfile.ci +++ b/Dockerfile.ci @@ -1,8 +1,16 @@ FROM eclipse-temurin:17-jre +RUN --mount=type=cache,target=/var/cache/apt/ \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + WORKDIR /app/ -COPY hotspot-entrypoint.sh / +COPY hotspot-entrypoint.sh docker-healthcheck.sh / COPY ./piped.jar /app/piped.jar @@ -10,4 +18,5 @@ COPY VERSION . EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /docker-healthcheck.sh ENTRYPOINT ["/hotspot-entrypoint.sh"] diff --git a/Dockerfile.graalvm-jvm b/Dockerfile.graalvm-jvm index 1e07549..a085b0d 100644 --- a/Dockerfile.graalvm-jvm +++ b/Dockerfile.graalvm-jvm @@ -17,16 +17,27 @@ RUN jlink \ FROM debian:stable-slim +RUN --mount=type=cache,target=/var/cache/apt/ \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + ENV JAVA_HOME=/opt/java/openjdk ENV PATH "${JAVA_HOME}/bin:${PATH}" COPY --from=build /javaruntime $JAVA_HOME WORKDIR /app/ +COPY docker-healthcheck.sh / + COPY --from=build /app/build/libs/piped-1.0-all.jar /app/piped.jar COPY VERSION . EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /docker-healthcheck.sh CMD java -jar /app/piped.jar diff --git a/Dockerfile.graalvm-jvm.ci b/Dockerfile.graalvm-jvm.ci index fd2d6ce..53be7ba 100644 --- a/Dockerfile.graalvm-jvm.ci +++ b/Dockerfile.graalvm-jvm.ci @@ -10,16 +10,27 @@ RUN jlink \ FROM debian:stable-slim +RUN --mount=type=cache,target=/var/cache/apt/ \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + ENV JAVA_HOME=/opt/java/openjdk ENV PATH "${JAVA_HOME}/bin:${PATH}" COPY --from=build /javaruntime $JAVA_HOME WORKDIR /app/ +COPY docker-healthcheck.sh / + COPY ./piped.jar /app/piped.jar COPY VERSION . EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /docker-healthcheck.sh CMD java -jar /app/piped.jar diff --git a/docker-healthcheck.sh b/docker-healthcheck.sh new file mode 100755 index 0000000..ab55be0 --- /dev/null +++ b/docker-healthcheck.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +# If PORT env var is set, use it, otherwise default to 8080 +PORT=${PORT:-8080} + +curl -f http://localhost:$PORT/healthcheck || exit 1