We recently came across an issue where we needed to build CentOS 7 RPM’s from a CentOS 6 host.
Typically, when you’re building packages you would do it on the target os, os version and architecture. In this case, we chose not to standup new servers to be able to build an rpm for a slightly different version of an OS.
In the RPM spec file you can target the different os versions by using conditional code such as:
?el7 syntax will detect that the host is an enterprise linux
(CentOS) 7 host. Unfortunately, this doesn’t work well for us because we
needed a way to generate a el7 installers from an el6 host.
There are a couple of ways to do this.
- use mock
- use chroot.
mock requires that we can create a el6 rpm then rebuild it as an
el7 rpm. This would mean that both the el6 and el7 dependencies would
need to be present in the rpmbuild.
chroot is probably the cleanest way to produce a valid el7 rpm, but requires quite a few things to be put into place to make it work. Also, we have multiple worker processes on each host that generates rpms concurrently, so this setup seemed quite risky.
The option we opted for was quite simple:
Then we include a special define parameter when shelling out to rpmbuild.