Skip to content

Commit a12ffa3

Browse files
author
Daniel Nguyen (NAVWAR)
committed
Merge branch '31-update-cli-module-to-handle-docker-compose-update' into 'main'
Accommodates output changes from Compose CLI changes. Closes #31 See merge request mole/mole!45
2 parents ff9eb33 + 4f35fa1 commit a12ffa3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

cli/utils.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,35 @@ def service_is_running(service_name, id=False):
8080
return False
8181

8282
cmd = ["docker", "compose", "ps", "--format", "json", service_name]
83+
# Compose CLI aligned with Docker CLI: https://docs.docker.com/compose/release-notes/#2210
84+
host_compose_version = subprocess.check_output(
85+
["docker", "compose", "version", "--short"]
86+
).decode()
87+
88+
compose_docker_cli_aligned = (
89+
int(host_compose_version.split(".")[1]) >= 21
90+
and int(host_compose_version.split(".")[1]) >= 2
91+
)
8392

8493
service_info = {}
8594
try:
8695
output = subprocess.check_output(cmd)
87-
service_info = json.loads(output.rstrip().decode())
96+
service_info = json.loads(output.rstrip().decode()) if output else service_info
8897
except subprocess.CalledProcessError:
8998
return False
9099

91100
if not service_info:
92101
if id:
93-
return False,-1
102+
return False, -1
94103
else:
95104
return False
96-
if service_info[0]["State"] == "running":
97-
running = True
98105

99-
container_id = service_info[0]["ID"]
106+
if not compose_docker_cli_aligned:
107+
service_info = service_info[0]
108+
109+
if service_info["State"] == "running":
110+
running = True
111+
container_id = service_info["ID"]
100112

101113
if id:
102114
return running, container_id
@@ -145,7 +157,6 @@ def configure_script_exists(configure_script: str):
145157
CONFIGURE_MOLE_PATH, "{}.py".format(configure_script)
146158
)
147159
if not os.path.isfile(configure_script_file):
148-
149160
available_scripts = glob.glob(CONFIGURE_MOLE_PATH + "[!_]*.py")
150161
available_scripts = [os.path.splitext(x)[0] for x in available_scripts]
151162
available_scripts = [os.path.basename(x) for x in available_scripts]

0 commit comments

Comments
 (0)