def sandcastle(self): """initialize Sandcastle lazily""" if self._sandcastle is None: # we import here so that packit does not depend on sandcastle (and thus python-kube) from sandcastle.api import Sandcastle, MappedDir, VolumeSpec self._mapped_dir = MappedDir( local_dir=self.local_project.working_dir, path=self.config.command_handler_work_dir, with_interim_pvc=True, ) pvc_volume_specs = [ VolumeSpec(**vol_spec_dict) for vol_spec_dict in self.config.command_handler_pvc_volume_specs if ( # Do not mount when the env-var is not set "pvc_from_env" not in vol_spec_dict or getenv(vol_spec_dict.get("pvc_from_env"))) and not ( # Do not mount repository cache when it's not used self.config.repository_cache and vol_spec_dict.get( "path") == self.config.repository_cache and not self.local_project.cache.projects_cloned_using_cache) ] self._sandcastle = Sandcastle( image_reference=self.config.command_handler_image_reference, k8s_namespace_name=self.config.command_handler_k8s_namespace, mapped_dir=self._mapped_dir, volume_mounts=pvc_volume_specs, ) logger.debug("running the sandcastle pod") self._sandcastle.run() return self._sandcastle
def run_command(self, command: List[str], return_output: bool = True, env: Optional[Dict] = None): """ Executes command in a sandbox provided by sandcastle. :param command: the command :param return_output: return output from this method if True :param env: dict with env vars to set for the command """ # we import here so that packit does not depend on sandcastle (and thus python-kube) from sandcastle.api import Sandcastle, MappedDir md = MappedDir( local_dir=self.local_project.working_dir, path=self.config.command_handler_work_dir, with_interim_pvc=True, ) sandcastle = Sandcastle( image_reference=self.config.command_handler_image_reference, k8s_namespace_name=self.config.command_handler_k8s_namespace, mapped_dir=md, env_vars=env, ) sandcastle.run() try: logger.info("running command: %s", command) out = sandcastle.exec(command=command) if return_output: return out return None finally: sandcastle.delete_pod()
def run_command( self, command: List[str], return_output: bool = True, env: Optional[Dict] = None, cwd: Union[str, Path] = None, print_live: bool = False, ): """ Executes command in a sandbox provided by sandcastle. :param command: the command :param return_output: return output from this method if True :param env: dict with env vars to set for the command :param cwd: working directory to run command in :param print_live: not used here """ # we import here so that packit does not depend on sandcastle (and thus python-kube) from sandcastle.api import Sandcastle, MappedDir md = MappedDir( local_dir=self.local_project.working_dir, path=cwd or self.config.command_handler_work_dir, with_interim_pvc=True, ) sandcastle = Sandcastle( image_reference=self.config.command_handler_image_reference, k8s_namespace_name=self.config.command_handler_k8s_namespace, mapped_dir=md, env_vars=env, ) sandcastle.run() try: logger.info(f"Running command: {' '.join(command)}") out: str = sandcastle.exec(command=command) finally: sandcastle.delete_pod() logger.info(f"Output of {command!r}:") # out = 'make po-pull\nmake[1]: Entering directory \'/sand for output_line in out.split("\n"): if output_line: logger.info(output_line) if return_output: return out return None
def sandcastle(self): """ initialize Sandcastle lazily """ if self._sandcastle is None: # we import here so that packit does not depend on sandcastle (and thus python-kube) from sandcastle.api import Sandcastle, MappedDir self._mapped_dir = MappedDir( local_dir=self.local_project.working_dir, path=self.config.command_handler_work_dir, with_interim_pvc=True, ) self._sandcastle = Sandcastle( image_reference=self.config.command_handler_image_reference, k8s_namespace_name=self.config.command_handler_k8s_namespace, mapped_dir=self._mapped_dir, ) logger.debug("running the sandcastle pod") self._sandcastle.run() return self._sandcastle
def __init__(self, local_project: LocalProject, config: Config): """ :param local_project: :param config: """ # we import here so that packit does not depend on sandcastle (and thus python-kube) from sandcastle.api import Sandcastle, MappedDir super().__init__(local_project, config) md = MappedDir( local_dir=local_project.working_dir, path=config.command_handler_work_dir, with_interim_pvc=True, ) self.sandcastle = Sandcastle( image_reference=config.command_handler_image_reference, k8s_namespace_name=config.command_handler_k8s_namespace, mapped_dir=md, )