From a9ca4a5481b479b8f1586d02b9d26ecfa89af564 Mon Sep 17 00:00:00 2001 From: Jaroslava Fiedlerova Date: Wed, 4 Dec 2024 08:21:44 +0100 Subject: [PATCH] CI: create GetServiceHealth() Rework GetContainerHealth() to work with docker compose and services, instead of using docker and containers. Return health and message about deployment status (used for console and HTML logging) for a given service. --- ci-scripts/cls_containerize.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ci-scripts/cls_containerize.py b/ci-scripts/cls_containerize.py index a9c4b5be08..2b00a5c2ae 100644 --- a/ci-scripts/cls_containerize.py +++ b/ci-scripts/cls_containerize.py @@ -156,17 +156,18 @@ def GetImageName(ssh, svcName, file): else: return ret.stdout.strip() -def GetContainerHealth(ssh, containerName): - if containerName is None: - return False - if 'db_init' in containerName or 'db-init' in containerName: # exits with 0, there cannot be healthy - return True +def GetServiceHealth(ssh, svcName, file): + if svcName is None: + return False, f"Service {svcName} not found in {file}" + image = GetImageName(ssh, svcName, file) + if 'db_init' in svcName or 'db-init' in svcName: # exits with 0, there cannot be healthy + return True, f"Service {svcName} healthy, image {image}" for _ in range(8): - result = ssh.run(f'docker inspect --format="{{{{.State.Health.Status}}}}" {containerName}', silent=True) + result = ssh.run(f"docker compose -f {file} ps --format json {svcName} | jq -r 'if type==\"array\" then .[0].Health else .Health end'", silent=True) if result.stdout == 'healthy': - return True + return True, f"Service {svcName} healthy, image {image}" time.sleep(5) - return False + return False, f"Failed to deploy: service {svcName}" def ExistEnvFilePrint(ssh, wd, prompt='env vars in existing'): ret = ssh.run(f'cat {wd}/.env', silent=True, reportNonZero=False)