Building an RPM can be a somewhat annoying, painful experience. There are plenty of pitfalls, but the most annoying, for me at least, is building a package and then trying to install it and realising that it doesn’t work because of some incompatibility in the packages that just happened to be on your build box.
One solution to this problem is to use Mock. Mock does a great job of building up an standalone environment, so that you can ‘Fail early’, if you haven’t written your spec file correctly.
Start by installing Mock and other required packages. For example:
Mock won’t allow users other than root by default. This is easily fixed by adding your build user to the mock group:
From there I usually create an rpmify script. This example comes from packaging a rails application:
The script is designed to be used within bamboo, so it does some handling around the artifacts that it produces
Mock looks in /etc/mock for the config that you specify, in this case /etc/mock/epel-6-x86_64.cfg. It is from here that it finds information on how to deploy the dependecies. If you have custom repositories, you’ll want to create your own file.