fpm – the fast track to the parcel

Today’s article deals with the tool “fpm” – effing package management.

We are currently sprinting towards orcharhino 3.2.0 within our agile working methodology ‘Scrum’. One aim of the new version of the tool for orchestration, administration and lifecycle management of servers within a data center is to represent the first step towards simplifying the installation of orcharhino through to the initial creation of a host. However, this is where we first encountered a challenge: When automatically deploying a specific Linux distribution, a DVD is required. Currently, the ISO image is integrated via VMware and made available in orcharhino as an installation medium. Complicated, a manual step and therefore error-prone. A solution had to be found…

Why not simply package the ISO image and install it when installing orcharhino ?

But how do we package the ISO image?

Conventional distributions offer appropriate tools to create clean RPM or deb packages. However, creating and maintaining the RPM spec file can take a lot of time. The advantage is that you can simply roll out an RPM created once on many different hosts and thus install application programs, plug-ins and data on the target system, for example. You can also make the target package available to the upstream project such as Fedora or Debian and thus make your contribution to the open source community.

You could also dispense with the RPM altogether and instead simply store a tar archive at a specific point after the orcharhino installation. The disadvantage of this, however, is that the package manager cannot be used for updating or deleting.

What we are looking for is a solution between full RPM usage and tar archive: The creation of the package should be quick and easy and the RPM package manager should be able to do its job of managing the files and be used when updating/deleting the package.

Ever heard of fpm?

With fpm you can

  • from various data sources such as gem, rpm, deb, python, apk, tar or a directory
  • quick and easy
  • for many target types such as rpm, deb, freebsd
  • create packages!

When making your decision, however, you should consider whether you really want to use fpm. Although fpm creates a package that can be installed, certain specifications and conventions of the Linux distributions may not be observed (e.g. specification of a license, correct management of a package changelog, no differentiation between features of the respective Linux distribution).

Enough warnings – how do you use fpm?

Let’s assume that we have included the ISO image from the previous example under /media/cdrom and want to create an RPM from it. It is important to know that fpm requires the respective build tools when creating the packages – in the case of the RPM, the “rpmbuild” program is required. It’s a good thing that we are currently on a CentOS, which is why we can immediately create the RPM with the following command:

fpm -s dir -t rpm -n ReallyCoolLinuxDistribution -C /media/cdrom .

This command creates an RPM (“-t rpm”) with the name (“-n ReallyCoolLinuxDistribution”) from a directory (“-s dir”) by first changing to the target directory (“-C /media/cdrom”) and then packing the directory (“.”). The resulting RPM is stored in the current folder with the name ReallyCoolLinuxDistribution-1.0-1.x86_64.rpm.

With the following command we can see what fpm has put together for us here:

rpm -qpl --info ReallyCoolLinuxDistribution-1.0-1.x86_64.rpm

That’s quite good, but we can see that some things are not set correctly – such as the version, release number, RPM summary, post-installation script and changelog. Let’s set this correctly now!

fpm -s dir -t rpm -n ReallyCoolLinuxDistribution -C chroot/ --rpm-dist rcld --rpm-summary "Really Cool Linux Distribution 1.0 ISO" 
--description "`cat desc.txt`"  --rpm-changelog changes.txt --after-install postinstall.sh --license MIT -a noarch -v 4.1 
--iteration 2 --url http:///www.orcharhino.com .

fpm creates the package and outputs the following:

Created package {:path=>"ReallyCoolLinuxDistribution-4.1-2.rcld.noarch.rpm"}

Looks pretty good already. Version 4.1, release to 2 and RPM distribution are set to “rcld”. With the following command we can also check whether the URL, description, etc. have been correctly specified by fpm in the package:

rpm -qpl --info ReallyCoolLinuxDistribution-4.1-2.rcld.noarch.rpm

If you want to understand in detail what fpm does to create the RPM, or if you are chasing a bug, you can also make fpm a little more talkative with “–verbose”. fpm uses corresponding
workspaces to create the packages that are cleaned up at the end. This can be prevented with “–debug-workspace”.

The “-e” option is also very elegant. If you specify this, the RPM spec file is opened by the standard editor (with “export EDITOR=vim” you can set “vim” as the editor). If you save the RPM Spec (with vim with “:w”) and close the editor (with “:q”), the build process of the RPM is continued with this RPM Spec and finally the RPM is written.

As already mentioned, fpm can be used to create not only RPMs of directories, but much more. Further options can be displayed with “fpm –help”. However, fpm should not be your first choice – I would only recommend it for one-off actions and in simple use cases. After all, it is better than a simple tar archive. For proper, clean RPMs (or Debian packages), the on-board tools of the respective Linux distribution should be used as before.

The following two tabs change content below.

ATIX-Crew

Der ATIX-Crew besteht aus Leuten, die in unterschiedlichen Bereichen tätig sind: Consulting, Development/Engineering, Support, Vertrieb und Marketing.

Latest posts by ATIX-Crew (see all)