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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user