Workshop: Advanced Packaging Miroslav Suchý <msuchy@redhat.com>
Workshop Overview Assumptions You built at least one RPM package. Hopefully you are familiar with Mock Limitations This workshop skips common problems and shows only variety of tips and trick which are hard to spot (or easy to skip) in documentations. Information Feel free to ask question
Dynamic macro The internal Lua interpreter can be used for dynamic macro content creation: %{lua: print("Requires: foo >= 1.2")} Source: http://www.rpm.org/wiki/PackagerDocs/RpmLua
%pretrans Can be run during kickstart No packages installed yet. Not even shell. You should use lua (embedded in rpm) %pre -p <lua> print("Hello from Lua") Source: http://www.rpm.org/wiki/PackagerDocs/RpmLua
Triggers %triggerin –- sendmail ln -sf /usr/bin/sendmail /etc/mymailer/mailer %trigger{un|in|postun} Source: http://rpm.org/api/4.4.2.2/triggers.html
Tags are macros License: BSD This is tag %build echo %{license} Print BSD Can sometimes work in reverse. i.e. you can redefine %name, which change %buildroot, but does not change actual package name.
Saving state between scriptlets %pre touch %{_localstatedir}/lib/rpm- state/%{name}.DoSomethingLater %posttrans if [ -e %{_localstatedir}/lib/rpm- state/%{name}.DoSomethingLater ]; then # do some conditional stuff rm -f %{_localstatedir}/lib/rpm- state/%{name}.DoSomethingLater fi Source: https://fedoraproject.org/wiki/Packaging:ScriptletSnippets
Create user and group Users can come from NIC or LDAP. Use: Requires(pre): shadow-utils %pre getent group GROUPNAME >/dev/null || \ groupadd -r GROUPNAME getent passwd USERNAME >/dev/null || \ useradd -r -g GROUPNAME -d HOMEDIR -s /sbin/nologin \ -c "Useful comment about the purpose of this account" \ USERNAME exit 0 Source: https://fedoraproject.org/wiki/Packaging:UsersAndGroups?rd=Packaging/UsersAndGr oups
Verbose file listing rpm -qplv some.rpm -rwxr-xr-x 1 root root 3371 Feb 4 23:01 /usr/sbin/rpmconf drwxr-xr-x 2 root root 0 Feb 4 23:01 /usr/share/licenses/rpmconf -rw-r--r-- 1 root root 35147 Dec 1 13:08 /usr/share/licenses/rpmconf/LICENSE -rw-r--r-- 1 root root 1424 Feb 4 23:01 /usr/share/man/man8/rpmconf.8.gz
Renaming package Use both Provides and Obsoletes Name: bar Version: 1.0 Release: 4%{?dist} Provides: foo = %{version}-%{release} Obsoletes: foo <= 1.0-4 # Important: We set the Obsoletes release to 4 to be higher than the previous Release: 3%{?dist} Source: https://fedoraproject.org/wiki/Packaging:Guidelines#Renaming.2FReplacing_Existing_Packages
Symlinks Relative symlinks: ln -s ./bar %{buildroot}/bin/foo Absolute Symlinks ln -s %{_bindir}/bar %{buildroot}/bin/foo Can break in buildtime or check phase. Source: https://fedoraproject.org/wiki/Packaging:Guidelines#Symlinks
Ghost files Declare that files are owned by package Not actually installed, but removed when package uninstalled. %install touch $RPM_BUILD_ROOT%{_localstatedir}/log/blather.log … %files %ghost %{_localstatedir}/log/blather.log Source: http://www.rpm.org/max-rpm-snapshot/s1-rpm-inside-files-list-directives.html
Directories inside /run Create %{_tmpfilesdir}/%{name}.conf d /run/NAME PERM USER GROUP - Source1: %{name}-tmpfiles.conf %install mkdir -p %{buildroot}%{_tmpfilesdir} install -m 0644 %{SOURCE1} %{buildroot}%{_tmpfilesdir}/%{name}.conf # The next two lines may not be needed if the upstream's install script creates them mkdir -p %{buildroot}/run install -d -m 0755 %{buildroot}/run/%{name}/ %files %dir /run/%{name}/ %{_tmpfilesdir}/%{name}.conf Source: https://fedoraproject.org/wiki/Packaging:Tmpfiles.d
Rpmlint / fedora-review Guidelines evolves. Every few years: Run rpmlint on spec and binary packages. fedora-review -rn some.src.rpm
nosrc.rpm NoSource: 0, 1 Source package, but without Source0 and Source1 files. Useful when you cannot distribute source (e.g. OracleDB). See http://developerblog.redhat.com/2014/12/10/how-to-package- proprietary-software/
mock mock -r fedora-23-x86_64 some.src.rpm Use /etc/mock/fedora-23-x86_64.cfg mock -r ./custom-fedora-23-x86_64.cfg some.src Use $PWD/custom-fedora-23-x86_64.cfg
Mock customization /etc/mock/site-defaults.cfg All tunables with comments. ~/.mock/user.cfg Your personal changes.
Mock building in memory Can reduce buildtime to 16% (small pkgs) – 70 % (big packages) config_opts['plugin_conf']['tmpfs_enable'] = True config_opts['plugin_conf']['tmpfs_opts']['max_fs_size'] = '50g' Source: http://miroslav.suchy.cz/blog/archives/2015/05/28/increase_mock_performance_- _build_packages_in_memory/
Mock and LVM config_opts['plugin_conf']['root_cache_enable'] = False config_opts['plugin_conf']['lvm_root_enable'] = True config_opts['plugin_conf']['lvm_root_opts'] = { 'volume_group': 'my-volume-group', 'size': '8G', 'pool_name': 'mock', 'check_size': True, } Source: https://fedoraproject.org/wiki/Mock/Plugin/LvmRoot
Mock shell mock –chroot ls * No shell expansion well there is if there is only one arg eg. Mock –chroot 'ls *' mock –shell ls '*' Shell expanded in chroot. mock –shell Gives you shell in chroot
Mock --copyin Mock -r fedora-23-x86_64 --init Mock –copyin foo.tar.gz /builddir/build/SOURCES/ Mock -r fedora-23-x86_64 --no-clean some.nosrc.rpm
Mock-scm dnf install mock-scm mock -r fedora-22-x86_64 --scm-enable \ --scm-option method=git \ --scm-option package=rpmconf \ --scm-option git_get=set \ --scm-option spec=rpmconf.spec \ --scm-option branch=master --scm-option write_tar=True --scm-option git_get='git clone https://github.com/xsuchy/rpmconf.git'
Koji config Koji mock-config --task=XX Fedpkg mock-config
Secondary arch ppc-koji arm-koji s390-koji Part of fedora-packager package.
rpmdev-* rpmdev-bumpspec foo.spec rpmdev-vercmp 1.2.3 1.2.a rpmdev-extract foo.src.rpm spectool –-list-files foo.spec
Tito tito init tito tag tito build –rpm tito build –rpm –test tito release fedora-git man tito, tito.props, releasers.conf
SCL dnf install scl-utils scl-utils-build spec2scl spec2scl foo.spec > foo-slc.spec