[ELGIS] Getting started with mock..

Mathieu Baudier mbaudier at argeo.org
Thu Nov 10 01:35:29 EST 2011


> On the ELGIS wiki page it says to ask for tips for starting with mock - here I am :)  I found the config file examples but am currently digging for tutorials.  I'm sure I'll find something soon, but wanted to ask here first.

# RPMBUILD
If you want to develop new packages, you can start by setting up an
RPM build environment without mock, as Nikolaos has described in his
previous mail.
You will get a better feeling of what building/rebuilding RPMs is
about, and you can iterate more quickly than with mock when developing
the spec file and the necessary patches on the code.

There is also an interesting reference on the CentOS wiki:
http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment
(and http://wiki.centos.org/HowTos/RebuildSRPM)

# MOCK
When building in mock the same mechanism with rpmbuild etc. is used,
but a new chrooted environment is created where only the packages
required for the build will be installed and the build is started
within this environment.
This ensures that the spec files define all dependencies and makes for
reproducible builds.

1. Install mock from EPEL
yum install mock
(doesn't work on RHEL Desktop, because it lacks some dependencies)

2. Add you regular user to the mock group
sudo usermod -a -G mock myusername
(log out / log in in order to make sure that this change is taken into account)

3. You then need to define a mock configuration with the repositories
you want to use.

You will find the mock configuration files used for ELGIS here:
https://projects.argeo.org/elgis/svn/factory/trunk/modules/org.argeo.elgis.rpmfactory/files/etc/mock
(use the elgis-6-testing* ones)

Copy them to /etc/mock (or to a separate directory that you will pass
to mock as argument).

4. To rebuild an SRPM
mock -r elgis-6-testing-x86_64 --rebuild /path/to/srpm

Tip: use the --debug option to see all the build information, or tail
/var/lib/mock/elgis-6-testing-x86_64/result/build.log

In order to create the SRPM from file, you can either put the
SPEC/SOURCES file in the rpmbuild environment (cf. Nikolaos mail) and
run:
rpmbuild --nodeps -bs /path/to/myspecfile.spec

or use mock --buildsrpm
(I haven't tested it yet, because it was not available in the mock
from CentOS that we used for ELGIS5, but it seems more consistent and
there is no reason why it shouldn't work)

5. When the build is completed your RPMs are available here:
/var/lib/mock/elgis-6-testing-x86_64/result/

while the related rpmbuild top dir is here:
/var/lib/mock/elgis-6-testing-x86_64/root/builddir/build/

If something went wrong, you can switch to the chroot environment in a shell:
mock -r elgis-6-testing-x86_64 --shell

and work on the RPM just as described by Nikolaos with rpmbuild but
within the chrooted environment.

# NOTES
- if you want to contribute new packages, building them in mock first
is not "mandatory" as such, but I *very* much appreciate it.
Tracking down each missing dependency by relaunching the whole mock
build is not the funniest part and if you don't do it in mock before
contributing, I will be the one who will have to do it before
publishing.

- the ELGIS spec files are here:
https://projects.argeo.org/elgis/svn/factory/trunk/rpmbuild

You can check out them somewhere with subversion:
svn co https://projects.argeo.org/elgis/svn/factory/trunk elgis-testing

The directory structure may soon change to be more in line with other
spec files repositories (e.g. Volker's one on GitHub), but the
information is here and versioned.
If you want to improve existing packages, please provide diffs against
the latest version of trunk.

Cheers,

Mathieu


More information about the el mailing list