3232 docker_rm_command ,
3333 docker_run_command ,
3434)
35+ from app .core .config import settings
3536from app .singleton import Singleton
3637from app .test_engine .logger import test_engine_logger as logger
3738
@@ -49,20 +50,23 @@ async def create_container(
4950 ) -> Container :
5051 container = self .__run_new_container (docker_image_tag , parameters )
5152 await self .__container_ready (container )
52- logger .info ("Container running for " + docker_image_tag )
53+ if settings .ENABLE_CONTAINER_LOGS :
54+ logger .info ("Container running for " + docker_image_tag )
5355
5456 return container
5557
5658 def destroy (self , container : Container ) -> None :
5759 if self .is_running (container ):
5860 # Log equivalent shell command for kill
59- shell_cmd = docker_kill_command (container .name )
60- logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
61+ if settings .ENABLE_CONTAINER_LOGS :
62+ shell_cmd = docker_kill_command (container .name )
63+ logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
6164 container .kill ()
6265
6366 # Log equivalent shell command for remove
64- shell_cmd = docker_rm_command (container .name , force = True )
65- logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
67+ if settings .ENABLE_CONTAINER_LOGS :
68+ shell_cmd = docker_rm_command (container .name , force = True )
69+ logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
6670 container .remove (force = True )
6771
6872 def get_container (self , id_or_name : str ) -> Optional [Container ]:
@@ -109,8 +113,9 @@ def __run_new_container(self, docker_image_tag: str, parameters: Dict) -> Contai
109113 # Create containers
110114 try :
111115 # Log equivalent shell command
112- shell_cmd = docker_run_command (docker_image_tag , parameters )
113- logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
116+ if settings .ENABLE_CONTAINER_LOGS :
117+ shell_cmd = docker_run_command (docker_image_tag , parameters )
118+ logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
114119
115120 return self .__client .containers .run (docker_image_tag , ** parameters )
116121 except DockerException as error :
@@ -151,20 +156,22 @@ def copy_file_from_container(
151156 destination_file_name : str ,
152157 ) -> None :
153158 try :
154- logger .info (
155- "### File Copy: CONTAINER->HOST"
156- f" From Container Path: { str (container_file_path )} "
157- f" To Host Path: { str (destination_path )} /{ destination_file_name } "
158- f" Container Name: { str (container .name )} "
159- )
159+ if settings .ENABLE_CONTAINER_LOGS :
160+ logger .info (
161+ "### File Copy: CONTAINER->HOST"
162+ f" From Container Path: { str (container_file_path )} "
163+ f" To Host Path: { str (destination_path )} /{ destination_file_name } "
164+ f" Container Name: { str (container .name )} "
165+ )
160166
161167 # Log equivalent shell command
162- shell_cmd = docker_cp_from_container_command (
163- container .name ,
164- container_file_path ,
165- destination_path / destination_file_name ,
166- )
167- logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
168+ if settings .ENABLE_CONTAINER_LOGS :
169+ shell_cmd = docker_cp_from_container_command (
170+ container .name ,
171+ container_file_path ,
172+ destination_path / destination_file_name ,
173+ )
174+ logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
168175
169176 stream , _ = container .get_archive (str (container_file_path ))
170177 with open (
@@ -187,18 +194,20 @@ def copy_file_to_container(
187194 destination_container_path : Path ,
188195 ) -> None :
189196 try :
190- logger .info (
191- "### File Copy: HOST->CONTAINER"
192- f" From Host Path: { str (host_file_path )} "
193- f" To Container Path: { destination_container_path } "
194- f" Container Name: { str (container .name )} "
195- )
197+ if settings .ENABLE_CONTAINER_LOGS :
198+ logger .info (
199+ "### File Copy: HOST->CONTAINER"
200+ f" From Host Path: { str (host_file_path )} "
201+ f" To Container Path: { destination_container_path } "
202+ f" Container Name: { str (container .name )} "
203+ )
196204
197205 # Log equivalent shell command
198- shell_cmd = docker_cp_to_container_command (
199- container .name , host_file_path , destination_container_path
200- )
201- logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
206+ if settings .ENABLE_CONTAINER_LOGS :
207+ shell_cmd = docker_cp_to_container_command (
208+ container .name , host_file_path , destination_container_path
209+ )
210+ logger .info (f"{ SHELL_CMD_LOG_PREFIX } { shell_cmd } " )
202211
203212 tar_stream = io .BytesIO ()
204213 with tarfile .open (f"{ host_file_path } " , mode = "r" ) as tar_in :
0 commit comments