def run(self):
        """
        run the plugin
        """
        yum_repos = {
            k: v
            for k, v in self.workflow.files.items()
            if k.startswith(YUM_REPOS_DIR)
        }
        if not yum_repos:
            return
        # absolute path in containers -> relative path within context
        repos_host_cont_mapping = {}
        host_repos_path = os.path.join(self.workflow.builder.df_dir,
                                       RELATIVE_REPOS_PATH)
        self.log.info("creating directory for yum repos: %s", host_repos_path)
        os.mkdir(host_repos_path)

        for repo, repo_content in self.workflow.files.items():
            yum_repo = YumRepo(repourl=repo,
                               content=repo_content,
                               dst_repos_dir=host_repos_path)
            repos_host_cont_mapping[repo] = yum_repo.write_and_return_content()

        # Find out the USER inherited from the base image
        inspect = self.workflow.builder.base_image_inspect
        inherited_user = inspect[INSPECT_CONFIG].get('User', '')
        df = df_parser(self.workflow.builder.df_path, workflow=self.workflow)
        add_yum_repos_to_dockerfile(repos_host_cont_mapping, df,
                                    inherited_user)
示例#2
0
    def run(self):
        """
        run the plugin
        """
        if self.workflow.builder.base_from_scratch and not self.workflow.builder.parent_images:
            self.log.info(
                "Skipping add yum repo by url: unsupported for FROM-scratch images"
            )
            return

        if self.repourls:
            for repourl in self.repourls:
                yumrepo = YumRepo(repourl)
                self.log.info("fetching yum repo from '%s'", yumrepo.repourl)
                try:
                    yumrepo.fetch()
                except Exception as e:
                    msg = "Failed to fetch yum repo {repo}: {exc}".format(
                        repo=yumrepo.repourl, exc=e)
                    raise RuntimeError(msg)
                else:
                    self.log.info("fetched yum repo from '%s'",
                                  yumrepo.repourl)

                if self.inject_proxy:
                    if yumrepo.is_valid():
                        yumrepo.set_proxy_for_all_repos(self.inject_proxy)
                self.workflow.files[yumrepo.dst_filename] = yumrepo.content
                self.log.debug("saving yum repo '%s', length %d",
                               yumrepo.dst_filename, len(yumrepo.content))
示例#3
0
 def extract_base_url(self, repo_url):
     yum_repo = YumRepo(repo_url)
     yum_repo.fetch()
     if not yum_repo.is_valid():
         return []
     repo = yum_repo.config
     return [repo.get(section, 'baseurl') for section in repo.sections()
             if repo.has_option(section, 'baseurl')]
示例#4
0
def test_write_content(tmpdir):
    test_content = 'test_content'
    repo = YumRepo(repourl='http://example.com/a/b/c/myrepo.repo',
                   content=test_content,
                   dst_repos_dir=str(tmpdir))
    repo.write_content()

    with open(os.path.join(str(tmpdir), repo.filename)) as f:
        assert f.read() == test_content
示例#5
0
    def run(self):
        """
        run the plugin
        """
        if self.workflow.builder.base_from_scratch and not self.workflow.builder.parent_images:
            self.log.info(
                "from scratch single stage can't add repos from koji target")
            return

        target_info = self.xmlrpc.getBuildTarget(self.target)
        if target_info is None:
            self.log.error("provided target '%s' doesn't exist", self.target)
            raise RuntimeError("Provided target '%s' doesn't exist!" %
                               self.target)
        tag_info = self.xmlrpc.getTag(target_info['build_tag_name'])

        if not tag_info or 'name' not in tag_info:
            self.log.warning("No tag info was retrieved")
            return

        repo_info = self.xmlrpc.getRepo(tag_info['id'])

        if not repo_info or 'id' not in repo_info:
            self.log.warning("No repo info was retrieved")
            return

        # to use urljoin, we would have to append '/', so let's append everything
        baseurl = self.pathinfo.repo(repo_info['id'],
                                     tag_info['name']) + "/$basearch"

        self.log.info("baseurl = '%s'", baseurl)

        repo = {
            'name': 'atomic-reactor-koji-plugin-%s' % self.target,
            'baseurl': baseurl,
            'enabled': 1,
            'gpgcheck': 0,
        }

        # yum doesn't accept a certificate path in sslcacert - it requires a db with added cert
        # dnf ignores that option completely
        # we have to fall back to sslverify=0 everytime we get https repo from brew so we'll surely
        # be able to pull from it

        if baseurl.startswith("https://"):
            self.log.info("Ignoring certificates in the repo")
            repo['sslverify'] = 0

        if self.proxy:
            self.log.info("Setting yum proxy to %s", self.proxy)
            repo['proxy'] = self.proxy

        path = YumRepo(os.path.join(YUM_REPOS_DIR, self.target)).dst_filename
        self.log.info("yum repo of koji target: '%s'", path)
        self.workflow.files[path] = render_yum_repo(repo, escape_dollars=False)
    def __init__(self, tasker, workflow, repo_name, baseurl):
        """
        constructor

        :param tasker: DockerTasker instance
        :param workflow: DockerBuildWorkflow instance
        :param repo_name: str, name of yum repo
        :param baseurl: str, URL to the repo
        """
        # call parent constructor
        super(AddYumRepoPlugin, self).__init__(tasker, workflow)
        self.repo = YumRepo(baseurl=baseurl, name=repo_name, enabled=True)
 def run(self):
     """
     run the plugin
     """
     self.workflow.repos.setdefault("yum", [])
     repo = {
         'name': self.repo_name,
         'baseurl': self.baseurl,
         'enabled': 1,
         'gpgcheck': 0,
     }
     path = YumRepo(os.path.join(YUM_REPOS_DIR, self.repo_name)).dst_filename
     self.log.info("yum repo of koji target: '%s'", path)
     self.workflow.files[path] = render_yum_repo(repo)
示例#8
0
 def run(self):
     """
     run the plugin
     """
     if self.repourls:
         for repourl in self.repourls:
             yumrepo = YumRepo(repourl)
             yumrepo.fetch()
             self.log.info("fetched repo from '%s'", yumrepo.repourl)
             if self.inject_proxy:
                 if yumrepo.is_valid():
                     yumrepo.set_proxy_for_all_repos(self.inject_proxy)
             self.workflow.files[yumrepo.dst_filename] = yumrepo.content
             self.log.debug("saving repo '%s', length %d",
                            yumrepo.dst_filename, len(yumrepo.content))
    def run(self):
        """
        run the plugin
        """

        source = self._load_source()

        set_flatpak_source_info(self.workflow, source)

        builder = FlatpakBuilder(source, None, None)

        builder.precheck()

        # Create the dockerfile

        module_info = source.base_module

        # We need to enable all the modules other than the platform pseudo-module
        modules_str = ' '.join(builder.get_enable_modules())

        install_packages_str = ' '.join(builder.get_install_packages())

        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=module_info.name,
                                           stream=module_info.stream,
                                           version=module_info.version,
                                           base_image=self.base_image,
                                           modules=modules_str,
                                           packages=install_packages_str,
                                           rpm_qf_args=rpm_qf_args()))

        self.workflow.builder.set_df_path(df_path)

        includepkgs = builder.get_includepkgs()
        includepkgs_path = os.path.join(self.workflow.builder.df_dir,
                                        'atomic-reactor-includepkgs')
        with open(includepkgs_path, 'w') as f:
            f.write('includepkgs = ' + ','.join(includepkgs) + '\n')

        # Create the cleanup script

        cleanupscript = os.path.join(self.workflow.builder.df_dir,
                                     "cleanup.sh")
        with open(cleanupscript, 'w') as f:
            f.write(builder.get_cleanup_script())
        os.chmod(cleanupscript, 0o0755)

        # Add a yum-repository pointing to the compose

        repo_name = 'atomic-reactor-module-{name}-{stream}-{version}'.format(
            name=module_info.name,
            stream=module_info.stream,
            version=module_info.version)

        compose_info = get_compose_info(self.workflow)

        repo = {
            'name': repo_name,
            'baseurl': compose_info.repo_url,
            'enabled': 1,
            'gpgcheck': 0,
        }

        path = YumRepo(os.path.join(YUM_REPOS_DIR, repo_name)).dst_filename
        self.workflow.files[path] = render_yum_repo(repo, escape_dollars=False)

        override_build_kwarg(self.workflow, 'module_compose_id',
                             compose_info.compose_id)
示例#10
0
def test_invalid_config():
    repo = YumRepo('http://example.com/a/b/c/myrepo.repo', 'line noise')
    if (sys.version_info < (3, 0)):
        assert not repo.is_valid()
    else:
        assert True
示例#11
0
def test_add_repo_to_url(repourl, add_hash, pattern):
    repo = YumRepo(repourl, add_hash=add_hash)
    assert repo.repourl == repourl
    assert fnmatch(repo.filename, pattern)
示例#12
0
def test_add_repo_to_url(repourl, filename):
    repo = YumRepo(repourl)
    assert repo.filename == filename