Beispiel #1
0
    def _inject_into_repo_files(self, build_dir: BuildDir):
        """Inject repo files into a relative directory inside the build context"""
        host_repos_path = build_dir.path / RELATIVE_REPOS_PATH
        self.log.info("creating directory for yum repos: %s", host_repos_path)
        os.mkdir(host_repos_path)
        allow_repo_dir_in_dockerignore(build_dir.path)

        for repo in self.yum_repos[build_dir.platform]:
            # Update every repo accordingly in a repofile
            # input_buf ---- updated ----> updated_buf
            with StringIO(repo.content.decode()) as input_buf, StringIO(
            ) as updated_buf:
                for line in input_buf:
                    updated_buf.write(line)
                    # Apply sslcacert to every repo in a repofile
                    if line.lstrip().startswith(
                            '[') and self._builder_ca_bundle:
                        updated_buf.write(
                            f'sslcacert=/tmp/{self._ca_bundle_pem}\n')

                yum_repo = YumRepo(repourl=repo.dst_filename,
                                   content=updated_buf.getvalue(),
                                   dst_repos_dir=host_repos_path,
                                   add_hash=False)
                yum_repo.write_content()
    def _inject_into_repo_files(self):
        """Inject repo files into a relative directory inside the build context"""
        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_filename, repo_content in self.workflow.files.items():
            # Update every repo accordingly in a repofile
            # input_buf ---- updated ----> updated_buf
            with StringIO(
                    repo_content) as input_buf, StringIO() as updated_buf:
                for line in input_buf:
                    updated_buf.write(line)
                    # Apply sslcacert to every repo in a repofile
                    if line.lstrip().startswith(
                            '[') and self._builder_ca_bundle:
                        updated_buf.write(
                            f'sslcacert=/tmp/{self._ca_bundle_pem}\n')

                yum_repo = YumRepo(repourl=repo_filename,
                                   content=updated_buf.getvalue(),
                                   dst_repos_dir=host_repos_path,
                                   add_hash=False)
                yum_repo.write_content()
    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
        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,
                               add_hash=False)
            yum_repo.write_content()

        # Find out the USER inherited from the base image
        inspect = self.workflow.builder.base_image_inspect
        inherited_user = ''
        if not self.workflow.builder.base_from_scratch:
            inherited_user = inspect.get(INSPECT_CONFIG).get('User', '')
        df = df_parser(self.workflow.builder.df_path, workflow=self.workflow)
        yum_repos = list(self.workflow.files)
        add_yum_repos_to_dockerfile(yum_repos, df, inherited_user,
                                    self.workflow.builder.base_from_scratch)
        for repo in yum_repos:
            self.log.info("injected yum repo: %s", repo)
Beispiel #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