@@ -80,23 +80,35 @@ def service_is_running(service_name, id=False):
80
80
return False
81
81
82
82
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
+ )
83
92
84
93
service_info = {}
85
94
try :
86
95
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
88
97
except subprocess .CalledProcessError :
89
98
return False
90
99
91
100
if not service_info :
92
101
if id :
93
- return False ,- 1
102
+ return False , - 1
94
103
else :
95
104
return False
96
- if service_info [0 ]["State" ] == "running" :
97
- running = True
98
105
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" ]
100
112
101
113
if id :
102
114
return running , container_id
@@ -145,7 +157,6 @@ def configure_script_exists(configure_script: str):
145
157
CONFIGURE_MOLE_PATH , "{}.py" .format (configure_script )
146
158
)
147
159
if not os .path .isfile (configure_script_file ):
148
-
149
160
available_scripts = glob .glob (CONFIGURE_MOLE_PATH + "[!_]*.py" )
150
161
available_scripts = [os .path .splitext (x )[0 ] for x in available_scripts ]
151
162
available_scripts = [os .path .basename (x ) for x in available_scripts ]
0 commit comments