RPM101: A gentle intro to creating your own packages Richard Keech Red Hat Asia-Pacific
Agenda Issues What's in an RPM SPEC files Rolling your own package
The RPM way For both core OS and add-ons Installation is not interactive ● Installation separated from configuration No such thing as a patch A file can only belong to one package Pristine source plus patches
RPM packaging Installed state becomes: ● Visible ● Verifiable ● Upgradable
RPM packaging Packages contain ● Files (obviously!) ● Scripts (install & uninstall) ● Metadata
Creating your own RPMs Benefits: ● Modular installation, removal and upgrading ● Rapid deployment ● Controlled configuration ● Integrates with OS dependencies Benefits – developers ● Repeatable builds ● Dependency handling ● Configuration control
Creating your own RPMs General approach: ● Create tar archive of manual install ● Create / adapt a SPEC file Outcome: ● End-usable package file ● 'Source' package file
Build tree /usr/src/redhat/ BUILD/ RPMS/ i386 noarch SOURCES/ SPECS/ SRPMS/
RPM Macros Variables and functions Defaults in /usr/lib/rpm/macros Overrides in /etc/rpm/macros.* and ~/.rpmmacros Users should set %{_topdir} macro, otherwise build will be in /usr/src/redhat
SPEC file: preamble Name: hello Version: 1.0 Release: 1 Summary: Hello, world! Group: Applications/Productivity License: Distributable Source0: hello-1.0.tar.gz Source1: hello.sh Source2: hello.csh BuildArch: i686 BuildRoot: /var/tmp/hello-root %description An enthusiastic greeting to the world of RPM building.
SPEC file: %prep %prep prepares sources ● Unpacks pristine sources into BUILD ● Applies any necessary patches Useful macros ● %setup ● %patch
SPEC file: %build %build compiles and prepares the software Runs as a shell script %configure macro make
SPEC file: %install %install prepares files for packaging Chroot tree - BuildRoot $RPM_BUILD_ROOT set %makeinstall
SPEC file: %clean %clean removes temporary files after the build Typically remove BuildRoot tree %clean rpm -rf $RPM_BUILD_ROOT
SPEC file: Scripts Should never be interactive %pre -- prior to file installation ● Adding users and groups %post -- after file installation ● chkconfig –add ● service re-start %preun – before file removal ● chkconfig --del %postun – after file removal rpm -q --scripts pkgname
SPEC file: %files %files lists all the files Sufficient to specify the base directory if all files are included %dir to specify empty directories %defattr(mode,user,group) filename %config %doc
SPEC file: %changelog %changelog records package history Date format: +”%a %b %d %Y” Show using rpm -q --changelog pkg
rpmbuild rpmbuild -bp specfile prep only rpmbuild -bc specfile prep and compile rpmbuild -bb specfile prep and compile and install rpmbuild -bs specfile build source pkg only rpmbuild -ba specfile all, ie binary and source pkg
Signing RPM packages GPG key required Signing is generally encouraged Signing is mandatory for many repos rpmbuild --sign rpmbuild --resign Macros: %_signature gpg %gpg_name My Name Make public key available
References Red Hat RPM Guide
Demo (time permitting)
Example: RPMs of Oracle DB Roll your own: encapsulation / backup of the Oracle install you'd do by hand find a spec file that does something similar Example: Red Hat product “Satellite” embeds Oracle Server Example: Oracle Express available as RPM
RPMs of Oracle DB oracle-server i386.rpm 162MB oracle-server-prod rhgps.x86_64.rpm 1017MB
Recommendations / Observations Sysadmin and DBA collaborate to prepare RPM of your way of doing Oracle DBA can prepare and maintain their own scripts / utilities RPM package. Sysadmin can prepare and maintain their own custom Red Hat CD Easy to leverage one project for the next Red Hat & TPS can meld for highly repeatable, productized deliverables
Thank you Any questions?