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.
This commit is contained in:
Jaroslava Fiedlerova
2024-12-05 14:13:18 +01:00
parent e1d06cfef8
commit a9ca4a5481
+9 -8
View File
@@ -156,17 +156,18 @@ def GetImageName(ssh, svcName, file):
else: else:
return ret.stdout.strip() return ret.stdout.strip()
def GetContainerHealth(ssh, containerName): def GetServiceHealth(ssh, svcName, file):
if containerName is None: if svcName is None:
return False return False, f"Service {svcName} not found in {file}"
if 'db_init' in containerName or 'db-init' in containerName: # exits with 0, there cannot be healthy image = GetImageName(ssh, svcName, file)
return True 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): 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': if result.stdout == 'healthy':
return True return True, f"Service {svcName} healthy, image {image}"
time.sleep(5) time.sleep(5)
return False return False, f"Failed to deploy: service {svcName}"
def ExistEnvFilePrint(ssh, wd, prompt='env vars in existing'): def ExistEnvFilePrint(ssh, wd, prompt='env vars in existing'):
ret = ssh.run(f'cat {wd}/.env', silent=True, reportNonZero=False) ret = ssh.run(f'cat {wd}/.env', silent=True, reportNonZero=False)