howto

Building own RPM packages

This article describes how you can set up your own RPM packaging repository and build RPM packages from upstream sources using git-buildpackage-rpm tool.

You may find this article useful if you want to:

  • package your or someone else software in RPM format
  • maintain your set of patches to existing source code and be able to build these as RPM.

Install git-buildpackage-rpm

OpenNode RPM repository can be used:

curl http://opennodecloud.com/CentOS/6/tools/opennode-tools.repo > /etc/yum.repos.d/opennode-tools.repo
rpm --import http://opennodecloud.com/CentOS/6/tools/RPM-GPG-KEY-ActiveSys
yum install git-buildpackage-rpm

Alternatively, you can get latest version of git-buildpackage-rpm from Github repository.

Get upstream sources

Upstream source code will be imported to packaging repository.

Upstream source code archive file should be named foo-1.2.3.tar.gz (or foo-1.2.3.tar.bz2) where foo is program upstream name and 1.2.3 is program version. Archive should contain one directory named foo-1.2.3 with all source code placed inside that.

Examples

Get source code archive from Python Package Index:

wget https://pypi.python.org/packages/source/S/South/South-0.8.4.tar.gz

Get source code archive from Github – ‘develop’ is desired branch or tag name here:

wget -O nodeconductor-develop.tar.gz https://github.com/opennode/nodeconductor/archive/develop.tar.gz

Get source code archive from Bitbucket:

wget -O South-0.8.4.tar.gz https://bitbucket.org/andrewgodwin/south/get/0.8.4.tar.gz

Create source code archive from cloned repository using setup.pydist/logan-0.5.9.tar.gz file will be created:

git clone https://github.com/dcramer/logan
cd logan
git checkout tags/0.5.9
python setup.py sdist

Create source code archive from cloned repository using tar/tmp/logan-0.5.9.tar.gz file will be created:

git clone https://github.com/dcramer/logan
cd logan
git checkout tags/0.5.9
tar -czf /tmp/logan-0.5.9.tar.gz --transform 's,^,logan-0.5.9/,' *

Create RPM spec file

RPM spec file describres how to build the RPM package.

RPM spec file should be named foo.spec where foo is RPM package name. Note that

  • RPM package name may be different from program upstream name, example: ‘python-south’ (RPM) vs ‘South’ (upstream)
  • single RPM spec file may be used to build multiple RPM packages.

Refer to Fedora Packaging Guidelines for more info on RPM spec files.

This is a minimal RPM spec file template that will help you to get started:

Name: foo
Version: 0.0.1
Release: 1
Summary: Package foo summary
License: MIT

%description
Package foo description.

Create packaging repository

git init
git remote add origin git@github.com:user/foo.git

– where user is your Github user and foo is packaging repository name.

Import upstream sources

Upstream code and packaging info should be kept in separate branches; default upstream branch name is upstream:

git-import-orig-rpm --no-interactive /path/to/source-archive.tar.gz
git checkout upstream
git push -u origin upstream

Add packaging info

Default packaging branch name is master, however, you may want to use distribution-specific branch names (centos-6, centos-7, trusty etc.) to be able to build multiple packages from one repository. Example for centos-6 branch:

git checkout -b centos-6

Create git-buildpackage-rpm configuration file:

cat > .gbp.conf <<EOF
[git-buildpackage-rpm]
patch-export = True
patch-numbers = True
patch-export-ignore-path = (.gbp.conf|packaging/.*)
packaging-branch=centos-6
upstream-branch=upstream
EOF

Create packaging directory:

mkdir packaging

Add these files to packaging directory:

  • RPM spec file: foo.spec
  • Unpacked patches, if any: 0001-foo-fix.patch etc.
  • Other files needed to build RPM package, if any: scripts, configs etc.

Check RPM spec file with rpmlint and make sure there are no errors:

rpmlint packaging/foo.spec

Commit changes:

git add packaging
git commit -m 'Added packaging info'
git push -u origin centos-6

All done.

You can now build RPM packages from this packaging repository:

git-buildpackage-rpm