Skip to main content

Building Amazon Linux RPMs with Fedora Mock

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.

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 subst
config_opts['releasever'] = '2017.03'
config_opts['use_nspawn'] = False
config_opts['awsdomain'] = 'amazonaws.com'
config_opts['awsregion'] = 'us-west-2'

config_opts['yum.conf'] = """
[main]
keepcache=1
debuglevel=2
reposdir=/dev/null
logfile=/var/log/yum.log
retries=20
obsoletes=1
gpgcheck=0
assumeyes=1
syslog_ident=mock
syslog_device=
mdpolicy=group:primary
best=1

# repos
[amzn-main]
name=amzn-main-Base
mirrorlist=http://repo.us-west-2.amazonaws.com/$releasever/main/mirror.list
mirrorlist_expire=300
metadata_expire=300
priority=10
failovermethod=priority
fastestmirror_enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga
enabled=1
retries=5
timeout=10
report_instanceid=yes

[amzn-main-debuginfo]
name=amzn-main-debuginfo
mirrorlist=http://repo.us-west-2.amazonaws.com/$releasever/main/debuginfo/mirror.list
mirrorlist_expire=300
metadata_expire=300
priority=10
failovermethod=priority
fastestmirror_enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga
enabled=0
retries=5
timeout=10
report_instanceid=yes

[amzn-main-source]
name=amzn-main-source
mirrorlist=http://repo.us-west-2.amazonaws.com/$releasever/main/SRPMS/mirror.list
mirrorlist_expire=300
metadata_expire=300
priority=10
failovermethod=priority
fastestmirror_enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga
enabled=0
retries=5
timeout=10
report_instanceid=yes

[in-progress]
name=in-progress
baseurl=file:///home/fedora/in-progress

[epel]
name=epel
mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=x86_64
failovermethod=priority
gpgkey=file:///usr/share/distribution-gpg-keys/epel/RPM-GPG-KEY-EPEL-6
gpgcheck=1
exclude=python-rpm-macros,epel-rpm-macros-*

[local]
name=local
baseurl=https://kojipkgs.fedoraproject.org/repos/dist-6E-epel-build/latest/x86_64/
cost=2000
enabled=0
"""
Building the SRPM is this:

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.rpm
There'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

Popular posts from this blog

Python and libpuzzle

As much as I've dogged on Python in the past (significant whitespace, really?), I've got to admit that it's got some cool features too. For example, I'm playing with libpuzzle  (a library for visually comparing images).  It has a command line utility and a C and PHP API.  Unfortunately, the CLI utility doesn't allow one to dump the raw comparison vector, and it's a PITA to write C just to play with a library. Python's native "ctypes" to the rescue! from ctypes import * class PuzzleCvec(Structure): _fields_ = [("sizeof_vec", c_size_t), ("vec", c_char_p)] class PuzzleCompressedCvec(Structure): _fields_ = [("sizeof_compressed_vec", c_size_t), ("vec", c_char_p)] class PuzzleContext(Structure): _fields_ = [("puzzle_max_width", c_uint), ("puzzle_max_height", c_uint), ("puzzle_lambdas", c_uint), ...

If it builds, ship it...

I've finally gotten a working build.  It turns out what I really needed was to get up @ 0630, take a shower, and just plug away. Anyhow, the source is up on github:   https://github.com/coredog64 I still need to get it to build an image for the Streak before I can actually test it.