99
1010import docker
1111import yaml
12- from pytest_simcore .helpers .typing_env import EnvVarsDict
1312from tenacity import retry
1413from tenacity .after import after_log
1514from tenacity .stop import stop_after_attempt
@@ -61,17 +60,19 @@ def get_service_published_port(
6160
6261 services = [s for s in client .services .list () if str (s .name ).endswith (service_name )]
6362 if not services :
64- raise RuntimeError (
63+ msg = (
6564 f"Cannot find published port for service '{ service_name } '."
6665 "Probably services still not started."
6766 )
67+ raise RuntimeError (msg )
6868
6969 service_ports = services [0 ].attrs ["Endpoint" ].get ("Ports" )
7070 if not service_ports :
71- raise RuntimeError (
71+ msg = (
7272 f"Cannot find published port for service '{ service_name } ' in endpoint."
7373 "Probably services still not started."
7474 )
75+ raise RuntimeError (msg )
7576
7677 published_port = None
7778 msg = ", " .join (
@@ -89,7 +90,7 @@ def get_service_published_port(
8990
9091 else :
9192 ports_to_look_for : list = (
92- [target_ports ] if isinstance (target_ports , ( int , str ) ) else target_ports
93+ [target_ports ] if isinstance (target_ports , int | str ) else target_ports
9394 )
9495
9596 for target_port in ports_to_look_for :
@@ -100,7 +101,8 @@ def get_service_published_port(
100101 break
101102
102103 if published_port is None :
103- raise RuntimeError (f"Cannot find published port for { target_ports } . Got { msg } " )
104+ msg = f"Cannot find published port for { target_ports } . Got { msg } "
105+ raise RuntimeError (msg )
104106
105107 return str (published_port )
106108
@@ -111,7 +113,6 @@ def run_docker_compose_config(
111113 project_dir : Path ,
112114 env_file_path : Path ,
113115 destination_path : Path | None = None ,
114- additional_envs : EnvVarsDict | None = None ,
115116) -> dict :
116117 """Runs docker compose config to validate and resolve a compose file configuration
117118
@@ -140,13 +141,12 @@ def run_docker_compose_config(
140141 ], "Expected yaml/yml file as destination path"
141142
142143 # SEE https://docs.docker.com/compose/reference/
143-
144- global_options = [
144+ bash_options = [
145145 "-p" ,
146146 str (project_dir ), # Specify an alternate working directory
147147 ]
148148 # https://docs.docker.com/compose/environment-variables/#using-the---env-file--option
149- global_options += [
149+ bash_options += [
150150 "-e" ,
151151 str (env_file_path ), # Custom environment variables
152152 ]
@@ -155,26 +155,22 @@ def run_docker_compose_config(
155155 # - When you use multiple Compose files, all paths in the files are relative to the first configuration file specified with -f.
156156 # You can use the --project-directory option to override this base path.
157157 for docker_compose_path in docker_compose_paths :
158- global_options += [os .path .relpath (docker_compose_path , project_dir )]
158+ bash_options += [os .path .relpath (docker_compose_path , project_dir )]
159159
160160 # SEE https://docs.docker.com/compose/reference/config/
161161 docker_compose_path = scripts_dir / "docker" / "docker-compose-config.bash"
162162 assert docker_compose_path .exists ()
163163
164- cmd = [f"{ docker_compose_path } " ] + global_options
165- print (" " .join (cmd ))
166-
167- process_environment_variables = dict (os .environ )
168- if additional_envs :
169- process_environment_variables |= additional_envs
164+ args = [f"{ docker_compose_path } " , * bash_options ]
165+ print (" " .join (args ))
170166
171167 process = subprocess .run (
172- cmd ,
168+ args ,
173169 shell = False ,
174- check = True ,
175170 cwd = project_dir ,
176171 capture_output = True ,
177- env = process_environment_variables ,
172+ check = True ,
173+ env = None , # NOTE: Do not use since since we pass all necessary env vars via --env-file option of docker compose
178174 )
179175
180176 compose_file_str = process .stdout .decode ("utf-8" )
0 commit comments