Beispiel #1
0
    def get_repo_urls(self, build):
        """
        Returns list of URLs to ODCS repositories which should be used
        to rebuild the container image for this event.

        :param build: from this build to gather repo URLs.
        :type build: ArtifactBuild
        :return: list of repository URLs.
        :rtype: list
        """
        repo_urls = []

        # Include image_extra_repos if any for this name-version.
        if build.original_nvr:
            parsed_nvr = parse_NVR(build.original_nvr)
            name_version = "%s-%s" % (parsed_nvr["name"], parsed_nvr["version"])
            if name_version in conf.image_extra_repo:
                repo_urls.append(conf.image_extra_repo[name_version])
        return repo_urls
Beispiel #2
0
    def build_image_artifact_build(self, build, repo_urls=None):
        """
        Submits ArtifactBuild of 'image' type to Koji.

        :param build: ArtifactBuild of 'image' type.
        :param list[str] repo_urls: list of YUM repository URLs that will be
            passed to the ``buildContainer`` eventually as a build option.
        :return: Koji build id.
        :rtype: int
        """
        if build.state != ArtifactBuildState.PLANNED.value:
            build.transition(
                ArtifactBuildState.FAILED.value,
                "Container image build is not in PLANNED state.")
            return

        if not build.build_args:
            build.transition(
                ArtifactBuildState.FAILED.value,
                "Container image does not have 'build_args' filled in.")
            return

        if not build.original_nvr:
            build.transition(
                ArtifactBuildState.FAILED.value,
                "Container image does not have original_nvr set.")
            return

        args = json.loads(build.build_args)
        scm_url = "%s/%s#%s" % (conf.git_base_url, args["repository"],
                                args["commit"])
        branch = args["branch"]
        target = args["target"]

        # If this container image depends on another container image
        # we are going to rebuild, use the new NVR of that image
        # as a dependency. Otherwise fallback to build_args, which means
        # the parent is not rebuilt by Freshmaker, but we just take existing
        # parent from Koji.
        if build.dep_on:
            parent = build.dep_on.rebuilt_nvr
        else:
            parent = args["original_parent"]

        # If set to None, then OSBS defaults to using the arches
        # of the build tag associated with the target.
        arches = args.get("arches")

        # Get the list of ODCS compose IDs which should be used to build
        # the image.
        compose_ids = []
        for relation in build.composes:
            compose_ids.append(relation.compose.odcs_compose_id)
        if args.get("renewed_odcs_compose_ids"):
            compose_ids += args["renewed_odcs_compose_ids"]

        for compose_id in compose_ids:
            odcs_compose = self.odcs_get_compose(compose_id)
            if odcs_compose["state"] in [COMPOSE_STATES['wait'],
                                         COMPOSE_STATES['generating']]:
                # In case the ODCS compose is still generating, raise an
                # exception.
                msg = ("Compose %s has not been generated yet. Waiting with "
                       "rebuild." % (str(compose_id)))
                self.log_info(msg)
                raise ODCSComposeNotReady(msg)
            # OSBS can renew a compose if it needs to, so we can just pass
            # it along without further verification for other states.

        rebuilt_nvr = get_rebuilt_nvr(build.type, build.original_nvr)
        if build.rebuilt_nvr is not None:
            self.log_debug(
                "Artifact build %s has rebuilt_nvr %s already. "
                "It will be replaced with a new one %s to be rebuilt.",
                build, build.rebuilt_nvr, rebuilt_nvr)

        build.rebuilt_nvr = rebuilt_nvr
        db.session.commit()

        return self.build_container(
            scm_url, branch, target,
            repo_urls=repo_urls,
            isolated=True,
            release=parse_NVR(build.rebuilt_nvr)["release"],
            koji_parent_build=parent,
            arch_override=arches,
            compose_ids=compose_ids)