From db1957edf9bae1ac9046cdb8df7d16b467bf8c29 Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Fri, 28 Jun 2024 13:17:47 +0100 Subject: [PATCH] Move healthcheck to dockerfile Signed-off-by: John Gomersall --- Dockerfile | 2 ++ docker-compose.yml | 3 --- runtime-scripts/after_startup.sh | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 29f3f1d13..0278e6666 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,5 +42,7 @@ FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} COPY --from=keycloak_builder /opt/keycloak/ /opt/keycloak/ +HEALTHCHECK --start-period=60s --interval=1s CMD timeout 1s bash -c 'test -f /tmp/health && :> /dev/tcp/localhost/8080' + ENTRYPOINT [ "sh", "/opt/keycloak/startup.sh" ] diff --git a/docker-compose.yml b/docker-compose.yml index 6d5c9fa6d..71bed45d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,3 @@ services: - KEYCLOAK_BASE_URL - KEYCLOAK_REALM_NAME - KC_SPI_EVENTS_LISTENER_REDIS_EVENT_LISTENER_REDIS_URL=redis://${REDIS_URL}/0 - healthcheck: - test: timeout 10s bash -c ':> /dev/tcp/localhost/8080' - start_interval: 10s \ No newline at end of file diff --git a/runtime-scripts/after_startup.sh b/runtime-scripts/after_startup.sh index 6957c9bf5..712e875c1 100644 --- a/runtime-scripts/after_startup.sh +++ b/runtime-scripts/after_startup.sh @@ -21,6 +21,9 @@ function wait_for_keycloak() { echo "Keycloak is now up and running." } +# Docker healthcheck waits for this file to appear and for port to be open +rm -f /tmp/health + # Waiting for Keycloak to start before proceeding with the configurations. wait_for_keycloak @@ -33,3 +36,5 @@ echo "Calling configure_keycloak" /opt/keycloak/bin/kcadm.sh update realms/open-products-facts -f /opt/keycloak/realm_settings.json /opt/keycloak/bin/kcadm.sh update users/profile -f /opt/keycloak/users_profile.json -r open-products-facts echo "End of configure_keycloak" + +echo Healthy > /tmp/health