Skip to content

Commit

Permalink
Accommodates output changes from Compose CLI changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Degnan (NIWC) committed Sep 14, 2023
1 parent ff9eb33 commit 4f35fa1
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,35 @@ def service_is_running(service_name, id=False):
return False

cmd = ["docker", "compose", "ps", "--format", "json", service_name]
# Compose CLI aligned with Docker CLI: https://docs.docker.com/compose/release-notes/#2210
host_compose_version = subprocess.check_output(
["docker", "compose", "version", "--short"]
).decode()

compose_docker_cli_aligned = (
int(host_compose_version.split(".")[1]) >= 21
and int(host_compose_version.split(".")[1]) >= 2
)

service_info = {}
try:
output = subprocess.check_output(cmd)
service_info = json.loads(output.rstrip().decode())
service_info = json.loads(output.rstrip().decode()) if output else service_info
except subprocess.CalledProcessError:
return False

if not service_info:
if id:
return False,-1
return False, -1
else:
return False
if service_info[0]["State"] == "running":
running = True

container_id = service_info[0]["ID"]
if not compose_docker_cli_aligned:
service_info = service_info[0]

if service_info["State"] == "running":
running = True
container_id = service_info["ID"]

if id:
return running, container_id
Expand Down Expand Up @@ -145,7 +157,6 @@ def configure_script_exists(configure_script: str):
CONFIGURE_MOLE_PATH, "{}.py".format(configure_script)
)
if not os.path.isfile(configure_script_file):

available_scripts = glob.glob(CONFIGURE_MOLE_PATH + "[!_]*.py")
available_scripts = [os.path.splitext(x)[0] for x in available_scripts]
available_scripts = [os.path.basename(x) for x in available_scripts]
Expand Down

0 comments on commit 4f35fa1

Please sign in to comment.