def test_registry_uris_param_v2(self): spec = CommonSpec() spec.set_params(registry_uris=['http://registry.example.com:5000/v2'], user=TEST_USER) registry = spec.registry_uris.value[0] assert registry.uri == 'http://registry.example.com:5000' assert registry.docker_uri == 'registry.example.com:5000' assert registry.version == 'v2'
class CommonBuild(BuildRequest): def __init__(self, build_json_store): """ :param build_json_store: str, path to directory with JSON build files """ super(CommonBuild, self).__init__(build_json_store) self.spec = CommonSpec() def set_params(self, **kwargs): """ set parameters according to specification these parameters are accepted: :param git_uri: str, URL of source git repository :param git_ref: str, what git tree to build (default: master) :param registry_uri: str, URL of docker registry where built image is pushed :param user: str, user part of resulting image name :param component: str, component part of the image name :param openshift_uri: str, URL of openshift instance for the build :param yum_repourls: list of str, URLs to yum repo files to include :param metadata_plugin_use_auth: bool, use auth when posting metadata from dock? """ logger.debug("setting params '%s' for %s", kwargs, self.spec) self.spec.set_params(**kwargs) def render(self): # !IMPORTANT! can't be too long: https://github.com/openshift/origin/issues/733 self.template['metadata']['name'] = self.spec.name.value if self._resource_limits is not None: resources = self.template['parameters'].get('resources', {}) limits = resources.get('limits', {}) limits.update(self._resource_limits) resources['limits'] = limits self.template['parameters']['resources'] = resources self.template['parameters']['source']['git']['uri'] = self.spec.git_uri.value self.template['parameters']['source']['git']['ref'] = self.spec.git_ref.value self.template['parameters']['output']['registry'] = self.spec.registry_uri.value if (self.spec.yum_repourls.value is not None and self.dj.dock_json_has_plugin_conf('prebuild_plugins', "add_yum_repo_by_url")): self.dj.dock_json_set_arg('prebuild_plugins', "add_yum_repo_by_url", "repourls", self.spec.yum_repourls.value) if self.spec.metadata_plugin_use_auth.value is not None: self.dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "use_auth", self.spec.metadata_plugin_use_auth.value) def validate_input(self): self.spec.validate()
def __init__(self, build_json_store): """ :param build_json_store: str, path to directory with JSON build files """ super(CommonBuild, self).__init__(build_json_store) self.spec = CommonSpec()
class CommonBuild(BuildRequest): def __init__(self, build_json_store): """ :param build_json_store: str, path to directory with JSON build files """ super(CommonBuild, self).__init__(build_json_store) self.spec = CommonSpec() def set_params(self, **kwargs): """ set parameters according to specification these parameters are accepted: :param git_uri: str, URL of source git repository :param git_ref: str, what git tree to build (default: master) :param registry_uri: str, URL of docker registry where built image is pushed :param user: str, user part of resulting image name :param component: str, component part of the image name :param openshift_uri: str, URL of openshift instance for the build :param yum_repourls: list of str, URLs to yum repo files to include :param use_auth: bool, use auth from atomic-reactor? """ logger.debug("setting params '%s' for %s", kwargs, self.spec) self.spec.set_params(**kwargs) def render(self): # !IMPORTANT! can't be too long: https://github.com/openshift/origin/issues/733 self.template['metadata']['name'] = self.spec.name.value if self._resource_limits is not None: resources = self.template['spec'].get('resources', {}) limits = resources.get('limits', {}) limits.update(self._resource_limits) resources['limits'] = limits self.template['spec']['resources'] = resources self.template['spec']['source']['git']['uri'] = self.spec.git_uri.value self.template['spec']['source']['git']['ref'] = self.spec.git_ref.value tag_with_registry = self.spec.registry_uri.value + "/" + self.spec.image_tag.value self.template['spec']['output']['to']['name'] = tag_with_registry if 'triggers' in self.template['spec']: self.template['spec']['triggers']\ [0]['imageChange']['from']['name'] = self.spec.trigger_imagestreamtag.value if (self.spec.yum_repourls.value is not None and self.dj.dock_json_has_plugin_conf('prebuild_plugins', "add_yum_repo_by_url")): self.dj.dock_json_set_arg('prebuild_plugins', "add_yum_repo_by_url", "repourls", self.spec.yum_repourls.value) if self.dj.dock_json_has_plugin_conf('prebuild_plugins', 'check_and_set_rebuild'): self.dj.dock_json_set_arg('prebuild_plugins', 'check_and_set_rebuild', 'url', self.spec.openshift_uri.value) if self.spec.use_auth.value is not None: self.dj.dock_json_set_arg('prebuild_plugins', 'check_and_set_rebuild', 'use_auth', self.spec.use_auth.value) if self.spec.use_auth.value is not None: try: self.dj.dock_json_set_arg('exit_plugins', "store_metadata_in_osv3", "use_auth", self.spec.use_auth.value) except RuntimeError: # For compatibility with older osbs.conf files self.dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "use_auth", self.spec.use_auth.value) # For Origin 1.0.6 we'll use the 'secrets' array; for earlier # versions we'll just use 'sourceSecret' if self._openshift_required_version < [1, 0, 6]: if 'secrets' in self.template['spec']['strategy']['customStrategy']: del self.template['spec']['strategy']['customStrategy']['secrets'] else: if 'sourceSecret' in self.template['spec']['source']: del self.template['spec']['source']['sourceSecret'] def validate_input(self): self.spec.validate()
class CommonBuild(BuildRequest): def __init__(self, build_json_store): """ :param build_json_store: str, path to directory with JSON build files """ super(CommonBuild, self).__init__(build_json_store) self.spec = CommonSpec() def set_params(self, **kwargs): """ set parameters according to specification these parameters are accepted: :param git_uri: str, URL of source git repository :param git_ref: str, what git tree to build (default: master) :param registry_uris: list, URI of docker registry where built image is pushed (str) :param source_registry_uri: str, URI of docker registry from which image is pulled :param user: str, user part of resulting image name :param component: str, component part of the image name :param openshift_uri: str, URL of openshift instance for the build :param builder_openshift_url: str, url of OpenShift where builder will connect :param yum_repourls: list of str, URLs to yum repo files to include :param use_auth: bool, use auth from atomic-reactor? """ logger.debug("setting params '%s' for %s", kwargs, self.spec) self.spec.set_params(**kwargs) def render_resource_limits(self): if self._resource_limits is not None: resources = self.template['spec'].get('resources', {}) limits = resources.get('limits', {}) limits.update(self._resource_limits) resources['limits'] = limits self.template['spec']['resources'] = resources def render_tag_and_push_registries(self): if self.dj.dock_json_has_plugin_conf('postbuild_plugins', 'tag_and_push'): push_conf = self.dj.dock_json_get_plugin_conf('postbuild_plugins', 'tag_and_push') args = push_conf.setdefault('args', {}) registries = args.setdefault('registries', {}) placeholder = '{{REGISTRY_URI}}' if placeholder in registries: for registry in self.spec.registry_uris.value: if not registry.uri: continue regdict = registries[placeholder].copy() regdict['version'] = registry.version registries[registry.docker_uri] = regdict del registries[placeholder] def render_add_yum_repo_by_url(self): if (self.spec.yum_repourls.value is not None and self.dj.dock_json_has_plugin_conf('prebuild_plugins', "add_yum_repo_by_url")): self.dj.dock_json_set_arg('prebuild_plugins', "add_yum_repo_by_url", "repourls", self.spec.yum_repourls.value) def render_check_and_set_rebuild(self, use_auth=None): if self.dj.dock_json_has_plugin_conf('prebuild_plugins', 'check_and_set_rebuild'): self.dj.dock_json_set_arg('prebuild_plugins', 'check_and_set_rebuild', 'url', self.spec.builder_openshift_url.value) if use_auth is not None: self.dj.dock_json_set_arg('prebuild_plugins', 'check_and_set_rebuild', 'use_auth', use_auth) def render_store_metadata_in_osv3(self, use_auth=None): try: self.dj.dock_json_set_arg('exit_plugins', "store_metadata_in_osv3", "url", self.spec.builder_openshift_url.value) if use_auth is not None: self.dj.dock_json_set_arg('exit_plugins', "store_metadata_in_osv3", "use_auth", use_auth) except RuntimeError: # For compatibility with older osbs.conf files self.dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "url", self.spec.builder_openshift_url.value) if use_auth is not None: # For compatibility with older osbs.conf files self.dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "use_auth", use_auth) def render(self): # !IMPORTANT! can't be too long: https://github.com/openshift/origin/issues/733 self.template['metadata']['name'] = self.spec.name.value self.render_resource_limits() self.template['spec']['source']['git']['uri'] = self.spec.git_uri.value self.template['spec']['source']['git']['ref'] = self.spec.git_ref.value if len(self.spec.registry_uris.value) > 0: primary_registry_uri = self.spec.registry_uris.value[0].docker_uri tag_with_registry = '{0}/{1}'.format(primary_registry_uri, self.spec.image_tag.value) self.template['spec']['output']['to']['name'] = tag_with_registry else: self.template['spec']['output']['to']['name'] = self.spec.image_tag.value self.render_tag_and_push_registries() if 'triggers' in self.template['spec']: imagechange = self.template['spec']['triggers'][0]['imageChange'] imagechange['from']['name'] = self.spec.trigger_imagestreamtag.value self.render_add_yum_repo_by_url() use_auth = self.spec.use_auth.value self.render_check_and_set_rebuild(use_auth=use_auth) self.render_store_metadata_in_osv3(use_auth=use_auth) # For Origin 1.0.6 we'll use the 'secrets' array; for earlier # versions we'll just use 'sourceSecret' if self._openshift_required_version < parse_version('1.0.6'): if 'secrets' in self.template['spec']['strategy']['customStrategy']: del self.template['spec']['strategy']['customStrategy']['secrets'] else: if 'sourceSecret' in self.template['spec']['source']: del self.template['spec']['source']['sourceSecret'] self.template['spec']['strategy']['customStrategy']['from']['name'] = \ self.spec.build_image.value def validate_input(self): self.spec.validate()
class CommonBuild(BuildRequest): def __init__(self, build_json_store): """ :param build_json_store: str, path to directory with JSON build files """ super(CommonBuild, self).__init__(build_json_store) self.spec = CommonSpec() def set_params(self, **kwargs): """ set parameters according to specification these parameters are accepted: :param git_uri: str, URL of source git repository :param git_ref: str, what git tree to build (default: master) :param registry_uris: list, URI of docker registry where built image is pushed (str) :param source_registry_uri: str, URI of docker registry from which image is pulled :param user: str, user part of resulting image name :param component: str, component part of the image name :param openshift_uri: str, URL of openshift instance for the build :param builder_openshift_url: str, url of OpenShift where builder will connect :param yum_repourls: list of str, URLs to yum repo files to include :param use_auth: bool, use auth from atomic-reactor? """ logger.debug("setting params '%s' for %s", kwargs, self.spec) self.spec.set_params(**kwargs) def render_resource_limits(self): if self._resource_limits is not None: resources = self.template['spec'].get('resources', {}) limits = resources.get('limits', {}) limits.update(self._resource_limits) resources['limits'] = limits self.template['spec']['resources'] = resources def render_tag_and_push_registries(self): if self.dj.dock_json_has_plugin_conf('postbuild_plugins', 'tag_and_push'): push_conf = self.dj.dock_json_get_plugin_conf( 'postbuild_plugins', 'tag_and_push') args = push_conf.setdefault('args', {}) registries = args.setdefault('registries', {}) placeholder = '{{REGISTRY_URI}}' if placeholder in registries: for registry in self.spec.registry_uris.value: if not registry.uri: continue regdict = registries[placeholder].copy() regdict['version'] = registry.version registries[registry.docker_uri] = regdict del registries[placeholder] def render_add_yum_repo_by_url(self): if (self.spec.yum_repourls.value is not None and self.dj.dock_json_has_plugin_conf('prebuild_plugins', "add_yum_repo_by_url")): self.dj.dock_json_set_arg('prebuild_plugins', "add_yum_repo_by_url", "repourls", self.spec.yum_repourls.value) def render_check_and_set_rebuild(self, use_auth=None): if self.dj.dock_json_has_plugin_conf('prebuild_plugins', 'check_and_set_rebuild'): self.dj.dock_json_set_arg('prebuild_plugins', 'check_and_set_rebuild', 'url', self.spec.builder_openshift_url.value) if use_auth is not None: self.dj.dock_json_set_arg('prebuild_plugins', 'check_and_set_rebuild', 'use_auth', use_auth) def render_store_metadata_in_osv3(self, use_auth=None): try: self.dj.dock_json_set_arg('exit_plugins', "store_metadata_in_osv3", "url", self.spec.builder_openshift_url.value) if use_auth is not None: self.dj.dock_json_set_arg('exit_plugins', "store_metadata_in_osv3", "use_auth", use_auth) except RuntimeError: # For compatibility with older osbs.conf files self.dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "url", self.spec.builder_openshift_url.value) if use_auth is not None: # For compatibility with older osbs.conf files self.dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "use_auth", use_auth) def render(self): # !IMPORTANT! can't be too long: https://github.com/openshift/origin/issues/733 self.template['metadata']['name'] = self.spec.name.value self.render_resource_limits() self.template['spec']['source']['git']['uri'] = self.spec.git_uri.value self.template['spec']['source']['git']['ref'] = self.spec.git_ref.value if len(self.spec.registry_uris.value) > 0: primary_registry_uri = self.spec.registry_uris.value[0].docker_uri tag_with_registry = '{0}/{1}'.format(primary_registry_uri, self.spec.image_tag.value) self.template['spec']['output']['to']['name'] = tag_with_registry else: self.template['spec']['output']['to'][ 'name'] = self.spec.image_tag.value self.render_tag_and_push_registries() if 'triggers' in self.template['spec']: imagechange = self.template['spec']['triggers'][0]['imageChange'] imagechange['from'][ 'name'] = self.spec.trigger_imagestreamtag.value self.render_add_yum_repo_by_url() use_auth = self.spec.use_auth.value self.render_check_and_set_rebuild(use_auth=use_auth) self.render_store_metadata_in_osv3(use_auth=use_auth) # For Origin 1.0.6 we'll use the 'secrets' array; for earlier # versions we'll just use 'sourceSecret' if self._openshift_required_version < parse_version('1.0.6'): if 'secrets' in self.template['spec']['strategy'][ 'customStrategy']: del self.template['spec']['strategy']['customStrategy'][ 'secrets'] else: if 'sourceSecret' in self.template['spec']['source']: del self.template['spec']['source']['sourceSecret'] self.template['spec']['strategy']['customStrategy']['from']['name'] = \ self.spec.build_image.value def validate_input(self): self.spec.validate()