def _extract_udocker_zip(supervisor_zip_path) -> None: file_path = "" with ZipFile(supervisor_zip_path) as thezip: for file in thezip.namelist(): if file.endswith("udocker.zip"): file_path = FileUtils.join_paths(FileUtils.get_tmp_dir(), file) thezip.extract(file, FileUtils.get_tmp_dir()) break return file_path
def _extract_handler_code(self) -> None: function_handler_dest = FileUtils.join_paths(self.tmp_payload_folder.name, f"{self.resources_info.get('lambda').get('name')}.py") file_path = "" with ZipFile(self.supervisor_zip_path) as thezip: for file in thezip.namelist(): if file.endswith("function_handler.py"): file_path = FileUtils.join_paths(FileUtils.get_tmp_dir(), file) # Extracts the complete folder structure and the file (cannot avoid) thezip.extract(file, FileUtils.get_tmp_dir()) break if file_path: # Copy only the handler to the payload folder FileUtils.copy_file(file_path, function_handler_dest)
def _create_layer(self) -> None: tmp_zip_path, layer_code_path = _create_tmp_folders() layer_zip_path = FileUtils.join_paths( FileUtils.get_tmp_dir(), f"{self._SUPERVISOR_LAYER_NAME}.zip") parent_folder = _download_supervisor(self.supervisor_version, tmp_zip_path) _copy_supervisor_files(parent_folder, tmp_zip_path, layer_code_path) _copy_extra_files(parent_folder, tmp_zip_path, layer_code_path) _create_layer_zip(layer_zip_path, layer_code_path) self.layer.create(**self._get_supervisor_layer_props(layer_zip_path)) FileUtils.delete_file(layer_zip_path)
def prepare_udocker_image(self): self.save_tmp_udocker_env() image_path = FileUtils.join_paths(FileUtils.get_tmp_dir(), "udocker_image.tar.gz") FileUtils.copy_file(self.aws.lambdaf.image_file, image_path) cmd_out = SysUtils.execute_command_with_msg( self.udocker_exec + ["load", "-i", image_path], cli_msg="Loading image file") # Get the image name from the command output self.aws.lambdaf.image = cmd_out.split('\n')[1] self._create_udocker_container() self.aws.lambdaf.environment['Variables'][ 'IMAGE_ID'] = self.aws.lambdaf.image self._set_udocker_local_registry() self.restore_udocker_env()