Runs any given command on the container. Args: command (str): Command to be executed. Returns: Optional[Any]: Response from container or None if error occures.
(self, command: str)
| 258 | return sidecar_config |
| 259 | |
| 260 | def run_command(self, command: str) -> Any | None: |
| 261 | """Runs any given command on the container. |
| 262 | |
| 263 | Args: |
| 264 | command (str): Command to be executed. |
| 265 | |
| 266 | Returns: |
| 267 | Optional[Any]: Response from container or None if error occures. |
| 268 | """ |
| 269 | command = command.upper() |
| 270 | |
| 271 | # Get additional environment variables to pass to the container |
| 272 | additional_env = self._parse_additional_envs() |
| 273 | |
| 274 | container_config = self.client.get_container_run_config( |
| 275 | command=["--command", command], |
| 276 | file_execution_id="", |
| 277 | auto_remove=True, |
| 278 | envs=additional_env, |
| 279 | ) |
| 280 | container = None |
| 281 | |
| 282 | # Run the Docker container |
| 283 | try: |
| 284 | container: ContainerInterface = self.client.run_container(container_config) |
| 285 | for text in container.logs(follow=True): |
| 286 | self.logger.info(f"[{container.name}] - {text}") |
| 287 | if f'"type": "{command}"' in text: |
| 288 | return json.loads(text) |
| 289 | except Exception as e: |
| 290 | self.logger.error( |
| 291 | f"Failed to run docker container: {e}", stack_info=True, exc_info=True |
| 292 | ) |
| 293 | if container: |
| 294 | container.cleanup() |
| 295 | return None |
| 296 | |
| 297 | def _get_container_command( |
| 298 | self, shared_log_dir: str, shared_log_file: str, settings: dict[str, Any] |
no test coverage detected