RPM Build Environment

From Outrun Wiki
Jump to: navigation, search

1 Overview

The package outrun-build contains macros and scripts to make RPM development easier. Installing it also triggers installation of the required development packages and tools.

2 Setting up a build environment

We will use the special user "builduser" for this case although any (non-root) user can be used.

Never use the root user to build packages! Some source packages attempt to overwrite files in /usr or other important locations. Not using root prevents you from compromising your own system.

2.1 Prerequisites

run as root:

# Install the outrun-build package
yum install outrun-build

You need to have the YUM repositories enabled for the full Linux installation. If you have installed Outrun from the ISO image, you will only have a limited subset of RPM packages available, which does not include the RPM build packages. If that's the case, enable the "base" repository<ref>CentOS only</ref>:

# Enable web based CentOS YUM repository
yum-config-manager --enable base

2.2 Creating the build user

# Create the build user
useradd -m -g outrun builduser -c "RPM build user"
# Add build user to "build" group
gpasswd -a builduser build
# Verify group membership
id builduser

2.3 Setting up a YUM repository

By default, binary and source packages end up in $HOME/rpms and $HOME/srpms. These locations are not available for other users and/or hosts. We need to:

  1. Create a shared folder where binary packages (RPMS) can be downloaded from.
  2. Set up metadata so a client host can know what kind of packages are available etc.

In this example we will set up a read-only anonymous FTP share because Outrun already provides Anonymous FTP as an embedded service - so all we have to do is place our packages in a subdirectory of the anonymous FTP server.

On Outrun, Anonymous FTP is available from /var/ftp/ - so if we create a subdirectory /var/ftp/yumlocal then we can use that to store our RPMs.

# Make the directory
mkdir /var/ftp/yumlocal
# Change ownership to allow builduser to save new packages here
chown builduser:build /var/ftp/yumlocal
# Set rights
chmod 2775 /var/ftp/yumlocal/

# Check if our new directory is accessible via FTP
# As there are no files the result will be empty but there should be no error messages
curl -l ftp://localhost/yumlocal/

2.4 Build user preparations

→ Login as builduser

Upon first login as a user that is member of 'build', a file called rpmmacros will be copied to the user's home dir as $HOME/.rpmmacros.

→ Review the contents of $HOME/.rpmmacros

The rpmmacros file defines target locations of RPM packages and some metadata when building packages. See Customizing the RPM Build environment for more info.
The default target path (in Outrun) for RPM packages is $HOME/rpms.
The default target path for source RPM packages is $HOME/srpms<ref>In non-Outrun systems or if your user is not a member of "build", the build system will create all build directories in $HOME/rpmbuild/...</ref>
We want our RPM packages to be stored in the shared FTP folder instead of our home directory. Edit .rpmmacros and change %_rpmdir and %_srpmdir.
You also can change the name of our new repository here. → Edit .rpmmacros to reflect this section:

# ...
# Where to dump rpm packages
%_rpmdir        /var/ftp/yumlocal/rpms
%_srcrpmdir     /var/ftp/yumlocal/srpms

# Package metadata
%vendor         The Outrun Shop
%packager       Outrunner
%distribution   example
# When building the release package:
# Note that the %distribution name will be used to name the YUM repository. Keep it short and simple.
# The %vendor tag will be used for the YUM repo description.
# ...

When using the release-template.spec later, the %vendor and $distribution tags will be used to name/describe the repo:

# On client systems
yum repolist | grep example
repo id    repo name         status
example    The Outrun Shop   1

The environment is now ready for building packages.

3 Creating a release package

It's possible to manually setup YUM repo definitions by creating a <file>.repo definition file on client hosts.
However, if the repository changes, the repo files will not be updated and it's hard to maintain larger number of hosts this way. The better way is to build an RPM package that contains the correct repo file and is usually called <name>-release-<version>.rpm. Using a release package has the following advantages:

  • If you want to move the location (host) of the repository, you can update the release package and wait for the clients to get the updated config
  • It's easier and less risk to install an RPM than manually create a .repo file
  • If you want to remove the repository you can do this by uninstalling the release package.

Outrun-build provides a pre-configured SPEC file from which you can build a release package, /usr/share/build/release-template.spec which can be used to easily setup the repository RPMs.


# Rebuild release RPM from SPEC file
rpmbuild -ba /usr/share/build/release-template.spec

# Update the YUM repositories
createrepo -v .
createrepo -v .

# Verify the packages were built correctly
# Check for the *-release-<version>.noarch.rpm file and the corresponding .src.rpm file here:
ls -al
ls -al

# Show package information
rpm -qip *release*.rpm

# Get installation instructions - this is provided in the Description field of the release file
rpm -qip *release*.rpm | grep yum

# Check if the release file is available on FTP - the release RPM should be here
curl -l ftp://localhost/yumlocal/rpms/

4 YUM Client setup

Client hosts need to know where to find our RPM packages and metadata. This is done by placing a ".repo" file in /etc/yum.repos.d/. The release RPM package we have built will take care of that.
As we have not defined the repository itself yet, we cannot just "yum install ..." the release file. We need to specify the full URL to YUM.
The full YUM command to install the release file on any host was provided in the release file itself, via the rpm -qip *release*.rpm command.

On the client host, as root:

# Run the YUM command as indicated by the release file description, something like:
yum install ftp://your.YUM.host.net/yumlocal/rpms/example-release-1.0-1.noarch.rpm

# Check if the repository is defined
yum repolist -v example

# To show how the vendor, packager and distribution tags are embedded in each package built:
rpm -q --qf "Package Name:\t%{NAME}\nPackage Vendor:\t%{VENDOR}\nRPM Packager\t%{PACKAGER}\nDistribution:\t%{DISTRIBUTION}\n" example-release