From adda1d8f232f669f6478484d07a42f2764e83456 Mon Sep 17 00:00:00 2001 From: Valerio Vinciarelli Date: Tue, 5 Mar 2024 18:06:01 +0100 Subject: [PATCH] added healthchecks to containers and fixed deploy --- cmd/methods/createfunctions.go | 20 ++++++ .../docker-compose/docker-compose.yaml | 70 +++++++++++-------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/cmd/methods/createfunctions.go b/cmd/methods/createfunctions.go index 6fb7d5f..58f6811 100644 --- a/cmd/methods/createfunctions.go +++ b/cmd/methods/createfunctions.go @@ -114,6 +114,7 @@ func CreateEnvironment(env string, dockercomposefile string, externalip string, "--env-file="+env, "up", "-d", + "--wait", "--build", "rabbitmq")); err != nil { PrintError("Creation of rabbitmq container failed, cause: " + err.Error()) @@ -121,6 +122,24 @@ func CreateEnvironment(env string, dockercomposefile string, externalip string, } time.Sleep(15 * time.Second) + + PrintTask("Installing metadata catalogue container on the machine") + + if err := ExecuteCommand(exec.Command("docker-compose", + "-f", + dockercomposefile, + "--env-file="+env, + "up", + "-d", + "--wait", + "--build", + "metadatacatalogue")); err != nil { + PrintError("Creation of metadata catalogue container failed, cause: " + err.Error()) + return err + } + + time.Sleep(15 * time.Second) + PrintTask("Installing all remaining containers on the machine") if err := ExecuteCommand(exec.Command("docker-compose", @@ -129,6 +148,7 @@ func CreateEnvironment(env string, dockercomposefile string, externalip string, "--env-file="+env, "up", "-d", + "--wait", "--build")); err != nil { PrintError("Creation of container failed, cause: " + err.Error()) return err diff --git a/cmd/methods/docker-compose/docker-compose.yaml b/cmd/methods/docker-compose/docker-compose.yaml index d169e9f..b641499 100644 --- a/cmd/methods/docker-compose/docker-compose.yaml +++ b/cmd/methods/docker-compose/docker-compose.yaml @@ -49,11 +49,14 @@ services: - SECURITY_KEY=${SECURITY_KEY} - AAI_SERVICE_ENDPOINT=${AAI_SERVICE_ENDPOINT} depends_on: - - rabbitmq - - resources - - backoffice - - ingestor - - externalaccess + resources: + condition: service_healthy + backoffice: + condition: service_healthy + ingestor: + condition: service_healthy + externalaccess: + condition: service_healthy rabbitmq: image: "${MESSAGE_BUS_IMAGE}" container_name: ${PREFIX}rabbitmq @@ -63,6 +66,11 @@ services: - RABBITMQ_DEFAULT_PASS=${BROKER_USERNAME} - RABBITMQ_DEFAULT_USER=${BROKER_PASSWORD} - RABBITMQ_DEFAULT_VHOST=${BROKER_VHOST} + healthcheck: + test: rabbitmq-diagnostics -q ping + interval: 30s + timeout: 10s + retries: 10 networks: - epos_network resources: @@ -93,13 +101,13 @@ services: - CONNECTION_POOL_MIN_SIZE=${CONNECTION_POOL_MIN_SIZE} - CONNECTION_POOL_MAX_SIZE=${CONNECTION_POOL_MAX_SIZE} healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/api/resources-service/v1/actuator/health"] - interval: 1m30s + test: "curl --fail --silent http://localhost:8080/api/resources-service/v1/actuator/health | grep UP || exit 1" + interval: 30s timeout: 10s - retries: 3 - start_period: 40s + retries: 10 depends_on: - - rabbitmq + metadatacatalogue: + condition: service_healthy backoffice: image: "${DOCKER_REGISTRY}/${BACKOFFICE_SERVICE_IMAGE}" container_name: ${PREFIX}backoffice-service @@ -116,13 +124,13 @@ services: - CONNECTION_POOL_MIN_SIZE=${CONNECTION_POOL_MIN_SIZE} - CONNECTION_POOL_MAX_SIZE=${CONNECTION_POOL_MAX_SIZE} healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/api/backoffice-service/v1/actuator/health"] - interval: 1m30s + test: "curl --fail --silent http://localhost:8080/api/backoffice-service/v1/actuator/health | grep UP || exit 1" + interval: 30s timeout: 10s - retries: 3 - start_period: 40s + retries: 10 depends_on: - - rabbitmq + metadatacatalogue: + condition: service_healthy ingestor: image: "${DOCKER_REGISTRY}/${INGESTOR_IMAGE}" container_name: ${PREFIX}ingestor-service @@ -144,13 +152,13 @@ services: - CONNECTION_POOL_MIN_SIZE=${CONNECTION_POOL_MIN_SIZE} - CONNECTION_POOL_MAX_SIZE=${CONNECTION_POOL_MAX_SIZE} healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/api/ingestor-service/v1/actuator/health"] - interval: 1m30s + test: "curl --fail --silent http://localhost:8080/api/ingestor-service/v1/actuator/health | grep UP || exit 1" + interval: 30s timeout: 10s - retries: 3 - start_period: 40s + retries: 10 depends_on: - - rabbitmq + metadatacatalogue: + condition: service_healthy externalaccess: image: "${DOCKER_REGISTRY}/${EXTERNAL_ACCESS_IMAGE}" container_name: ${PREFIX}external-access-service @@ -177,13 +185,15 @@ services: - CONNECTION_POOL_MIN_SIZE=${CONNECTION_POOL_MIN_SIZE} - CONNECTION_POOL_MAX_SIZE=${CONNECTION_POOL_MAX_SIZE} healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/api/external-access-service/v1/actuator/health"] - interval: 1m30s + test: "curl --fail --silent http://localhost:8080/api/external-access-service/v1/actuator/health | grep UP || exit 1" + interval: 30s timeout: 10s - retries: 3 - start_period: 40s + retries: 10 depends_on: - - rabbitmq + metadatacatalogue: + condition: service_healthy + rabbitmq: + condition: service_healthy converter: image: "${DOCKER_REGISTRY}/${CONVERTER_IMAGE}" container_name: ${PREFIX}converter-service @@ -207,7 +217,8 @@ services: - CONNECTION_POOL_MIN_SIZE=${CONNECTION_POOL_MIN_SIZE} - CONNECTION_POOL_MAX_SIZE=${CONNECTION_POOL_MAX_SIZE} depends_on: - - rabbitmq + rabbitmq: + condition: service_healthy metadatacatalogue: restart: always image: "${DOCKER_REGISTRY}/${METADATA_DB_IMAGE}" @@ -218,8 +229,11 @@ services: - POSTGRES_DB=${POSTGRES_DB} volumes: - psqldata:/var/lib/postgresql - depends_on: - - rabbitmq + healthcheck: + test: ["CMD-SHELL","pg_isready"] + interval: 30s + timeout: 10s + retries: 10 networks: - epos_network volumes: