def is_image_fbc(image): """ Detect File-Based catalog image. We can have two types of image - SQLite and FBC Those can be distinguished by LABELS. Image with File-Based catalog will have defined this LABEL: "operators.operatorframework.io.index.configs.v1" :param str image: the pull specification of the container image (usually from_image) :return: True if image is FBC type, False otherwise (SQLite) :rtype: bool """ from iib.workers.tasks.utils import get_image_label return bool(get_image_label(image, 'operators.operatorframework.io.index.configs.v1'))
def _get_index_database(from_index, base_dir): """ Get database file from the specified index image and save it locally. :param str from_index: index image to get database file from. :param str base_dir: base directory to which the database file should be saved. :return: path to the copied database file. :rtype: str :raises IIBError: if any podman command fails. """ db_path = get_image_label(from_index, 'operators.operatorframework.io.index.database.v1') if not db_path: raise IIBError('Index image doesn\'t have the label specifying its database location.') _copy_files_from_image(from_index, db_path, base_dir) local_path = os.path.join(base_dir, os.path.basename(db_path)) return local_path
def get_catalog_dir(from_index, base_dir): """ Get file-based catalog directory from the specified index image and save it locally. :param str from_index: index image to get file-based catalog directory from. :param str base_dir: base directory to which the database file should be saved. :return: path to the copied file-based catalog directory. :rtype: str :raises IIBError: if any podman command fails. """ from iib.workers.tasks.build import _copy_files_from_image from iib.workers.tasks.utils import get_image_label log.info("Store file-based catalog directory from %s", from_index) fbc_dir_path = get_image_label(from_index, 'operators.operatorframework.io.index.configs.v1') if not fbc_dir_path: error_msg = f'Index image {from_index} does not contain file-based catalog.' log.error(error_msg) raise IIBError(error_msg) _copy_files_from_image(from_index, fbc_dir_path, base_dir) return os.path.join(base_dir, os.path.basename(fbc_dir_path))
def test_get_image_label(mock_si, label, expected): mock_si.return_value = {'config': {'Labels': {'some_label': 'value'}}} assert utils.get_image_label('some-image:latest', label) == expected