Exemplo n.º 1
0
 def convert_package(self) -> types.TaskDict:
     """Build a DEB package from a RPM one."""
     mounts = [
         utils.bind_ro_mount(source=self.sources,
                             target=Path('/rpmbuild/source.rpm')),
         utils.bind_mount(source=constants.PKG_DEB_ROOT,
                          target=Path('/debbuild/result')),
     ]
     builddeb_callable = docker_command.DockerRun(
         command=['/entrypoint.sh', 'rpm2deb'],
         builder=self.builder,
         run_config=docker_command.default_run_config(
             constants.DEBIAN_ENTRYPOINT
         ),
         mounts=mounts
     )
     task = self.basic_task
     task.update({
         'name': self._get_task_name('rpm_to_deb'),
         'actions': [builddeb_callable],
         'doc': 'Build DEB package from RPM for {}'.format(self.name),
         'title': utils.title_with_target1('RPM2DEB'),
         'targets': [self.deb],
     })
     task['file_dep'].append(self.sources)
     return task
Exemplo n.º 2
0
    def build_srpm(self) -> types.TaskDict:
        """Build the SRPM for the package."""
        env = {
            'SPEC': self.spec.name,
            'SRPM': self.srpm.name,
            'SOURCES': ' '.join(source.name for source in self.sources),
            'VERSION': self.version,
        }
        buildsrpm_callable = docker_command.DockerRun(
            command=['/entrypoint.sh', 'buildsrpm'],
            builder=self.builder,
            environment=env,
            tmpfs={'/home/build': '', '/var/tmp': ''},
            mounts=self._get_buildsrpm_mounts(self.srpm.parent),
            read_only=True,
            run_config=docker_command.default_run_config(
                constants.REDHAT_ENTRYPOINT
            )
        )

        task = self.basic_task
        task.update({
            'name': self._get_task_name('srpm'),
            'actions': [buildsrpm_callable],
            'doc': 'Build {}'.format(self.srpm.name),
            'title': utils.title_with_target1('BUILD SRPM'),
            'targets': [self.srpm],
            # Prevent Docker from polluting our output.
            'verbosity': 0,
        })
        task['file_dep'].extend([self.spec])
        task['file_dep'].extend(self.sources)
        task['task_dep'].append(self._get_task_name(self.MKDIR_TASK_NAME,
                                                    with_basename=True))
        return task
Exemplo n.º 3
0
 def build_package(self) -> types.TaskDict:
     """Build DEB packages from source files."""
     mounts = [
         utils.bind_ro_mount(
             source=self.sources, target=Path('/debbuild/pkg-src')
         ),
         utils.bind_ro_mount(
             source=self.debuild_sources, target=Path('/debbuild/pkg-meta')
         ),
         utils.bind_mount(
             source=constants.PKG_DEB_ROOT, target=Path('/debbuild/result')
         ),
     ]
     builddeb_callable = docker_command.DockerRun(
         command=['/entrypoint.sh', 'builddeb'],
         builder=self.builder,
         run_config=docker_command.default_run_config(
             constants.DEBIAN_ENTRYPOINT
         ),
         mounts=mounts,
         environment={
             'VERSION': '{}-{}'.format(self.version, self.build_id)
         },
     )
     task = self.basic_task
     task.update({
         'name': self._get_task_name('build_deb'),
         'actions': [builddeb_callable],
         'doc': 'Build DEB package from sources for {}'.format(self.name),
         'title': utils.title_with_target1('BUILD DEB'),
         'targets': [self.deb],
     })
     task['file_dep'].extend(coreutils.ls_files_rec(self.sources))
     task['file_dep'].extend(coreutils.ls_files_rec(self.debuild_sources))
     return task
Exemplo n.º 4
0
def task__download_deb_packages() -> types.TaskDict:
    """Download Debian packages locally."""
    witness = constants.PKG_DEB_ROOT / '.witness'

    def clean() -> None:
        """Delete downloaded Debian packages."""
        for repository in DEB_REPOSITORIES:
            # Repository with an explicit list of packages are created by a
            # dedicated task that will also handle their cleaning, so we skip
            # them here.
            if repository.packages:
                continue
            coreutils.rm_rf(repository.pkgdir)
        utils.unlink_if_exist(witness)
        constants.REPO_DEB_ROOT.rmdir()

    def mkdirs() -> None:
        """Create directories for the repositories."""
        for repository in DEB_REPOSITORIES:
            repository.pkgdir.mkdir(exist_ok=True)

    mounts = [
        utils.bind_ro_mount(
            source=constants.ROOT / 'packages' / 'debian' /
            'download_packages.py',
            target=Path('/download_packages.py'),
        ),
        utils.bind_mount(source=constants.PKG_DEB_ROOT,
                         target=Path('/repositories')),
    ]
    dl_packages_callable = docker_command.DockerRun(
        command=['/download_packages.py', *DEB_TO_DOWNLOAD],
        builder=builder.DEB_BUILDER,
        mounts=mounts,
        environment={'SALT_VERSION': versions.SALT_VERSION},
        run_config=docker_command.default_run_config(
            constants.DEBIAN_ENTRYPOINT))
    return {
        'title':
        utils.title_with_target1('GET DEB PKGS'),
        'actions': [mkdirs, dl_packages_callable],
        'targets': [constants.PKG_DEB_ROOT / '.witness'],
        'task_dep': [
            '_package_mkdir_deb_root',
            '_package_mkdir_deb_iso_root',
            '_build_builder:{}'.format(builder.DEB_BUILDER.name),
        ],
        'clean': [clean],
        'uptodate': [doit.tools.config_changed(_TO_DOWNLOAD_DEB_CONFIG)],
        # Prevent Docker from polluting our output.
        'verbosity':
        0,
    }
Exemplo n.º 5
0
 def _do_build(self) -> List[types.Action]:
     """Return the actions used to build the image."""
     return [
         docker_command.DockerRun(
             command=['/entrypoint.sh', self.tag],
             builder=builder.GO_BUILDER,
             run_config=docker_command.default_run_config(
                 constants.STORAGE_OPERATOR_ROOT / 'entrypoint.sh'),
             mounts=[
                 utils.bind_mount(target=Path('/storage-operator'),
                                  source=constants.STORAGE_OPERATOR_ROOT),
                 # This container (through operator-sdk) will call `docker
                 # build`, so we need to expose our Docker socket.
                 utils.bind_mount(
                     target=Path('/var/run/docker.sock'),
                     source=Path('/var/run/docker.sock'),
                 )
             ])
     ]
Exemplo n.º 6
0
def task__download_rpm_packages() -> types.TaskDict:
    """Download packages locally."""
    def clean() -> None:
        """Delete cache and repositories on the ISO."""
        coreutils.rm_rf(constants.PKG_RPM_ROOT / 'var')
        for repository in RPM_REPOSITORIES:
            # Repository with an explicit list of packages are created by a
            # dedicated task that will also handle their cleaning, so we skip
            # them here.
            if repository.packages:
                continue
            coreutils.rm_rf(repository.rootdir)

    mounts = [
        utils.bind_mount(source=constants.PKG_RPM_ROOT,
                         target=Path('/install_root')),
        utils.bind_mount(source=constants.REPO_RPM_ROOT,
                         target=Path('/repositories')),
    ]
    dl_packages_callable = docker_command.DockerRun(
        command=['/entrypoint.sh', 'download_packages', *RPM_TO_DOWNLOAD],
        builder=builder.RPM_BUILDER,
        mounts=mounts,
        environment={'RELEASEVER': 7},
        run_config=docker_command.default_run_config(
            constants.REDHAT_ENTRYPOINT))
    return {
        'title':
        utils.title_with_target1('GET RPM PKGS'),
        'actions': [dl_packages_callable],
        'targets': [constants.PKG_RPM_ROOT / 'var'],
        'task_dep': [
            '_package_mkdir_rpm_root',
            '_package_mkdir_rpm_iso_root',
            '_build_builder:{}'.format(builder.RPM_BUILDER.name),
        ],
        'clean': [clean],
        'uptodate': [doit.tools.config_changed(_TO_DOWNLOAD_RPM_CONFIG)],
        # Prevent Docker from polluting our output.
        'verbosity':
        0,
    }
Exemplo n.º 7
0
 def _buildrepo_action(self) -> types.Action:
     """Return the command to run `reprepro` inside a container."""
     mounts = [
         utils.bind_ro_mount(
             source=constants.ROOT/'packages'/'debian'/'distributions',
             target=Path('/distributions')
         ),
         utils.bind_ro_mount(source=self.pkgdir, target=Path('/packages')),
         utils.bind_mount(source=self.rootdir, target=Path('/repository'))
     ]
     buildrepo_callable = docker_command.DockerRun(
         command=['/entrypoint.sh', 'buildrepo', self.fullname],
         builder=self.builder,
         mounts=mounts,
         read_only=True,
         run_config=docker_command.default_run_config(
             constants.DEBIAN_ENTRYPOINT
         )
     )
     return buildrepo_callable
Exemplo n.º 8
0
def task_doc() -> Iterator[types.TaskDict]:
    """Generate the documentation."""
    def clean(target: DocTarget) -> Callable[[], None]:
        """Delete the build sub-directory for the given target."""
        return lambda: coreutils.rm_rf(target.target.parent)

    doc_targets = (DocTarget(name='html',
                             command='html',
                             target=DOC_BUILD_DIR / 'html/index.html'),
                   DocTarget(name='pdf',
                             command='latexpdf',
                             target=DOC_PDF_FILE))
    for target in doc_targets:
        doc_format = target.name.upper()
        run_config = docker_command.default_run_config(constants.ROOT /
                                                       'docs/entrypoint.sh')
        # The builder stores the tox env in /tmp, don't shadow it!
        run_config.pop('tmpfs', None)
        build_doc = docker_command.DockerRun(
            command=['/entrypoint.sh', target.command],
            builder=builder.DOC_BUILDER,
            run_config=run_config,
            mounts=[
                utils.bind_mount(target=Path('/usr/src/metalk8s/'),
                                 source=constants.ROOT)
            ])
        yield {
            'name':
            target.name,
            'title':
            utils.title_with_target1('DOC {}'.format(doc_format)),
            'doc':
            'Generate {} {} documentation'.format(config.PROJECT_NAME,
                                                  doc_format),
            'actions': [build_doc],
            'targets': [target.target],
            'file_dep':
            list(utils.git_ls('docs')),
            'task_dep': ['_build_builder:{}'.format(builder.DOC_BUILDER.name)],
            'clean': [clean(target)],
        }
Exemplo n.º 9
0
    def build_packages(self) -> List[types.TaskDict]:
        """Build the RPMs from SRPMs."""
        tasks = [self._mkdir_repo_root(), self._mkdir_repo_arch()]
        for pkg in self.packages:
            rpm = self.get_rpm_path(pkg)
            env = {
                'RPMS': '{arch}/{rpm}'.format(arch=self.ARCH, rpm=rpm.name),
                'SRPM': pkg.srpm.name,
            }

            buildrpm_callable = docker_command.DockerRun(
                command=['/entrypoint.sh', 'buildrpm'],
                builder=self.builder,
                environment=env,
                mounts=self._get_buildrpm_mounts(pkg.srpm, rpm.parent),
                tmpfs={'/home/build': '', '/var/tmp': ''},
                run_config=docker_command.default_run_config(
                    constants.REDHAT_ENTRYPOINT
                )
            )

            task = self.basic_task
            task.update({
                'name': self._get_task_name('build_rpm/{}'.format(pkg.name)),
                'actions': [buildrpm_callable],
                'doc': 'Build {pkg} RPM for the {repo} repository.'.format(
                    pkg=pkg.name, repo=self.name
                ),
                'title': utils.title_with_target1('BUILD RPM'),
                'targets': [self.get_rpm_path(pkg)],
                # Prevent Docker from polluting our output.
                'verbosity': 0,
            })
            task['file_dep'].append(pkg.srpm)
            task['task_dep'].append(self._get_task_name(MKDIR_ARCH_TASK_NAME,
                                                        with_basename=True))
            task['task_dep'].append(
                '_build_builder:{}'.format(self.builder.name)
            )
            tasks.append(task)
        return tasks
Exemplo n.º 10
0
    def _buildrepo_action(self) -> types.Action:
        """Return the command to run `buildrepo` inside a container."""
        mounts = [
            utils.bind_ro_mount(
                source=self.rootdir, target=Path('/repository')
            ),
            utils.bind_mount(
                source=self.repodata, target=Path('/repository/repodata')
            )
        ]
        buildrepo_callable = docker_command.DockerRun(
            command=['/entrypoint.sh', 'buildrepo'],
            builder=self.builder,
            mounts=mounts,
            read_only=True,
            run_config=docker_command.default_run_config(
                constants.REDHAT_ENTRYPOINT
            )
        )

        return buildrepo_callable
Exemplo n.º 11
0
 def generate_meta(self) -> types.TaskDict:
     """Generate the .meta file for the package."""
     spec_guest_file = Path('/rpmbuild/SPECS', self.spec.name)
     meta_guest_file = Path('/rpmbuild/META', self.meta.name)
     mounts = [
         utils.bind_ro_mount(
             source=self.spec, target=spec_guest_file
         ),
         utils.bind_mount(
             source=self.meta.parent, target=meta_guest_file.parent
         )
     ]
     rpmspec_config = docker_command.default_run_config(
         constants.REDHAT_ENTRYPOINT
     )
     rpmspec_config['read_only'] = True
     buildmeta_callable = docker_command.DockerRun(
         command=['/entrypoint.sh', 'buildmeta'],
         builder=self.builder,
         environment={
             'SPEC': self.spec.name,
             'META': self.meta.name
         },
         run_config=rpmspec_config,
         mounts=mounts
     )
     task = self.basic_task
     task.update({
         'name': self._get_task_name('rpmspec'),
         'actions': [buildmeta_callable],
         'doc': 'Generate {}.meta'.format(self.name),
         'title': utils.title_with_target1('RPMSPEC'),
         'targets': [self.meta],
     })
     task['file_dep'].extend([self.spec])
     task['task_dep'].append(self._get_task_name(self.MKDIR_TASK_NAME,
                                                 with_basename=True))
     return task