From cd6d6f351718d508b7a25aba2efaec1be18106db Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Apr 12 2017 20:21:20 +0000 Subject: Allow container builds from any namespace Previously rpkg enforced a "%s-docker-candidate" koji tag for any container-build such that "%s" was the DistGit branch unless there was a target override passed. This patch allows for the DistGit namespace to be inherited into the koji tag making it "%s-%s-candidate" such that "%s-%s" % (DistGitBranch, DistGitNamespace). Signed-off-by: Adam Miller --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 66dd7e2..c92150f 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -608,6 +608,36 @@ class Commands(object): ' Use --module-name.') @property + def ns(self): + """This property provides the namespace of the module""" + + if not self._ns: + self.load_ns() + return self._ns + + def load_ns(self): + """Loads the namespace""" + + try: + if self.distgit_namespaced: + if self.push_url: + parts = urllib.parse.urlparse(self.push_url) + + path_parts = [p for p in parts.path.split("/") if p] + if len(path_parts) == 1: + path_parts.insert(0, "rpms") + ns = path_parts[-2] + + self._ns = ns + return + else: + self._ns = None + self.log.info("Could not find ns, distgit is not namespaced") + return + except rpkgError: + self.log.warning('Failed to get ns from Git url or pushurl') + + @property def ns_module_name(self): """This property ensures the module attribute""" @@ -1782,8 +1812,8 @@ class Commands(object): :param bool is_dirty: Default to True. To check whether there is uncommitted changes. :param bool has_namespace: Default to True. To check whether this repo - is checked out with namespace, e.g. rpms/, docker/. If the repo is - an old checkout, warn user with message how to fix it. + is checked out with namespace, e.g. rpms/, docker/, container/. If + the repo is an old checkout, warn user with message how to fix it. :param bool all_pushed: Default to True. To check whether all changes are pushed. :raises rpkgError: if any unexpected status is detected. For example, if changes are not committed yet. @@ -2500,11 +2530,17 @@ class Commands(object): git_branch = self.branch_merge user = self.user component = self.module_name - docker_target = self.target + container_target = self.target if not target_override: # Translate the build target into a docker target, # but only if --target wasn't specified on the command-line - docker_target = '%s-docker-candidate' % self.target.split('-candidate')[0] + if self.distgit_namespaced: + # Allow for any namespace, not just "docker" + container_target = '%s-%s-candidate' % \ + (self.target.split('-candidate')[0], self.ns) + else: + container_target = '%s-docker-candidate' % \ + self.target.split('-candidate')[0] build = osbs.create_build( git_uri=git_uri, @@ -2512,7 +2548,7 @@ class Commands(object): git_branch=git_branch, user=user, component=component, - target=docker_target, + target=container_target, architecture="x86_64", yum_repourls=yum_repourls ) @@ -2545,11 +2581,17 @@ class Commands(object): nowait=False): # check if repo is dirty and all commits are pushed self.check_repo() - docker_target = self.target + container_target = self.target if not target_override: # Translate the build target into a docker target, # but only if --target wasn't specified on the command-line - docker_target = '%s-docker-candidate' % self.target.split('-candidate')[0] + if self.distgit_namespaced: + # Allow for any namespace, not just "docker" + container_target = '%s-%s-candidate' % \ + (self.target.split('-candidate')[0], self.ns) + else: + container_target = '%s-docker-candidate' % \ + self.target.split('-candidate')[0] koji_session_backup = (self.build_client, self.kojiconfig) (self.build_client, self.kojiconfig) = (build_client, kojiconfig) @@ -2558,9 +2600,9 @@ class Commands(object): if "buildContainer" not in self.kojisession.system.listMethods(): raise RuntimeError("Kojihub instance does not support buildContainer") - build_target = self.kojisession.getBuildTarget(docker_target) + build_target = self.kojisession.getBuildTarget(container_target) if not build_target: - msg = "Unknown build target: %s" % docker_target + msg = "Unknown build target: %s" % container_target self.log.error(msg) raise UnknownTargetError(msg) else: @@ -2580,7 +2622,7 @@ class Commands(object): task_opts[key] = opts[key] priority = opts.get("priority", None) task_id = self.kojisession.buildContainer(source, - docker_target, + container_target, task_opts, priority=priority) self.log.info('Created task: %s', task_id)