RPM/Mock
Using Mock
Init the chroot environment
CentOS 5
mock centos-5-x86_64 --init
CentOS 6
mock centos-6-x86_64 --init
Install a package manually
CentOS 5
mock centos-5-x86_64 --install <PACKAGE>
CentOS 6
mock centos-6-x86_64 --install <PACKAGE>
Run command on chroot
CentOS 5
mock centos-5-x86_64 --chroot <CMD>
CentOS 6
mock centos-6-x86_64 --chroot <CMD>
Build binary RPMs from SRPM
CentOS 5
mock centos-5-x86_64 --rebuild PACKAGE.src.rpm
CentOS 6
mock centos-6-x86_64 --rebuild PACKAGE.src.rpm
Mock Config Example
Remi Collet
As I have a new builder, I spend some time to optimize my configuration.
Mainly to use the space available in tpmfs (up to 6Gio), rather than some disk space (which is slow and noisy).
Before, mock launch the build using space (basedir) in /var/lib/mock (a stripped LV for me).
To free the build space used as soon as possible, I use the cleanup_on_success option. But this doesn't work because of a little bug in mock (#668222), until I find a simple workaround patch (which need to be improved).
I also use the createrepo_on_rpms option and configure the resultdir as a repository which will be used by next build. This is really useful, as this avoid to update my main repository (which is quite big, so quite long to update).
There is also another little bug in mock (#668278), which impose me to use the root account to clean the resultdir (I hope this will be fixed by upstream).
So, here is one of my mock configuration file (for fedora 14 x86_64) :
config_opts['root'] = 'fc14x' config_opts['target_arch'] = 'x86_64' config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build' config_opts['dist'] = 'fc14' # only useful for --resultdir variable subst config_opts['plugin_conf']['ccache_enable'] = True config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '1G' config_opts['plugin_conf']['ccache_opts']['dir'] = "/dev/shm/ccache.fc14x/"
config_opts['basedir'] = '/dev/shm/' config_opts['resultdir'] = "/var/lib/mock/fc14x" config_opts['cleanup_on_success'] = True config_opts['cleanup_on_failure'] = False config_opts['createrepo_on_rpms'] = True config_opts['createrepo_command'] = '/usr/bin/createrepo -d -q -x *.src.rpm' config_opts['macros']['%_topdir']="/builddir/build" config_opts['macros']['%_smp_mflags']="-j3" config_opts['macros']['%vendor']="Remi Collet" config_opts['macros']['%packager']="http://blog.famillecollet.com/" config_opts['macros']['%dist']=".fc14.remi" config_opts['macros']['%fedora']="14" config_opts['macros']['%_with_ibase']="1" config_opts['macros']['%_with_oci8']="1" config_opts['macros']['%runselftest']="1" config_opts['yum.conf'] = """ [main] cachedir=/var/cache/yum debuglevel=1 reposdir=/dev/null logfile=/var/log/yum.log retries=20 obsoletes=1 gpgcheck=0 assumeyes=1 # repositories [fedora] name=fedora mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-14&arch=x86_64 [updates-released] name=updates mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f14&arch=x86_64 [remi] name=remi public baseurl=file:/home/rpmbuild/site/rpms/fedora/14/remi/x86_64/ [remi-priv] name=remi prive baseurl=file:/home/rpmbuild/site/rpms/priv/x86_64/ [result] name=result baseurl=file:/var/lib/mock/fc14x/ """
I hopes it could help others, as it seems to work really well.
Here is an exemple :
$ mock --configdir=/var/lib/mock/etc -r fc14x rebuild php-phpunit-PHPUnit-3.5.7-1.remi.src.rpm
INFO: mock.py version 1.1.7 starting...
State Changed: init plugins
INFO: selinux enabled
State Changed: start
INFO: Start(/home/extras/SRPMS/php-phpunit-PHPUnit-3.5.7-1.remi.src.rpm) Config(fc14x)
State Changed: lock buildroot
State Changed: clean
State Changed: init
State Changed: lock buildroot
Mock Version: 1.1.7
INFO: Mock Version: 1.1.7
INFO: enabled root cache
State Changed: unpacking root cache
INFO: enabled yum cache
State Changed: cleaning yum metadata
INFO: enabled ccache
State Changed: running yum
State Changed: setup
State Changed: build
INFO: Done(/home/extras/SRPMS/php-phpunit-PHPUnit-3.5.7-1.remi.src.rpm) Config(fc14x) 0 minutes 13 seconds
INFO: Results and/or logs in: /var/lib/mock/fc14x
INFO: Cleaning up build root ('clean_on_success=True')
State Changed: lock buildroot
State Changed: clean
INFO: chroot (/dev/shm/fc14x) unlocked and deleted
INFO: Running createrepo on binary rpms in resultdir
This is a small and simple package, rpmbuild take around 4", so I can say that mock overhead is only 9" with this configuration. Really acceptable. No reason to keep using rpmbuild and definitively prefer the sane build environment provided by mock.
Johnny Hughes
Mock configuration for CentOS 5 x86_64
#!/usr/bin/python -tt import os config_opts['root'] = 'centos-5-x86_64-os-ft-extras' config_opts['basedir'] = '/var/lib/mock/' config_opts['chroot'] = '/usr/sbin/mock-helper chroot' config_opts['mount'] = '/usr/sbin/mock-helper mount' config_opts['umount'] = '/usr/sbin/mock-helper umount' config_opts['rm'] = '/usr/sbin/mock-helper rm' config_opts['mknod'] = '/usr/sbin/mock-helper mknod' config_opts['yum'] = '/usr/sbin/mock-helper yum' config_opts['runuser'] = '/sbin/runuser' config_opts['buildgroup'] = 'build' config_opts['chrootuser'] = 'mockbuild' config_opts['chrootgroup'] = 'mockbuild' config_opts['chrootuid'] = os.geteuid() config_opts['chrootgid'] = os.getegid() config_opts['chroothome'] = '/builddir' config_opts['clean'] = True config_opts['target_arch'] = 'x86_64' config_opts['yum.conf'] = """ [main] cachedir=/var/cache/yum debuglevel=1 logfile=/var/log/yum.log reposdir=/dev/null retries=20 obsoletes=1 gpgcheck=0 assumeyes=1 exclude=[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz]*.i?86 g[abcdefghijkmnopqrstuvwxyz]*.i?86 glib2*.i?86 glib-*.i?86 glib.i?86 # repos [base] name=base baseurl=http://192.168.0.26/5/os/x86_64/ [updates] name=updates baseurl=http://192.168.0.26/5/updates/x86_64/ [fasttrack] name=fasttrack baseurl=http://192.168.0.26/5/fasttrack/x86_64/ [extras] name=extras baseurl=http://192.168.0.26/5/extras/x86_64/ [extrasStaged] name=extrasStaged baseurl=file:///home/buildcentos/rebuilder/extrasStaged/ [buildsys] name=buildsys baseurl=http://dev.centos.org/centos/buildsys/5/ """ config_opts['macros'] = """ %_topdir /builddir/build %_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm # Change the next two lines to reflect yourself. %packager Johnny Hughes <johnny@centos.org> %vendor CentOS # please change this to reflect the Distro Tree and Repo hosting packages! #%dist .el5.centos %centos_ver 5 %rhel 5 %_unpackaged_files_terminate_build 0 %_missing_doc_files_terminate_build 0 """
Mock configuration for CentOS 5 i386
#!/usr/bin/python -tt import os config_opts['root'] = 'centos-5-i386-os-ft-extras' config_opts['basedir'] = '/var/lib/mock/' config_opts['chroot'] = '/usr/sbin/mock-helper chroot' config_opts['mount'] = '/usr/sbin/mock-helper mount' config_opts['umount'] = '/usr/sbin/mock-helper umount' config_opts['rm'] = '/usr/sbin/mock-helper rm' config_opts['mknod'] = '/usr/sbin/mock-helper mknod' config_opts['yum'] = '/usr/sbin/mock-helper yum' config_opts['runuser'] = '/sbin/runuser' config_opts['buildgroup'] = 'build' config_opts['chrootuser'] = 'mockbuild' config_opts['chrootgroup'] = 'mockbuild' config_opts['chrootuid'] = os.geteuid() config_opts['chrootgid'] = os.getegid() config_opts['chroothome'] = '/builddir' config_opts['clean'] = True config_opts['target_arch'] = 'i386' config_opts['yum.conf'] = """ [main] cachedir=/var/cache/yum debuglevel=1 logfile=/var/log/yum.log reposdir=/dev/null retries=20 obsoletes=1 gpgcheck=0 assumeyes=1 exclude=*.x86_64 # repos [base] name=base baseurl=http://192.168.0.26/5/os/i386/ [updates] name=updates baseurl=http://192.168.0.26/5/updates/i386/ [fasttrack] name=fasttrack baseurl=http://192.168.0.26/5/fasttrack/i386/ [extras] name=extras baseurl=http://192.168.0.26/5/extras/i386/ [extrasStaged] name=extrasStaged baseurl=file:///home/buildcentos/rebuilder/extrasStaged/ [buildsys] name=buildsys baseurl=http://dev.centos.org/centos/buildsys/5/ """ config_opts['macros'] = """ %_topdir /builddir/build %_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm # Change the next two lines to reflect yourself. %packager Johnny Hughes <johnny@centos.org> %vendor CentOS # please change this to reflect the Distro Tree and Repo hosting packages! #%dist .el5.centos %centos_ver 5 %rhel 5 %_unpackaged_files_terminate_build 0 %_missing_doc_files_terminate_build 0 """