Building packages is a task that every system administrator will end up doing. Most of the time this is not a very interesting task but someone has to do it, right? Normally you will end up modifying and tweaking based on your own needs an existing package that was built by the maintainers of the Linux distribution that you are using. In time you might even become familiar with the packaging system you are using (rpm, deb, etc.) and you will be able to write a spec file and start from scratch and build a new package if you need to. Still, this process is complicated and requires a lot of work.
Luckily, Jordan Sissel has built a tool called FPM (Effing Package Management), exactly for this: to ease the pain of building new packages; packages that you will use for your own infrastructure and you want them customized based on your own needs; and you don’t care about upstream rules and standards and other limitations when building such packages. This can be very useful for people deploying their own applications as rpms (or debs) and can simplify a lot of the process of building those packages.
FPM can be easily installed on your build system using rubygems:
Once installed you can use fpm to build packages (targets):
from any of the following sources:
- directory (of compiled source of some application)
- python eggs
- node npm packages
Use the command line help (fpm —help) or the wiki to see full details on how to use it. I’ll show some simple examples on how to build some packages from various input sources that I’ve found useful myself.
1. Package a directory – output of a ‘make install’ command
This is how you would usually package an application that you would install with: ./configure; make; make install For example, here is how you can create an rpm of the latest version of memcached:
1 2 3 4 5
so far everything looks like a normal manual installation (that would be followed by make install). Still we will now install it in a separate folder so we can capture the output:
and finally using fpm to create the rpm package:
where -s is the input source type (directory), -t is the type of package (rpm), -n in the name of the package and -v is the version; -C is the directory where fpm will look for the files. Note: you might need to install various libraries to build your package; for ex. in this case I had to install libevent-dev.
If you are packaging your own application you can do this just by pointing to your build folder and set the version of the app. Here is an example for an deb package:
There are various other parameters that you can use but basically this is how simple it is to build a package from a directory. Here is an example on how to define some dependencies on the package you are building (using -d; repeat it as many times as needed):
1 2 3
2. Ruby gems or python egg – converted to packages
You can create a deb or rpm from a gem very simple with fpm:
this will download the gem and create a package named rubygem-<gem_name> For example:
will create a debian package for fpm: rubygem-fpm_0.3.7_all.deb
You can inspect it with dpkg —info and you can notice that in this case it will fill nicely all the fields with the maintainer, and dependencies on various other gems. Very cool.
If you use python and want to package various python eggs this will work exactly the same and you will use -s python (it will download the python packages with easy_install first).
Overall FPM is a great tool and can help you simplify the way you are building your own packages. Check it out and let me know what you think and if you found it useful. And if you found this useful don’t forget to thank Jordan for his great work on this awesome tool.