From Fedora Project Wiki

m (1 revision(s))
(the group is created by rpm when installing mock, isn't it?)
(45 intermediate revisions by 17 users not shown)
Line 1: Line 1:
{{autolang|base=yes}}
= Mock =
= Mock =


Mock creates chroots and builds packages in them. Its only task is to reliably populate a chroot and attempt to build a package in that chroot.
Mock is a tool for building packages. It can build packages for different architectures and different Fedora or RHEL versions than the build host has. Mock creates chroots and builds packages in them. Its only task is to reliably populate a chroot and attempt to build a package in that chroot.
 
Mock also offers a multi-package tool, mockchain, that can build chains of packages that depend on each other.
 
Mock is capable of building SRPMs  from source configuration management if the mock-scm package is present, then building the SRPM into RPMs. See --scm-enable in the documentation.


== Status ==
== Status ==
Mock is currently being used for all Fedora builds. It is called by [[Projects/Plague|  Plague]] (<=FC-6) and [[Koji|  Koji]]  (>=F-7) to build chroots and packages.
 
Mock is currently being used for all Fedora builds. It is called by [[Koji]] and [https://copr.fedoraproject.org Copr] to build chroots and packages.
 
== Release Notes ==
* [[1.2.14]]
* [[1.2.13]]


== Download ==
== Download ==
https://fedorahosted.org/mock/ has all the latest builds.  It can be installed with "yum install mock".


To check out the current code:
If you want to contribute to code, please checkout https://fedorahosted.org/mock/ for more informations.
* <code>git clone git://git.fedorahosted.org/git/mock.git mock</code>
 
Otherwise just run "dnf install mock".


== Setup ==
== Setup ==
All users that are to use mock must be added to the 'mock' group.


All users that are to use mock must be added to the mock group.
<code>usermod -a -G mock [User name]</code>


Configuration files are in /etc/mock.  Mock versions 0.8.0 and higher cache the downloaded rpm packages (via the yum_cache plugin), which speeds up subsequent builds by a considerable margin. Nevertheless, you may wish to change the default configuration to point to local repositories to speed up builds.
Configuration files are in /etc/mock.  Mock versions 0.8.0 and higher cache the downloaded rpm packages (via the yum_cache plugin), which speeds up subsequent builds by a considerable margin. Nevertheless, you may wish to change the default configuration to point to local repositories to speed up builds.
Line 20: Line 32:
By default, builds are done in /var/lib/mock, so be sure you have room. Starting with mock 0.8.0 and higher, you can change this via the 'basedir' config option.
By default, builds are done in /var/lib/mock, so be sure you have room. Starting with mock 0.8.0 and higher, you can change this via the 'basedir' config option.


== Using ==
== Plugins ==
<pre>
Usage:
usage:
mock [options]  {init|clean}
mock [options]  [rebuild]  /path/to/srpm(s)
mock [options]  {shell|chroot} <cmd>
mock [options]  installdeps {SRPM|RPM}
mock [options]  install PACKAGE
commands:
rebuild    - build the specified SRPM(s) [default command]
chroot      - run the specified command within the chroot
shell      - run an interactive shell within specified chroot
clean      - clean out the specified chroot
init        - initialize the chroot, do not build anything
installdeps - install build dependencies for a specified SRPM
install    - install packages using yum


Options:
* [[Projects/Mock/Plugin/BindMount|bind_mount]] - bind mountpoints inside the chroot
--version            show program's version number and exit
* [[Projects/Mock/Plugin/CCache|ccache]] - compiler cache plugin
-h, --help            show this help message and exit
* [[Projects/Mock/Plugin/ChrootScan|chroot_scan]] - allows you to retrieve build artifacts from buildroot (e.g. additional logs, coredumps)
-r CHROOT            chroot name/config file name default: default
* [[Projects/Mock/Plugin/CompressLogs|compress_logs]] - compress logs
--no-clean            do not clean chroot before building
* [[Projects/Mock/Plugin/LvmRoot|lvm_root]] - caching buildroots using LVM
--cleanup-after      Clean chroot after building. Use with --resultdir.
* [[Projects/Mock/Plugin/Mount|mount]] - allows you to mount directories into chroot
Only active for 'rebuild'.
* [[Projects/Mock/Plugin/PackageState|package_state]] - dumps list of available and installed packages
--no-cleanup-after    Dont clean chroot after building. If automatic cleanup
* [[Projects/Mock/Plugin/PMRequest|pm_request]] - Executes package manager commands requested by processes runninng in the chroot.
is enabled, use this to disable.
* [[Projects/Mock/Plugin/RootCache|root_cache]] - cache buildroots (as tar file).
--arch=ARCH          target build arch
* [[Projects/Mock/Plugin/Scm|scm]] - SCM integration module - builds directly from Git or Svn.
--resultdir=RESULTDIR
* [[Projects/Mock/Plugin/SELinux|selinux]] - on SELinux enabled box, this plugin will pretend, that SELinux is disabled in build environment.
path for resulting files to be put
* [[Projects/Mock/Plugin/Sign|sign]] - call command on the produced rpm.
--uniqueext=UNIQUEEXT
* [[Projects/Mock/Plugin/Tmpfs|tmpfs]] - mount buildroot directory as tmpfs
Arbitrary, unique extension to append to buildroot
* [[Projects/Mock/Plugin/YumCache|yum_cache]] - mount /var/cache/yum of your machine to chroot
directory name
--configdir=CONFIGDIR
Change where config files are found
--rpmbuild_timeout=RPMBUILD_TIMEOUT
Fail build if rpmbuild takes longer than 'timeout'
seconds
--enable-plugin=ENABLED_PLUGINS
Enable plugin. Currently-available plugins: ('ccache',
'yum_cache', 'root_cache', 'bind_mount')
--disable-plugin=DISABLED_PLUGINS
Disable plugin. Currently-available plugins:
('ccache', 'yum_cache', 'root_cache', 'bind_mount')
</pre>


For example, to rebuild a package for i386 on the development branch of Fedora:
== Using Mock outside your git sandbox ==
Create your SRPM using 'rpmbuild -bs'. Then change to the directory where your srpm was created.


* <code>mock rebuild -r fedora-devel-i386 /path/to/rpm</code>
Now you can start mock with


See /etc/mock for the available targets. If you have the bash-completion package installed, it will tab complete the targets for you.
<code>mock -r <configname> rebuild package-1.2-3.src.rpm</code>
 
where <configname> is the name of a configuration from /etc/mock/, without the /etc/mock path prefix and without the .cfg suffix.
 
Note that you can track the progress of mock using the logs stored in <code>/var/lib/mock/<configfile>/result</code>
 
== Mock on EL 6 and EL 7: Yum, and DNF ==
 
Starting with the Rawhide builds for Fedora 23, Mock requires DNF to run properly. Since not all parts of DNF are available on EL 6 and EL 7, Mock cannot be run there with the default configuration.
 
There are however two workarounds available:
 
* For one time runs it is possible to pass <code>--yum</code> as an option on the command line.
* To make yum the default package manager, a change in <code>/etc/mock/site-defaults.cfg</code> or inside of any <code>/etc/mock/*.cfg</code> file is necessary:
 
<code>config_opts['package_manager'] = 'yum'</code>
 
For more information, please see the [http://miroslav.suchy.cz/blog/archives/2015/05/20/why_mock_does_not_work_on_el_6_and_el7_and_how_to_fix_it/index.html blog entry by Miroslav Suchý].


== Problems ==
== Problems ==
If you encounter a bug running mock, please file it in [http://bugzilla.redhat.com Bugzilla] , product "Fedora Hosted Projects", component mock.
If you encounter a bug running mock, please file it in [https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora&component=mock Bugzilla], product "Fedora", component mock ([https://bugzilla.redhat.com/buglist.cgi?query_format=advanced&product=Fedora&component=mock&bug_status=NEW&bug_status=ASSIGNED&bug_status=MODIFIED&bug_status=ON_DEV&bug_status=ON_QA&bug_status=VERIFIED&bug_status=FAILS_QA&bug_status=RELEASE_PENDING&bug_status=POST Open Bugs]).
 
If your problem is specific to EPEL, then [https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora%20EPEL&component=mock file it] against the "Fedora EPEL" product instead ([https://bugzilla.redhat.com/buglist.cgi?query_format=advanced&product=Fedora%20EPEL&component=mock&bug_status=NEW&bug_status=ASSIGNED&bug_status=MODIFIED&bug_status=ON_DEV&bug_status=ON_QA&bug_status=VERIFIED&bug_status=FAILS_QA&bug_status=RELEASE_PENDING&bug_status=POST Open Bugs]).
 
== Generate custom config file ==
 
Mock main config file is <code>/etc/mock/site-defaults.cfg</code>, which contains all defaults setting and all possible variables you can change.
Then you have <code>/etc/mock/<buildroot>.cfg</code> for various buildroots, which contains settings for yum/dnf which are for various distribution different.
 
When you want to alter the config you may copy one and edit it manually, however if koji is already using such an config, then you can use  '''mock-config --help''' for information how to generate one. E.g.:
koji mock-config --tag f21-build --arch=aarch64  f21
 
You should not alter <code>site-defaults.cfg</code> unless you want to change settings for all users. You should put your changes to <code>~/.mock/user.cfg</code> or to <code>~/.config/mock.cfg</code>.
 
The order of reading and evaluating configuration files is:
 
# /etc/mock/site-defaults.cfg
# /etc/mock/<buildroot>.cfg
# ~/.mock/user.cfg
# ~/.config/mock.cfg (since mock-1.2.15)


== See Also ==
== See Also ==


[[Extras/MockTricks]]  has some useful tips for using mock.<BR>
* [[Using_Mock_to_test_package_builds]]  has some useful tips for using mock.
[[Docs/Drafts/MockSetupUsingLocalMirror]]  Setting up a local mirror using Mock. <BR>
* [[Docs/Drafts/MockSetupUsingLocalMirror]]  Setting up a local mirror using Mock.
[[Legacy/Mock]]  has some useful tips for building packages in mock for older Fedora and Red Hat Linux releases.
* [[Legacy/Mock]]  has some useful tips for building packages in mock for older Fedora and Red Hat Linux releases.
* [http://miroslav.suchy.cz/blog/archives/2015/05/28/increase_mock_performance_-_build_packages_in_memory/index.html Increase Mock performance].

Revision as of 15:47, 21 January 2016

Mock

Mock is a tool for building packages. It can build packages for different architectures and different Fedora or RHEL versions than the build host has. Mock creates chroots and builds packages in them. Its only task is to reliably populate a chroot and attempt to build a package in that chroot.

Mock also offers a multi-package tool, mockchain, that can build chains of packages that depend on each other.

Mock is capable of building SRPMs from source configuration management if the mock-scm package is present, then building the SRPM into RPMs. See --scm-enable in the documentation.

Status

Mock is currently being used for all Fedora builds. It is called by Koji and Copr to build chroots and packages.

Release Notes

Download

If you want to contribute to code, please checkout https://fedorahosted.org/mock/ for more informations.

Otherwise just run "dnf install mock".

Setup

All users that are to use mock must be added to the 'mock' group.

usermod -a -G mock [User name]

Configuration files are in /etc/mock. Mock versions 0.8.0 and higher cache the downloaded rpm packages (via the yum_cache plugin), which speeds up subsequent builds by a considerable margin. Nevertheless, you may wish to change the default configuration to point to local repositories to speed up builds.

By default, builds are done in /var/lib/mock, so be sure you have room. Starting with mock 0.8.0 and higher, you can change this via the 'basedir' config option.

Plugins

  • bind_mount - bind mountpoints inside the chroot
  • ccache - compiler cache plugin
  • chroot_scan - allows you to retrieve build artifacts from buildroot (e.g. additional logs, coredumps)
  • compress_logs - compress logs
  • lvm_root - caching buildroots using LVM
  • mount - allows you to mount directories into chroot
  • package_state - dumps list of available and installed packages
  • pm_request - Executes package manager commands requested by processes runninng in the chroot.
  • root_cache - cache buildroots (as tar file).
  • scm - SCM integration module - builds directly from Git or Svn.
  • selinux - on SELinux enabled box, this plugin will pretend, that SELinux is disabled in build environment.
  • sign - call command on the produced rpm.
  • tmpfs - mount buildroot directory as tmpfs
  • yum_cache - mount /var/cache/yum of your machine to chroot

Using Mock outside your git sandbox

Create your SRPM using 'rpmbuild -bs'. Then change to the directory where your srpm was created.

Now you can start mock with

mock -r <configname> rebuild package-1.2-3.src.rpm

where <configname> is the name of a configuration from /etc/mock/, without the /etc/mock path prefix and without the .cfg suffix.

Note that you can track the progress of mock using the logs stored in /var/lib/mock/<configfile>/result

Mock on EL 6 and EL 7: Yum, and DNF

Starting with the Rawhide builds for Fedora 23, Mock requires DNF to run properly. Since not all parts of DNF are available on EL 6 and EL 7, Mock cannot be run there with the default configuration.

There are however two workarounds available:

  • For one time runs it is possible to pass --yum as an option on the command line.
  • To make yum the default package manager, a change in /etc/mock/site-defaults.cfg or inside of any /etc/mock/*.cfg file is necessary:

config_opts['package_manager'] = 'yum'

For more information, please see the blog entry by Miroslav Suchý.

Problems

If you encounter a bug running mock, please file it in Bugzilla, product "Fedora", component mock (Open Bugs).

If your problem is specific to EPEL, then file it against the "Fedora EPEL" product instead (Open Bugs).

Generate custom config file

Mock main config file is /etc/mock/site-defaults.cfg, which contains all defaults setting and all possible variables you can change. Then you have /etc/mock/<buildroot>.cfg for various buildroots, which contains settings for yum/dnf which are for various distribution different.

When you want to alter the config you may copy one and edit it manually, however if koji is already using such an config, then you can use mock-config --help for information how to generate one. E.g.:

koji mock-config --tag f21-build --arch=aarch64  f21

You should not alter site-defaults.cfg unless you want to change settings for all users. You should put your changes to ~/.mock/user.cfg or to ~/.config/mock.cfg.

The order of reading and evaluating configuration files is:

  1. /etc/mock/site-defaults.cfg
  2. /etc/mock/<buildroot>.cfg
  3. ~/.mock/user.cfg
  4. ~/.config/mock.cfg (since mock-1.2.15)

See Also