rpkg is an RPM packaging utility based on python-rpkg library.

It works with both DistGit and standard Git repositories.

It handles two types of directory content: packed and unpacked.

  • Packed (unexpanded) content is that composed of tarballs, patches, and a .spec file
  • Unpacked (expanded) content is that composed of plain source files and a .spec file

There are currently two ways of handling those two different content types:

  • spec templates
  • autopacking (deprecated)

Spec templates

Apart from being useful as a means to handle unpacked (as well as packed) content, they also make it possible to generate certain parts of your spec file automatically from a Git repository where your spec file is located.

An example spec template might look like this:

Name:       {{{ git_name }}}
Version:    {{{ git_version }}}
Release:    1%{?dist}
Summary:    This is a test package.

License:    GPLv2+
URL:        https://someurl.org
VCS:        {{{ git_vcs }}}

Source:     {{{ git_pack }}}

%description
This is a test package.

%prep
{{{ git_setup_macro }}}

%changelog
{{{ git_changelog }}}

Having a spec template like this in your project (instead of just a plain spec file) allows you to build rpm packages that automatically follow git history of your project.

Read more here. If you are new to .spec files, you can start here.

Auto-packing (deprecated)

Auto-packing works only if auto_pack configuration option is set to True and only if the content you are working with is not packed (see rpkg is-packed).

When invoking rpkg srpm on an unpacked content, rpkg will download external sources (if any) and then it will generate a tarball from the whole content of the working directory named according to Source0 definition present in the associated .spec file. This tarball and the .spec file are then passed to rpmbuild to generate the resulting srpm.

More examples

Run %prep phase of an rpm build:

    $ rpkg prep
    git_pack: Wrote: /tmp/rpkg/rpkg-util-1-WdjXHt/rpkg-util-1.0.git.205.b82efb8.tar.gz
    Wrote: /tmp/rpkg/rpkg-util-1-WdjXHt/rpkg-util.spec
    Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.vgwvFS
    + umask 022
    + cd /tmp/rpkg/rpkg-util-1-WdjXHt
    + cd /tmp/rpkg/rpkg-util-1-WdjXHt
    + rm -rf rpkg-util-1.0.git.205.b82efb8
    + /usr/bin/gzip -dc /tmp/rpkg/rpkg-util-1-WdjXHt/rpkg-util-1.0.git.205.b82efb8.tar.gz
    + /usr/bin/tar -xof -
    + STATUS=0
    + '[' 0 -ne 0 ']'
    + cd rpkg-util-1.0.git.205.b82efb8
    + /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
    + exit 0

For the following command, you need to have a project in COPR created. See quick tutorial here on how to do it.

    $ rpkg build
    git_pack: Wrote: /tmp/rpkg/rpkg-util-3-KoTcl5/rpkg-util-1.0.git.205.b82efb8.tar.gz
    Wrote: /tmp/rpkg/rpkg-util-3-KoTcl5/rpkg-util.spec
    Wrote: /tmp/rpkg/rpkg-util-3-KoTcl5/rpkg-util-1.0.git.205.b82efb8-1.fc27.src.rpm
    Uploading package /tmp/rpkg/rpkg-util-3-KoTcl5/rpkg-util-1.0.git.205.b82efb8-1.fc27.src.rpm
    100% |################################| 122kB 325kB/s eta 0:00:00
    Build was added to rpkg-util:
      https://copr.fedorainfracloud.org/coprs/build/736555/
    Created builds: 736555
    Watching build(s): (this may be safely interrupted)
      21:25:06 Build 736555: importing
    ...

Other useful commands that you can use:

  • rpkg lint to check the .spec file and the overall package conformance to RPM standard
  • rpkg local to locally build the package into an rpm
  • rpkg upload to upload a new source to DistGit lookaside cache
  • rpkg ... (see rpkg --help or man rpkg)

Credits