def _populate_image_tag(self): timestamp = utcnow().strftime('%Y%m%d%H%M%S') # RNG is seeded once its imported, so in cli calls scratch builds would get unique name. # On brew builders we import osbs once - thus RNG is seeded once and `randrange` # returns the same values throughout the life of the builder. # Before each `randrange` call we should be calling `.seed` to prevent this random.seed() tag_segments = [ self.koji_target or 'none', str(random.randrange(10**(RAND_DIGITS - 1), 10**RAND_DIGITS)), timestamp ] if self.platform: tag_segments.append(self.platform) tag = '-'.join(tag_segments) self.image_tag = '{}/{}:{}'.format(self.user, self.component, tag)
def _populate_image_tag(self): timestamp = utcnow().strftime('%Y%m%d%H%M%S') # RNG is seeded once its imported, so in cli calls scratch builds would get unique name. # On brew builders we import osbs once - thus RNG is seeded once and `randrange` # returns the same values throughout the life of the builder. # Before each `randrange` call we should be calling `.seed` to prevent this random.seed() tag_segments = [ self.koji_target.value or 'none', str(random.randrange(10**(RAND_DIGITS - 1), 10**RAND_DIGITS)), timestamp ] # Support for platform specific tags has only been added in arrangement 4. if self.platform.value and (self.arrangement_version.value or 0) >= 4: tag_segments.append(self.platform.value) tag = '-'.join(tag_segments) self.image_tag.value = '{0}/{1}:{2}'.format(self.user.value, self.component.value, tag)
def set_params(self, git_uri=None, git_ref=None, registry_uri=None, # compatibility name for registry_uris registry_uris=None, registry_secrets=None, user=None, component=None, openshift_uri=None, source_registry_uri=None, yum_repourls=None, use_auth=None, builder_openshift_url=None, build_image=None, build_imagestream=None, proxy=None, sources_command=None, architecture=None, vendor=None, build_host=None, authoritative_registry=None, distribution_scope=None, koji_target=None, kojiroot=None, kojihub=None, koji_certs_secret=None, koji_use_kerberos=None, koji_kerberos_keytab=None, koji_kerberos_principal=None, koji_task_id=None, source_secret=None, # compatibility name for pulp_secret pulp_secret=None, pulp_registry=None, smtp_host=None, smtp_from=None, smtp_email_domain=None, smtp_additional_addresses=None, smtp_error_addresses=None, smtp_to_submitter=None, smtp_to_pkgowner=None, nfs_server_path=None, nfs_dest_dir=None, git_branch=None, base_image=None, name_label=None, builder_build_json_dir=None, registry_api_versions=None, platform=None, platforms=None, release=None, reactor_config_secret=None, client_config_secret=None, token_secrets=None, arrangement_version=None, info_url_format=None, artifacts_allowed_domains=None, **kwargs): self.git_uri.value = git_uri self.git_ref.value = git_ref self.user.value = user self.component.value = component self.proxy.value = proxy # registry_uri is the compatibility name for registry_uris if registry_uri is not None: assert registry_uris is None registry_uris = [registry_uri] self.registry_uris.value = registry_uris or [] self.registry_secrets.value = registry_secrets or [] self.source_registry_uri.value = source_registry_uri self.openshift_uri.value = openshift_uri self.builder_openshift_url.value = builder_openshift_url if not (yum_repourls is None or isinstance(yum_repourls, list)): raise OsbsValidationException("yum_repourls must be a list") self.yum_repourls.value = yum_repourls or [] self.use_auth.value = use_auth if build_imagestream and build_image: raise OsbsValidationException( 'Please only define build_image -OR- build_imagestream, not both') self.build_image.value = build_image or DEFAULT_BUILD_IMAGE self.build_imagestream.value = build_imagestream self.sources_command.value = sources_command self.architecture.value = architecture self.vendor.value = vendor self.build_host.value = build_host self.authoritative_registry.value = authoritative_registry self.distribution_scope.value = distribution_scope self.registry_api_versions.value = registry_api_versions self.koji_target.value = koji_target self.kojiroot.value = kojiroot self.kojihub.value = kojihub self.koji_certs_secret.value = koji_certs_secret self.koji_use_kerberos.value = koji_use_kerberos self.koji_kerberos_principal.value = koji_kerberos_principal self.koji_kerberos_keytab.value = koji_kerberos_keytab self.koji_task_id.value = koji_task_id self.pulp_secret.value = pulp_secret or source_secret self.pulp_registry.value = pulp_registry self.smtp_host.value = smtp_host self.smtp_from.value = smtp_from self.smtp_additional_addresses.value = smtp_additional_addresses self.smtp_error_addresses.value = smtp_error_addresses self.smtp_email_domain.value = smtp_email_domain self.smtp_to_submitter.value = smtp_to_submitter self.smtp_to_pkgowner.value = smtp_to_pkgowner self.nfs_server_path.value = nfs_server_path self.nfs_dest_dir.value = nfs_dest_dir self.git_branch.value = git_branch self.name.value = make_name_from_git(self.git_uri.value, self.git_branch.value) if not base_image: raise OsbsValidationException("base_image must be provided") self.trigger_imagestreamtag.value = get_imagestreamtag_from_image(base_image) self.builder_build_json_dir.value = builder_build_json_dir if not name_label: raise OsbsValidationException("name_label must be provided") self.imagestream_name.value = name_label.replace('/', '-') # The ImageStream should take tags from the source registry # or, if no source registry is set, the first listed registry imagestream_reg = self.source_registry_uri.value if not imagestream_reg: try: imagestream_reg = self.registry_uris.value[0] except IndexError: logger.info("no registries specified, cannot determine imagestream url") imagestream_reg = None if imagestream_reg: self.imagestream_url.value = os.path.join(imagestream_reg.docker_uri, name_label) logger.debug("setting 'imagestream_url' to '%s'", self.imagestream_url.value) insecure = imagestream_reg.uri.startswith('http://') self.imagestream_insecure_registry.value = insecure logger.debug("setting 'imagestream_insecure_registry' to %r", insecure) timestamp = utcnow().strftime('%Y%m%d%H%M%S') self.image_tag.value = "%s/%s:%s-%s-%s" % ( self.user.value, self.component.value, self.koji_target.value or 'none', random.randrange(10**(RAND_DIGITS - 1), 10**RAND_DIGITS), timestamp ) self.platform.value = platform self.platforms.value = platforms self.release.value = release self.reactor_config_secret.value = reactor_config_secret self.client_config_secret.value = client_config_secret self.token_secrets.value = token_secrets or {} self.arrangement_version.value = arrangement_version self.info_url_format.value = info_url_format self.artifacts_allowed_domains.value = artifacts_allowed_domains
def run(self): """ run the plugin """ # source container build if PLUGIN_FETCH_SOURCES_KEY in self.workflow.prebuild_results: source_nvr = self.get_source_build_nvr( scratch=is_scratch_build(self.workflow)) self.log.info("Setting source_build_nvr: %s", source_nvr) self.workflow.koji_source_nvr = source_nvr if self.reserve_build and not is_scratch_build(self.workflow): self.reserve_build_in_koji(source_nvr['name'], source_nvr['version'], source_nvr['release'], None, None, source_build=True) return parser = df_parser(self.workflow.builder.df_path, workflow=self.workflow) dockerfile_labels = parser.labels labels = Labels(dockerfile_labels) missing_labels = {} missing_value = 'missing' empty_value = 'empty' add_timestamp_to_release = ( self.workflow.source.config.autorebuild.get( 'add_timestamp_to_release', False) and is_rebuild(self.workflow)) timestamp = utcnow().strftime('%Y%m%d%H%M%S') component_label = labels.get_name(Labels.LABEL_TYPE_COMPONENT) try: component = dockerfile_labels[component_label] except KeyError: self.log.error("%s label: %s", missing_value, component_label) missing_labels[component_label] = missing_value version_label = labels.get_name(Labels.LABEL_TYPE_VERSION) try: version = dockerfile_labels[version_label] if not version: self.log.error('%s label: %s', empty_value, version_label) missing_labels[version_label] = empty_value except KeyError: self.log.error('%s label: %s', missing_value, version_label) missing_labels[version_label] = missing_value try: release_label, release = labels.get_name_and_value( Labels.LABEL_TYPE_RELEASE) except KeyError: release = None else: if not release: self.log.error('%s label: %s', empty_value, release_label) missing_labels[release_label] = empty_value if missing_labels: raise RuntimeError( 'Required labels are missing or empty or using' ' undefined variables: {}'.format(missing_labels)) # Always set preferred release label - other will be set if old-style # label is present release_label = labels.LABEL_NAMES[Labels.LABEL_TYPE_RELEASE][0] # Reserve build for isolated builds as well (or any build with supplied release) user_provided_release = self.workflow.user_params.get('release') if user_provided_release: if is_scratch_build(self.workflow): return self.check_build_existence_for_explicit_release( component, version, user_provided_release) if self.reserve_build: self.reserve_build_in_koji(component, version, user_provided_release, release_label, dockerfile_labels, user_provided_release=True) return if release: if not self.append: if add_timestamp_to_release: release = '%s.%s' % (release, timestamp) self.log.debug( "autorebuild with add_timestamp_to_release and " "release set explicitly, appending timestamp: %s", timestamp) else: self.log.debug( "release set explicitly so not incrementing") if not is_scratch_build(self.workflow): self.check_build_existence_for_explicit_release( component, version, release) dockerfile_labels[release_label] = release else: return if not release or self.append: self.next_release_general(component, version, release, release_label, dockerfile_labels) if self.reserve_build and not is_scratch_build(self.workflow): self.reserve_build_in_koji(component, version, release, release_label, dockerfile_labels)