ReleaseEngineering/PuppetAgain/HowTo/Build DEBs

From MozillaWiki
Jump to navigation Jump to search

Building

At the moment we don't have any shared resources to build Debian packages. You need to use Ubuntu 12.04 based VM on your laptop.

To build a package in clean-room environment use pbuilder. It uses precreated images to build DEBs in chroot.

Create pbuilder images

Use the following command to create environments.

  • 64 bit
sudo pbuilder --create --distribution precise --architecture amd64 \
    --components "main restricted universe multiverse" \
    --debootstrapopts --variant=buildd \
    --basetgz /var/cache/pbuilder/base-precise-amd64.tgz \
    --mirror http://archive.ubuntu.com/ubuntu \
    --othermirror "deb http://archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse" \
    --othermirror "deb http://archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse"
  • 32 bit
sudo pbuilder --create --distribution precise --architecture i386 \
    --components "main restricted universe multiverse" \
    --debootstrapopts --variant=buildd \
    --basetgz /var/cache/pbuilder/base-precise-i386.tgz \
    --mirror http://archive.ubuntu.com/ubuntu \
    --othermirror "deb http://archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse" \
    --othermirror "deb http://archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse"

Building a package

There are some different ways to build a binary package

Building from orig.tar.gz, debian.tar.gz and dsc

sudo pbuilder --build --distribution precise --architecture amd64 --basetgz /var/cache/pbuilder/base-precise-amd64.tgz\
    --buildresult ./out *.dsc

"out" directory will be populated with files you'll need to import into the repo.

By default if the same upstream version has 2 entries in debian/changelog, packaging tools don't add orig.tar.gz in the *.changes files (used when you import the package). If for some reason you need to add the upstream source into the "changes" file (for example, when you backport some package) pass "-sa" to the packaging tools:

sudo pbuilder --build --distribution precise --architecture amd64 --basetgz /var/cache/pbuilder/base-precise-amd64.tgz \
   --buildresult out --debbuildopts "-sa" *.dsc

Building using git-buildpackage

git-buildpackage allows you to have everything related to a package under version control. Your git checkout contains the following branches needed to build the package:

  • upstream: upstream sources
  • debian: debianization work
  • pristine-tar (optional): binary information needed to recreate orig.tar.gz from git with a proper final checksum

The following config (~/.gbp.conf) file is used:

[DEFAULT]
cleaner = fakeroot debian/rules clean
pristine-tar = True
color = auto

[git-buildpackage]
export-dir = ../build-area/
tarball-dir = ../tarballs/
pbuilder = True
dist = precise

[git-import-orig]
dch = False

The following scenario used to rebuild puppet-2.7.17:

# get Debian's package (apt-cache showsrc puppet|grep ^Vcs-Git:)
git clone git://git.debian.org/git/pkg-puppet/puppet.git
cd puppet
git co -b pristine-tar origin/pristine-tar
git co -b mozilla upstream/2.7.17 # checkout upstream version we need, by tag
git merge debian/2.7.17-1 # merge debian changes for that version, by tag
dch --local mozilla --distribution precise # bump debian/changelog with proper version suffix
git commit -va
# biuld it
ARCH=amd64 BUILDER=pbuilder git-buildpackage --git-upstream-branch=origin/upstream --git-debian-branch=mozilla  # add -sa to include source)
# once you're happy with the package, tag it
ARCH=amd64 BUILDER=pbuilder git-buildpackage --git-upstream-branch=origin/upstream --git-debian-branch=mozilla --git-tag
# to build i386 specific package you need to pass -B to avoid adding orig/debian.tar/gz files into the changes file
ARCH=i386 BUILDER=pbuilder git-buildpackage --git-upstream-branch=origin/upstream --git-debian-branch=mozilla  -B

Building multiple dependent packages

Sometimes you may need to build a package which requires a fresher dependency (library). In this case you need to build the library first and use a temporary local repo. Packaging nodejs is a good example.

Pbuilder can use hooks to run some actions.

  • Add the following entries to your ~/.pbuilderrc
HOOKDIR="$HOME/.pbuilder-hooks"
OTHERMIRROR="deb file://$HOME/debs/packages ./"
BINDMOUNTS="$HOME/debs/packages"
EXTRAPACKAGES="apt-utils"
  • Add a hook to generate package indexes
mkdir ~/.pbuilder-hooks
  • .pbuilder-hooks/D05deps contents:
#!/bin/sh
(cd /home/rail/debs/packages && apt-ftparchive packages . > Packages)
apt-get update
  • chmod 755 .pbuilder-hooks/D05deps
  • edit existing images
sudo pbuilder --login --basetgz /var/cache/pbuilder/base-precise-amd64.tgz --save-after-login
# inside the subshell
apt-get install apt-utils
echo "deb file:///home/rail/debs/packages ./" >> /etc/apt/sources.list
echo 'APT::Get::AllowUnauthenticated "true";' > /etc/apt/apt.conf.d/90mozilla
  • repeat for the i386 image
  • build the library
  • copy the resulting debs into $HOME/debs/packages
  • build the application

Testing

At the moment there is no testing repo. You need to manually install packages to test them.