#567 Added 'x-pkg verrel' for containers
Merged 2 years ago by onosek. Opened 2 years ago by jkunstle.
jkunstle/rpkg verrel_for_dockerfile  into  master

file modified
+1
@@ -18,6 +18,7 @@ 

  htmlcov/

  /.eggs/

  .env/

+ .venv/

  

  doc/build/

  doc/source/_static

file modified
+47 -2
@@ -665,10 +665,24 @@ 

      def load_nameverrel(self):

          """Set the release of a package."""

  

+         #  If the repo is a container, we check for 'verrel' information in the Dockerfile.

+         if self.ns in ("container", "containers"):

+             if os.path.isfile(os.path.join(self.layout.root_dir, "Dockerfile")):

+                 docker_name, docker_version, docker_release = self.load_nameverrel_dockerfile()

+ 

+                 self._package_name_spec = docker_name

+                 self._epoch = "0"

+                 self._ver = docker_version

+                 self._rel = docker_release

+                 return

+             else:

+                 raise rpkgError("Dockerfile for {0} not found.".format(self.repo_name))

+ 

+         #  Otherwise, we get 'verrel' information from the '.spec' file.

          cmd = ['rpm']

          cmd.extend(self.rpmdefines)

  

-         specfile_path = os.path.join(self.path, self.spec)

+         specfile_path = os.path.join(self.layout.specdir, self.spec)

  

          if specfile_uses_rpmautospec:

              self._uses_autorelease = specfile_uses_rpmautospec(
@@ -706,7 +720,7 @@ 

              self.log.error(err)

          if proc.returncode > 0:

              raise rpkgError('Could not get n-v-r-e from %s'

-                             % os.path.join(self.path, self.spec))

+                             % os.path.join(self.layout.specdir, self.spec))

  

          # Get just the output, then split it by ??, grab the first and split

          # again to get ver and rel
@@ -4090,3 +4104,34 @@ 

          if ret == 0:

              self.log.info("Remote '{}' for '{}' was added.".format(remote_name, anongiturl))

          self._run_command(['git', 'fetch', remote_name])

+ 

+     def load_nameverrel_dockerfile(self):

+ 

+         named_version_pattern = re.compile(r"{0}_VERSION\s?=\s?([0-9.]+)".format(self.repo_name),

+                                            re.IGNORECASE)

+         version_pattern = re.compile(r"\bVERSION\b\s?=\s?([0-9.]+)", re.IGNORECASE)

+         release_pattern = re.compile(r"\bRELEASE\b\s?=\s?([0-9.]+)", re.IGNORECASE)

+ 

+         with open(os.path.join(self.layout.root_dir, "Dockerfile"), "r") as f:

+             text = str(f.read())

+ 

+             named_version_match = re.search(named_version_pattern, text)

+             version_match = re.search(version_pattern, text)

+             release_match = re.search(release_pattern, text)

+ 

+             if named_version_match:

+                 version = named_version_match.group(1)

+             else:

+                 if version_match:

+                     version = version_match.group(1)

+                 else:

+                     raise rpkgError('Could not query n-v-r of %s: no version in Dockerfile.'

+                                     % (self.repo_name))

+ 

+             if release_match:

+                 release = release_match.group(1)

+             else:

+                 raise rpkgError('Could not query n-v-r of %s: no release value in Dockerfile.'

+                                 % (self.repo_name))

+ 

+         return self._repo_name, version, release

file modified
+1 -1
@@ -1545,7 +1545,7 @@ 

      def register_verrel(self):

  

          verrel_parser = self.subparsers.add_parser(

-             'verrel', help='Print the name-version-release')

+             'verrel', help='Print the name-version-release.')

          verrel_parser.set_defaults(command=self.verrel)

  

      def register_container_build_common(self):

Added 'x-pkg verrel' for containers

Users wanted the ability to use 'x-pkg verrel' to
get relevant information about their container images.

Method parses values in Dockerfile. If there is an
overloaded value for a repo's version the method
uses the higher precedence value:

(1) <repo_name>_VERSION superceded VERSION

If there is no RELEASE value in the Dockerfile,
'verrel' fails.

+ added changes suggested by @onosek

Fixes: #547
Signed-off-by: jkunstle jkunstle@redhat.com

@onosek Here is the PR for this issue.

rebased onto b4a39aa305caa461f696fd5818253d38cf46e9d7

2 years ago

rebased onto 584fc8104c7a25f385950ad081c6933008d03b49

2 years ago

rebased onto f1530877bb098b2b8d01f42894a447b3f5618a26

2 years ago

rebased onto a6efd2e7ae67fae14da95e00cb8c16e245a7b4ab

2 years ago

rebased onto a268e6abf780a3b0f65843d5683cb05e722c4aac

2 years ago

rebased onto aa0af94cb6fbbd53a03226a35f464a97b4914f9e

2 years ago

rebased onto 0c94d11917e79ed3b2b1aef9675f8daae2dc864e

2 years ago

rebased onto d3f207e2910010ad673baeb90543f8b70e185a49

2 years ago

rebased onto fad444f850af9a8529133347e13c777312056059

2 years ago

rebased onto 0eb686b79c6a921a83522b3fcf9634b96485af3c

2 years ago

rebased onto 2f026984ea7149f20a92a67c3566489759fe30f7

2 years ago

rebased onto ec325b8712148afa6566c82471814e26c6b71c89

2 years ago

rebased onto e834019

2 years ago

Looks fine. Unit tests can be done later in a separate commit.

Pull-Request has been merged by onosek

2 years ago