For me, some of the build tools are used so seldom that when things go pear shaped, it is more often a mad scramble to put out fires. Being big on devops, I wanted to be able to run the all packaging scripts on my own setup (or any other developer’s setup at that) or VMs. Particularly when issues arise, be it dependencies related or error in the packaging process, having a Vagrant box at hand with all the production trimmings mitigate the need to use production Jenkins server for debugging where possible. This is a good thing!
This is a blog post that serves as a quick primer for myself and anybody who feels like dabbling in old school package building for their release management process with a modern twist.
You will need Vagrant, Virtualbox and a couple of reliable Ubuntu and Centos Vagrant boxes. Some knowledge of deb and redhat build scaffolding is also helpful.
Getting started with chroot & sbuild
The following steps will yield a precise64 chroot environment.
Note that I was unsuccessful with setting up sbuild using Vagrant provisioning scripts. So the following steps are executed after the VM has been provisioned.
sudo apt-get update sudo apt-get install sbuild sudo sbuild-createchroot --arch=amd64 precise /srv/chroot/precise-amd64 http://no.archive.ubuntu.com/ubuntu --components=main,universe sudo sbuild-adduser vagrant cp /usr/share/doc/sbuild/examples/example.sbuildrc /home/vagrant/.sbuildrc
The above steps will create a symlink folder that resides in
/etc/sbuild/chroot/precaise-amd64-sbuild that points to
/srv/chroot/precise-amd64. You can now list the available chroot by doing
and enter the precise64 jail by doing
schroot -c precise-amd64-sbuild
Ideally now is a good time to generate a gpg key.
sudo sbuild-update --keygen
If you run into entropy issue and require more bytes, put the keygen process in the background, then do the following
sudo apt-get install rng-tools sudo rngd -r /dev/urandom
At this point, you have almost a happy sbuild setup. However, you probably want to mount a folder to the chroot environments, accessible by the vagrant user.
Add the following line to
/vagrant /vagrant none rw,bind 0 0
Doing it this way, the mounted Vagrant folder will be accessible by the chroot environments with the default vagrant user.
With using sbuild, it is as simple as issuing the following command.
sbuild --arch-all -v -m 'vagrant user ' --arch "amd64" -d "precise" app_*.dsc
Without -c parameter specified, sbuild will search the default folder
/etc/sbuild/chroot/ for an environment matching the architecture and distribution.
Getting started with with chroot & mock
Setting up mock is slightly less complicated. With EPEL repo at hand, do…
sudo yum install mock python-ctypes sudo usermod -G mock vagrant
mock will install a big bunch of chroot configurations residing in
You can clean and initialise the chroot environment each time as you need them. There are also no mounting of folders to fiddle with. Source and result folders are specified as parameters with the mock command.
mock -v -r epel-6-x86_64--clean mock -v -r epel-6-x86_64 --init mock -v -r epel-6-x86_64 --no-clean --no-cleanup-after --buildsrpm \ --spec “app.spec" \ --source "$(pwd)/source" \ --resultdir "$(pwd)/result"
Vagrant boxes for reuse
Since mock installs a whole bunch of dependencies on the Centos VM, the resulting box will very quickly blow up to around 7.8 GB in size. Likewise, the aforementioned Ubuntu box with two chroot and sbuild will be around 2.2 GB in size. In addition, provisioning these boxes are time consuming. Therefore I highly recommend that once the VMs are provisioned, a new set of Vagrant boxes are to be created and set aside for reuse.
See https://docs.vagrantup.com/v2/virtualbox/boxes.html for details.