Example #1
0
    def _check_labels(self, repo_info):
        df_parser = repo_info.dockerfile_parser
        labels = utils.Labels(df_parser.labels)

        required_missing = False
        req_labels = {}
        # version label isn't used here, but is required label in Dockerfile
        # and is used and required for atomic reactor
        # if we don't catch error here, it will fail in atomic reactor later
        for label in [utils.Labels.LABEL_TYPE_NAME,
                      utils.Labels.LABEL_TYPE_COMPONENT,
                      utils.Labels.LABEL_TYPE_VERSION]:
            try:
                _, req_labels[label] = labels.get_name_and_value(label)
            except KeyError:
                required_missing = True
                logger.error("required label missing from Dockerfile : %s",
                             labels.get_name(label))

        if required_missing:
            raise OsbsValidationException("required label missing from Dockerfile")

        # Verify the name label meets requirements.
        # It is made up of slash-separated name components.
        #
        # When pulling an image, the first component of the name
        # pulled is interpreted as a registry name if it contains a
        # '.' character, and otherwise the configured registries are
        # queried in turn.
        #
        # Due to this, a name with '.' in its initial component will
        # be awkward to pull from a registry because the registry name
        # will have to be explicitly supplied, e.g. "docker pull
        # foo.bar/baz" will fail because the "foo.bar" registry cannot
        # be contacted.
        #
        # Avoid this awkwardness by forbidding '.' in the initial
        # component of the image name.
        name_components = req_labels[utils.Labels.LABEL_TYPE_NAME].split('/', 1)
        if '.' in name_components[0]:
            raise OsbsValidationException("initial image name component "
                                          "must not contain '.'")

        return req_labels, df_parser.baseimage
Example #2
0
    def _do_create_prod_build(
            self,
            git_uri,
            git_ref,
            git_branch,  # may be None
            user,
            component=None,
            target=None,
            architecture=None,
            yum_repourls=None,
            koji_task_id=None,
            scratch=None,
            platform=None,
            platforms=None,
            release=None,
            inner_template=None,
            outer_template=None,
            customize_conf=None,
            arrangement_version=None,
            **kwargs):
        df_parser = utils.get_df_parser(git_uri,
                                        git_ref,
                                        git_branch=git_branch)
        build_request = self.get_build_request(inner_template=inner_template,
                                               outer_template=outer_template,
                                               customize_conf=customize_conf)
        labels = utils.Labels(df_parser.labels)

        required_missing = False
        req_labels = {}
        # version label isn't used here, but is required label in Dockerfile
        # and is used and required for atomic reactor
        # if we don't catch error here, it will fail in atomic reactor later
        for label in [
                utils.Labels.LABEL_TYPE_NAME,
                utils.Labels.LABEL_TYPE_COMPONENT,
                utils.Labels.LABEL_TYPE_VERSION
        ]:
            try:
                _, req_labels[label] = labels.get_name_and_value(label)
            except KeyError:
                required_missing = True
                logger.error("required label missing from Dockerfile : %s",
                             labels.get_name(label))

        if required_missing:
            raise OsbsValidationException(
                "required label missing from Dockerfile")

        build_request.set_params(
            git_uri=git_uri,
            git_ref=git_ref,
            git_branch=git_branch,
            user=user,
            component=req_labels[utils.Labels.LABEL_TYPE_COMPONENT],
            build_image=self.build_conf.get_build_image(),
            build_imagestream=self.build_conf.get_build_imagestream(),
            base_image=df_parser.baseimage,
            name_label=req_labels[utils.Labels.LABEL_TYPE_NAME],
            registry_uris=self.build_conf.get_registry_uris(),
            registry_secrets=self.build_conf.get_registry_secrets(),
            source_registry_uri=self.build_conf.get_source_registry_uri(),
            registry_api_versions=self.build_conf.get_registry_api_versions(),
            openshift_uri=self.os_conf.get_openshift_base_uri(),
            builder_openshift_url=self.os_conf.get_builder_openshift_url(),
            kojiroot=self.build_conf.get_kojiroot(),
            kojihub=self.build_conf.get_kojihub(),
            sources_command=self.build_conf.get_sources_command(),
            koji_target=target,
            koji_certs_secret=self.build_conf.get_koji_certs_secret(),
            koji_task_id=koji_task_id,
            koji_use_kerberos=self.build_conf.get_koji_use_kerberos(),
            koji_kerberos_keytab=self.build_conf.get_koji_kerberos_keytab(),
            koji_kerberos_principal=self.build_conf.
            get_koji_kerberos_principal(),
            architecture=architecture,
            platform=platform,
            platforms=platforms,
            release=release,
            vendor=self.build_conf.get_vendor(),
            build_host=self.build_conf.get_build_host(),
            authoritative_registry=self.build_conf.get_authoritative_registry(
            ),
            distribution_scope=self.build_conf.get_distribution_scope(),
            yum_repourls=yum_repourls,
            proxy=self.build_conf.get_proxy(),
            pulp_secret=self.build_conf.get_pulp_secret(),
            smtp_host=self.build_conf.get_smtp_host(),
            smtp_from=self.build_conf.get_smtp_from(),
            smtp_additional_addresses=self.build_conf.
            get_smtp_additional_addresses(),
            smtp_error_addresses=self.build_conf.get_smtp_error_addresses(),
            smtp_email_domain=self.build_conf.get_smtp_email_domain(),
            smtp_to_submitter=self.build_conf.get_smtp_to_submitter(),
            smtp_to_pkgowner=self.build_conf.get_smtp_to_pkgowner(),
            use_auth=self.build_conf.get_builder_use_auth(),
            pulp_registry=self.os_conf.get_pulp_registry(),
            nfs_server_path=self.os_conf.get_nfs_server_path(),
            nfs_dest_dir=self.build_conf.get_nfs_destination_dir(),
            builder_build_json_dir=self.build_conf.
            get_builder_build_json_store(),
            scratch=self.build_conf.get_scratch(scratch),
            reactor_config_secret=self.build_conf.get_reactor_config_secret(),
            client_config_secret=self.build_conf.get_client_config_secret(),
            token_secrets=self.build_conf.get_token_secrets(),
            arrangement_version=arrangement_version,
            info_url_format=self.build_conf.get_info_url_format(),
            artifacts_allowed_domains=self.build_conf.
            get_artifacts_allowed_domains(),
            low_priority_node_selector=self.build_conf.
            get_low_priority_node_selector())
        build_request.set_openshift_required_version(
            self.os_conf.get_openshift_required_version())
        if build_request.scratch:
            response = self._create_scratch_build(build_request)
        else:
            response = self._create_build_config_and_build(build_request)
        logger.debug(response.json)
        return response
Example #3
0
    def create_prod_build(self, git_uri, git_ref,
                          git_branch,  # may be None
                          user,
                          component=None,
                          target=None,
                          architecture=None, yum_repourls=None,
                          koji_task_id=None,
                          scratch=None,
                          platform=None,
                          release=None,
                          inner_template=None,
                          outer_template=None,
                          customize_conf=None,
                          **kwargs):
        """
        Create a production build

        :param git_uri: str, URI of git repository
        :param git_ref: str, reference to commit
        :param git_branch: str, branch name (may be None)
        :param user: str, user name
        :param component: str, not used anymore
        :param target: str, koji target
        :param architecture: str, build architecture
        :param yum_repourls: list, URLs for yum repos
        :param koji_task_id: int, koji task ID requesting build
        :param scratch: bool, this is a scratch build
        :param platform: str, the platform name
        :param release: str, the release value to use
        :param inner_template: str, name of inner template for BuildRequest
        :param outer_template: str, name of outer template for BuildRequest
        :param customize_conf: str, name of customization config for BuildRequest
        :return: BuildResponse instance
        """

        df_parser = utils.get_df_parser(git_uri, git_ref, git_branch=git_branch)
        build_request = self.get_build_request(inner_template=inner_template,
                                               outer_template=outer_template,
                                               customize_conf=customize_conf)
        labels = utils.Labels(df_parser.labels)

        required_missing = False
        req_labels = {}
        # version label isn't used here, but is required label in Dockerfile
        # and is used and required for atomic reactor
        # if we don't catch error here, it will fail in atomic reactor later
        for label in [utils.Labels.LABEL_TYPE_NAME,
                      utils.Labels.LABEL_TYPE_COMPONENT,
                      utils.Labels.LABEL_TYPE_VERSION]:
            try:
                _, req_labels[label] = labels.get_name_and_value(label)
            except KeyError:
                required_missing = True
                logger.error("required label missing from Dockerfile : %s",
                             labels.get_name(label))

        if required_missing:
            raise OsbsValidationException("required label missing from Dockerfile")

        build_request.set_params(
            git_uri=git_uri,
            git_ref=git_ref,
            git_branch=git_branch,
            user=user,
            component=req_labels[utils.Labels.LABEL_TYPE_COMPONENT],
            build_image=self.build_conf.get_build_image(),
            build_imagestream=self.build_conf.get_build_imagestream(),
            base_image=df_parser.baseimage,
            name_label=req_labels[utils.Labels.LABEL_TYPE_NAME],
            registry_uris=self.build_conf.get_registry_uris(),
            registry_secrets=self.build_conf.get_registry_secrets(),
            source_registry_uri=self.build_conf.get_source_registry_uri(),
            registry_api_versions=self.build_conf.get_registry_api_versions(),
            openshift_uri=self.os_conf.get_openshift_base_uri(),
            builder_openshift_url=self.os_conf.get_builder_openshift_url(),
            kojiroot=self.build_conf.get_kojiroot(),
            kojihub=self.build_conf.get_kojihub(),
            sources_command=self.build_conf.get_sources_command(),
            koji_target=target,
            koji_certs_secret=self.build_conf.get_koji_certs_secret(),
            koji_task_id=koji_task_id,
            koji_use_kerberos=self.build_conf.get_koji_use_kerberos(),
            koji_kerberos_keytab=self.build_conf.get_koji_kerberos_keytab(),
            koji_kerberos_principal=self.build_conf.get_koji_kerberos_principal(),
            architecture=architecture,
            platform=platform,
            release=release,
            vendor=self.build_conf.get_vendor(),
            build_host=self.build_conf.get_build_host(),
            authoritative_registry=self.build_conf.get_authoritative_registry(),
            distribution_scope=self.build_conf.get_distribution_scope(),
            yum_repourls=yum_repourls,
            proxy=self.build_conf.get_proxy(),
            pulp_secret=self.build_conf.get_pulp_secret(),
            pdc_secret=self.build_conf.get_pdc_secret(),
            pdc_url=self.build_conf.get_pdc_url(),
            smtp_uri=self.build_conf.get_smtp_uri(),
            use_auth=self.build_conf.get_builder_use_auth(),
            pulp_registry=self.os_conf.get_pulp_registry(),
            nfs_server_path=self.os_conf.get_nfs_server_path(),
            nfs_dest_dir=self.build_conf.get_nfs_destination_dir(),
            builder_build_json_dir=self.build_conf.get_builder_build_json_store(),
            scratch=self.build_conf.get_scratch(scratch),
            unique_tag_only=self.build_conf.get_unique_tag_only(),
            reactor_config_secret=self.build_conf.get_reactor_config_secret(),
            client_config_secret=self.build_conf.get_client_config_secret(),
            token_secrets=self.build_conf.get_token_secrets(),
        )
        build_request.set_openshift_required_version(self.os_conf.get_openshift_required_version())
        if build_request.scratch:
            response = self._create_scratch_build(build_request)
        else:
            response = self._create_build_config_and_build(build_request)
        logger.debug(response.json)
        return response