#214 Allow container builds from any namespace
Closed 6 years ago by lsedlar. Opened 7 years ago by maxamillion.
maxamillion/rpkg container_namespace  into  master

file modified
+52 -10
@@ -608,6 +608,36 @@ 

                          ' 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):
cqi commented 7 years ago

It would be nice to refactor load_ns_module_name to make it and load_ns share the same code and logic.

+         """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
cqi commented 7 years ago

Looks return is not necessary.

+             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 @@ 

  

          :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 @@ 

          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 @@ 

              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 @@ 

                               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]
cqi commented 7 years ago

How about to put these lines of code into a separate property and reuse it.

@property
def container_build_target(self):
    ...

  

          koji_session_backup = (self.build_client, self.kojiconfig)

          (self.build_client, self.kojiconfig) = (build_client, kojiconfig)
@@ -2558,9 +2600,9 @@ 

              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 @@ 

                      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)

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 maxamillion@fedoraproject.org

rebased

7 years ago

I fixed something and pushed on a rebase, but it's not rerunning the jenkins job. I'm not sure how to kick that off for testing.

It would be nice to refactor load_ns_module_name to make it and load_ns share the same code and logic.

Looks return is not necessary.

How about to put these lines of code into a separate property and reuse it.

@property
def container_build_target(self):
    ...

@maxamillion Can you add tests as well?

Hi @maxamillion Can you introduce some background of this change of why to allow building docker container from any namespace not only from container/?

I think that the namespace is too implementation specific to be in rpkg, it should be up to fedpkg, centpkg, etc to limit what namespaces are allowed for that instance

Apologies for the delay here, I was traveling. The background is that Fedora Atomic WG has targeted the move to the container namespace in DistGit and in pkgdb in order to make the container namespace be generic for all OCI Compliant container implementations instead of a specific one. Also the change I introduce remains backwards compatible to the best of my knowledge.

The code handling --module-name option in pyrpkg/cli.py should also be updated to set the ns property.

Merged in #219 with a few changes to address the comments here.

Pull-Request has been closed by lsedlar

6 years ago

@lsedlar I just realized today because someone ping'd me on irc that #219 does not actually solve the problem I was trying to solve here. Can this be revisited?

It should have changed the build target to '%s-%s-candidate' % (self.branch_merge, self.ns) which seems like what you wanted. However the patch was not released yet. It's included in rpkg-1.49-5, which is still in updates-testing.