Skip to content

Instantly share code, notes, and snippets.

@radimih
Last active April 20, 2023 10:53
Show Gist options
  • Save radimih/e16c0e4d1b15f1ee2e77c420e35362ab to your computer and use it in GitHub Desktop.
Save radimih/e16c0e4d1b15f1ee2e77c420e35362ab to your computer and use it in GitHub Desktop.
Spring Boot Actuator based Docker HEALTHCHECK
FROM openjdk:11-jre-slim
EXPOSE 8080
ENV TZ=Europe/Moscow
RUN adduser --system --group --home /opt/app appuser
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl jq \
&& rm -rf /var/lib/apt/lists/*
ARG JAR_FILE=target/*.jar
COPY --chown=appuser:appuser ${JAR_FILE} /opt/app/application.jar
USER appuser
WORKDIR /opt/app
ENTRYPOINT ["java", "-jar", "/opt/app/application.jar"]
HEALTHCHECK --start-period=30s --interval=30s --timeout=3s --retries=3 \
CMD curl --silent --fail --request GET http://localhost:8080/actuator/health \
| jq --exit-status '.status == "UP"' || exit 1
@marcoberri
Copy link

jq have a bug, ad empty response is evalueted to true..

i succeeded in compose file with:

test: curl -m 5 --silent --fail --request GET http://localhost:8080/actuator/health | jq --exit-status -n 'inputs | if has("status") then .status=="UP" else false end' > /dev/null || exit 1

@LeMikaelF
Copy link

LeMikaelF commented Mar 9, 2021

@marcoberri Yes, indeed:

echo '' | jq --exit-status '.status == "UP"'

Doesn't print anything, and exit code is 0. Good catch!

@marcoberri
Copy link

it's work for me!

test : curl -m 5 --silent --fail --request GET http://localhost:8080/actuator/health | jq --exit-status -n 'inputs | if has("status") then .status=="UP" else false end' > /dev/null || exit 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment