Fedora's 'mock' tool provides a much more convenient way to build RPMs than using 'rpmbuild'. It creates a chroot environment for your target OS and will install required dependencies.
I've been running into limitations on the version of CollectD that ships with Amazon Linux, so I thought it wouldn't be that difficult to use mock to build an updated version complete with some missing plugins. I knew that it generally worked, as I was able to use the specfile from the project to build for EPEL6 using Fedora 26. Man, was I wrong about how easy it would be for Amazon Linux.
I won't go into details here, but it's worth mentioning that the CollectD project documentation calls out that the specfile in their contrib directory is generally out of date. That is 100% correct, so you'll need to budget some time for tweaking it.
The first issue is that there are some packages in EPEL that can't be installed in Amazon Linux. The most aggravating are libyajl/libyajl-devel, both of which are required for the curl_json plugin in CollectD.
Working around that particular issue required grabbing the SRPM from EPEL, extracting the contents, and building for Amazon Linux. Then I had to figure out how to pull those packages into my mock workflow. Luckily, that was as easy as putting them into a local directory and calling 'createrepo'.
The next problem was that Amazon's general Python 2.6 RPM conflicts with another RPM from EPEL (python-rpm-macros). Thanks to these kind folks, I was able to figure out that I could exclude packages. Unfortunately, 'python-rpm-macros' isn't a direct dependency, so I had to run mock a few times to figure out how to blacklist the correct packages.
After some experimentation, here's my mock config file for Amazon Linux 2017.03. I'm running in the us-west-2 region, so if you're running elsewhere you'll obviously need to change the region in the file.
And then building the RPM from the SRPM is this:
I've been running into limitations on the version of CollectD that ships with Amazon Linux, so I thought it wouldn't be that difficult to use mock to build an updated version complete with some missing plugins. I knew that it generally worked, as I was able to use the specfile from the project to build for EPEL6 using Fedora 26. Man, was I wrong about how easy it would be for Amazon Linux.
I won't go into details here, but it's worth mentioning that the CollectD project documentation calls out that the specfile in their contrib directory is generally out of date. That is 100% correct, so you'll need to budget some time for tweaking it.
The first issue is that there are some packages in EPEL that can't be installed in Amazon Linux. The most aggravating are libyajl/libyajl-devel, both of which are required for the curl_json plugin in CollectD.
Working around that particular issue required grabbing the SRPM from EPEL, extracting the contents, and building for Amazon Linux. Then I had to figure out how to pull those packages into my mock workflow. Luckily, that was as easy as putting them into a local directory and calling 'createrepo'.
The next problem was that Amazon's general Python 2.6 RPM conflicts with another RPM from EPEL (python-rpm-macros). Thanks to these kind folks, I was able to figure out that I could exclude packages. Unfortunately, 'python-rpm-macros' isn't a direct dependency, so I had to run mock a few times to figure out how to blacklist the correct packages.
After some experimentation, here's my mock config file for Amazon Linux 2017.03. I'm running in the us-west-2 region, so if you're running elsewhere you'll obviously need to change the region in the file.
Building the SRPM is this:config_opts['root'] = 'amazon-2017.03-x86_64'config_opts['target_arch'] = 'x86_64'config_opts['legal_host_arches'] = ('x86_64',)config_opts['chroot_setup_cmd'] = 'install @buildsys-build'#config_opts['dist'] = 'el6' # only useful for --resultdir variable substconfig_opts['releasever'] = '2017.03'config_opts['use_nspawn'] = Falseconfig_opts['awsdomain'] = 'amazonaws.com'config_opts['awsregion'] = 'us-west-2'config_opts['yum.conf'] = """[main]keepcache=1debuglevel=2reposdir=/dev/nulllogfile=/var/log/yum.logretries=20obsoletes=1gpgcheck=0assumeyes=1syslog_ident=mocksyslog_device=mdpolicy=group:primarybest=1# repos[amzn-main]name=amzn-main-Basemirrorlist=http://repo.us-west-2.amazonaws.com/$releasever/main/mirror.listmirrorlist_expire=300metadata_expire=300priority=10failovermethod=priorityfastestmirror_enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-gaenabled=1retries=5timeout=10report_instanceid=yes[amzn-main-debuginfo]name=amzn-main-debuginfomirrorlist=http://repo.us-west-2.amazonaws.com/$releasever/main/debuginfo/mirror.listmirrorlist_expire=300metadata_expire=300priority=10failovermethod=priorityfastestmirror_enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-gaenabled=0retries=5timeout=10report_instanceid=yes[amzn-main-source]name=amzn-main-sourcemirrorlist=http://repo.us-west-2.amazonaws.com/$releasever/main/SRPMS/mirror.listmirrorlist_expire=300metadata_expire=300priority=10failovermethod=priorityfastestmirror_enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-gaenabled=0retries=5timeout=10report_instanceid=yes[in-progress]name=in-progressbaseurl=file:///home/fedora/in-progress[epel]name=epelmirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=x86_64failovermethod=prioritygpgkey=file:///usr/share/distribution-gpg-keys/epel/RPM-GPG-KEY-EPEL-6gpgcheck=1exclude=python-rpm-macros,epel-rpm-macros-*[local]name=localbaseurl=https://kojipkgs.fedoraproject.org/repos/dist-6E-epel-build/latest/x86_64/cost=2000enabled=0"""
mock -r /etc/mock/amazon-2017.03-x86_64.cfg --buildsrpm --spec $HOME/rpmbuild/SPECS/collectd.spec --sources $HOME/rpmbuild/SOURCES
And then building the RPM from the SRPM is this:
mock -r /etc/mock/amazon-2017.03-x86_64.cfg --no-clean --rebuild /var/lib/mock/amazon-2017.03-x86_64/result/collectd-5.7.2-3.amzn1.src.rpmThere's a couple other native packages I want to build, so at some point I plan to put all this stuff up in GitHub to make it easier to consume.
Comments