I wanted to learn how to build an RPM package out of a Python module so, now that I’m playing a bit with OpenStack, I decided to pick up a log merger for OpenStack files and build the corresponding package on my Fedora 24.
First thing is to setup the distribution with the right packages:
1 | [root@localhost ~]$ dnf install @development-tools fedora-packager |
1 | [dani@localhost ~]$ rpmdev-setuptree |
2 | [dani@localhost ~]$ ls rpmbuild/ |
3 | BUILD BUILDROOT RPMS SOURCES SPECS SRPMS |
Now, under the SPECS directory, we need to create the spec file which will include the necessary info to build the RPM:
1 | %global srcname os-log-merger |
2 | %global sum OpenStack Log Merger |
13 | BuildRoot: %{_tmppath}/%{srcname}-%{version}-build |
18 | A tool designed to take a bunch of openstack logs across different projects, and merge them in a single file , ordered by time entries |
22 | %{?python_provide:%python_provide python2-%{srcname}} |
24 | %description -n %{srcname} |
25 | A tool designed to take a bunch of openstack logs across different projects, and merge them in a single file , ordered by time entries |
28 | %autosetup -n %{srcname}-%{version} |
34 | %{__python2} setup.py test |
40 | %{_bindir}/os-log-merger |
45 | * Tue Jul 19 2016 dani - 1.0.6-1 |
46 | - First version of the os-log-merger-package |
Once the file is created, it’s time to build the RPM package:
1 | [dani@localhost SPECS]$ rpmbuild -bb os-log-merger.spec |
4 | + cd /home/dani/rpmbuild/BUILD |
5 | + cd os-log-merger-1.0.6 |
6 | + /usr/bin/ rm -rf /home/dani/rpmbuild/BUILDROOT/python-os-log-merger-1.0.6-1.fc24.x86_64 |
8 | [dani@localhost SPECS]$ ls -alh ../RPMS/noarch/ |
10 | drwxr-xr-x. 2 dani dani 4,0K jul 19 20:35 . |
11 | drwxr-xr-x. 3 dani dani 4,0K jul 19 20:35 .. |
12 | -rw-rw-r--. 1 dani dani 34K jul 19 20:47 os-log-merger-1.0.6-1.fc24.noarch.rpm |
We can see that the rpmbuild command produced the RPM file inside ~/rpmbuild/RPMS/noarch. Let’s pull the info from it and check whether it’s correct:
1 | [dani@localhost SPECS]$ rpm -qip ../RPMS/noarch/os-log-merger-1.0.6-1.fc24.noarch.rpm |
6 | Install Date: (not installed) |
11 | Source RPM : python-os-log-merger-1.0.6-1.fc24.src.rpm |
12 | Build Date : mar 19 jul 2016 20:47:42 CEST |
14 | Relocations : (not relocatable) |
16 | Summary : OpenStack Log Merger |
18 | A tool designed to take a bunch of openstack logs across different projects, and merge them in a single file , ordered by time entries |
The last step is trying to install the actual file and execute the module to see if everything went fine:
1 | [root@localhost noarch]$ rpm -qa | grep os-log-merger |
2 | [root@localhost noarch]$ rpm -i os-log-merger-1.0.6-1.fc24.noarch.rpm |
3 | [root@localhost noarch]$ oslogmerger |
4 | usage: oslogmerger [-h] [- v ] [--log-base LOG_BASE] |
5 | [--log-postfix LOG_POSTFIX] [-- alias -level ALIAS_LEVEL] |
6 | [--min-memory] [--msg-logs file [:ALIAS] [ file [:ALIAS] ...]] |
7 | [--timestamp-logs file [:ALIAS] [ file [:ALIAS] ...]] |
8 | log_file[:ALIAS] [log_file[:ALIAS] ...] |
References:
https://fedoraproject.org/wiki/How_to_create_a_GNU_Hello_RPM_package
https://fedoraproject.org/wiki/Packaging:Python