Пример #1
0
def test_rpm_qf_args(tags, separator, expected):
    kwargs = {}
    if tags is not None:
        kwargs['tags'] = tags
    if separator is not None:
        kwargs['separator'] = separator
    assert rpm_qf_args(**kwargs) == expected
    def run(self):
        """
        run the plugin
        """

        self._load_source_spec()
        source_spec = get_flatpak_source_spec(self.workflow)
        module_info = ModuleSpec.from_str(source_spec)

        # Load additional information from the flatpak section

        flatpak_yaml = self.workflow.source.config.flatpak

        base_image = flatpak_yaml.get('base_image', self.default_base_image)
        name = flatpak_yaml.get('name', module_info.name)
        component = flatpak_yaml.get('component', module_info.name)

        # Create the dockerfile

        df_path = os.path.join(self.workflow.builder.df_dir, DOCKERFILE_FILENAME)
        with open(df_path, 'w') as fp:
            fp.write(DOCKERFILE_TEMPLATE.format(name=name,
                                                component=component,
                                                cleanupscript=FLATPAK_CLEANUPSCRIPT_FILENAME,
                                                includepkgs=FLATPAK_INCLUDEPKGS_FILENAME,
                                                stream=module_info.stream.replace('-', '_'),
                                                base_image=base_image,
                                                relative_repos_path=RELATIVE_REPOS_PATH,
                                                rpm_qf_args=rpm_qf_args(),
                                                yum_repos_dir=YUM_REPOS_DIR))

        self.workflow.builder.set_df_path(df_path)
Пример #3
0
    def gather_output(self, build_dir: BuildDir) -> Optional[List[RpmComponent]]:
        image = self.workflow.data.tag_conf.get_unique_images_with_platform(build_dir.platform)[0]
        with tempfile.TemporaryDirectory(dir=build_dir.path) as rpmdb_dir:
            self.workflow.imageutil.extract_file_from_image(image, RPMDB_PATH, rpmdb_dir)
            rpmdb_path = os.path.join(rpmdb_dir, RPMDB_DIR_NAME)

            if not os.listdir(rpmdb_path):
                self.log.info('rpmdb directory %s is empty', RPMDB_PATH)
                if self.workflow.data.dockerfile_images.base_from_scratch:
                    return None
                raise RuntimeError(f'rpmdb directory {RPMDB_PATH} is empty')

            rpm_cmd = 'rpm --dbpath {} {}'.format(rpmdb_path, rpm_qf_args())
            try:
                self.log.info('getting rpms from rpmdb: %s', rpm_cmd)
                cmd_output = subprocess.check_output(rpm_cmd,
                                                     shell=True, universal_newlines=True)  # nosec
            except Exception as e:
                self.log.error("Failed to get rpms from rpmdb: %s", e)
                raise e
        output = [line for line in cmd_output.splitlines() if line]

        # gpg-pubkey are autogenerated packages by rpm when you import a gpg key
        # these are of course not signed, let's ignore those by default
        if self.ignore_autogenerated_gpg_keys:
            self.log.debug("ignore rpms 'gpg-pubkey'")
            output = [x for x in output if not x.startswith("gpg-pubkey" + self.sep)]

        return parse_rpm_output(output)
 def _create_dockerfile(build_dir: BuildDir) -> List[Path]:
     content = DOCKERFILE_TEMPLATE.format(name=name,
                                          component=component,
                                          cleanupscript=FLATPAK_CLEANUPSCRIPT_FILENAME,
                                          includepkgs=FLATPAK_INCLUDEPKGS_FILENAME,
                                          stream=module_info.stream.replace('-', '_'),
                                          base_image=base_image,
                                          relative_repos_path=RELATIVE_REPOS_PATH,
                                          rpm_qf_args=rpm_qf_args(),
                                          yum_repos_dir=YUM_REPOS_DIR)
     build_dir.dockerfile_path.write_text(content, "utf-8")
     return [build_dir.dockerfile_path]
Пример #5
0
    def gather_output(self):
        for _ in range(5):
            container_id = self.tasker.run(
                self.image_id,
                command=rpm_qf_args(),
                create_kwargs={"entrypoint": "/bin/rpm", "user": "******"},
                start_kwargs={},
            )
            self._container_ids.append(container_id)
            self.tasker.wait(container_id)
            output = self.tasker.logs(container_id, stream=False)

            if output:
                return output

        raise RuntimeError('Unable to gather list of installed packages in container')
Пример #6
0
    def gather_output_scratch(self):
        container_dict = self.tasker.create_container(self.image_id,
                                                      command=['/bin/bash'])
        container_id = container_dict['Id']
        self._container_ids.append(container_id)

        try:
            bits, _ = self.tasker.get_archive(container_id, RPMDB_PATH)
        except APIError as ex:
            self.log.info('Could not extract rpmdb in %s : %s', RPMDB_PATH, ex)
            return None
        except Exception as ex:
            self.log.info(
                'Get archive failed while extracting rpmdb in %s : %s',
                RPMDB_PATH, ex)
            raise RuntimeError(ex) from ex

        with tempfile.NamedTemporaryFile() as rpmdb_archive:
            for chunk in bits:
                rpmdb_archive.write(chunk)
            rpmdb_archive.flush()
            tar_archive = tarfile.TarFile(rpmdb_archive.name)

        with tempfile.TemporaryDirectory() as rpmdb_dir:
            tar_archive.extractall(rpmdb_dir)

            rpmdb_path = os.path.join(rpmdb_dir, RPMDB_DIR_NAME)
            rpmdb_packages = os.path.join(rpmdb_path, RPMDB_PACKAGES_NAME)

            if not os.path.exists(rpmdb_packages):
                self.log.info('%s does not exist in rpmdb',
                              RPMDB_PACKAGES_NAME)
                return None

            rpm_cmd = 'rpm --dbpath {} {}'.format(rpmdb_path, rpm_qf_args())
            try:
                self.log.info('getting rpms from rpmdb: %s', rpm_cmd)
                rpm_output = subprocess.check_output(
                    rpm_cmd, shell=True, universal_newlines=True)  # nosec
            except Exception as e:
                self.log.error("Failed to get rpms from rpmdb: %s", e)
                raise e

        rpm_output = [line for line in rpm_output.splitlines() if line]
        return rpm_output