Pbuilder

From Wikitech
(Difference between revisions)
Jump to: navigation, search
m
(modernize)
Line 2: Line 2:
 
'''pbuilder''' is a tool to automatically build packages in a clean chroot of an arbitrary Debian / Ubuntu distribution. By abstracting away the particulars of your environment, it helps ensure that your packages install correctly on other machines.
 
'''pbuilder''' is a tool to automatically build packages in a clean chroot of an arbitrary Debian / Ubuntu distribution. By abstracting away the particulars of your environment, it helps ensure that your packages install correctly on other machines.
  
=== Setup ===
+
=== Setting up your environment ===
Start by getting your hands on a Labs instance with a <tt>misc::package-builder</tt> Puppet role (you can add this role if necessary). This will drop a clean install image in <tt>/var/cache/pbuilder/''distribution''.tgz</tt>. If you prefer to do so, you can create a clean install image manually using <tt>pbuilder create</tt>. For example:
+
Start by getting your hands on a Labs instance with a <tt>misc::package-builder</tt> Puppet role (you can add this role if necessary). This will drop a clean install image in <tt>/var/cache/pbuilder/''distribution''.tgz</tt>. (Alternately, you can create a clean install image manually using <tt>pbuilder create</tt>.)
  
# pbuilder create --distribution feisty
+
Create a <tt>packaging/</tt> directory in your home directory and copy the image there. Next, configure some useful defaults in <tt>~/.pbuilderrc</tt> (creating it if it does not exist):
  
Notably, pbuilder doesn't set up a correct APT <tt>/etc/apt/sources.list</tt> in the chroot image, so it's best to use <tt>pbuilder login --save-after-login</tt> once after creating it, and replace its sources.list with an actual correct one.
+
  DEBEMAIL="Your Name <your.email@wikimedia.org>"
 +
  BASETGZ="/home/yourname/packaging/precise.tgz"  # Path must be canonical and absolute
 +
  APTCONFDIR="/etc/apt" # Use host environment's apt config -- see below for caveat
 +
  DEBBUILDOPTS="-sa"    # Include source
  
=== Building ===
+
The <tt>APTCONFDIR</tt> copies your apt configuration to the build environment. This will add the Wikimedia apt repositories, which allows your package to have dependencies on other packages in our repository. However, this only works if your host is the running the same distribution as the one you are targeting. If you added the APTCONFDIR line, you should update the image, which will complete the build environment's apt configuration:
Then, when you want to build a package using this distribution image, use:
+
  
# pbuilder build --basetgz /var/cache/pbuilder/''distribution''.tgz ''package.dsc''
+
  # sudo pbuilder update --override-config
  
If all goes well, you'll find the resulting package(s) in <tt>/var/cache/pbuilder/result</tt>.
+
If you are targeting a different distribution or wish to include other repositories, you can declare them in <tt>pbuilderrc</tt> (see <tt>man pbuilderrc</tt>), or you can configure your build environment in an interactive session, by running <tt>pbuilder login --save-after-login</tt> and making the required modifications by hand.
  
 +
=== Build ===
 +
When you are ready to build a package, use:
 +
 +
# sudo pbuilder build ''package.dsc''
 +
 +
If you would like to use a different base image, you can specify it using the <tt>--basetgz</tt> command-line argument. (Other defaults are similarly overridable -- see the man page for pbuilder.) If all goes well, you'll find the resulting package(s) in <tt>/var/cache/pbuilder/result</tt>.
 +
 +
=== New distribution images ===
 
Create a new distribution image using another filename:
 
Create a new distribution image using another filename:
 
  # pbuilder create --distribution feisty --debootstrapopts --arch --debootstrapopts i386 --basetgz /var/cache/pbuilder/base-i386.tgz
 
  # pbuilder create --distribution feisty --debootstrapopts --arch --debootstrapopts i386 --basetgz /var/cache/pbuilder/base-i386.tgz
Line 23: Line 33:
  
 
=== Modifying the base image ===
 
=== Modifying the base image ===
To change something in the base image, for example to add an APT repository, use:
+
As noted earlier, the easiest way to change something in the base image is via an interactive session:
 
  # pbuilder login --save-after-login
 
  # pbuilder login --save-after-login
  
 
== External documentation ==
 
== External documentation ==
* [http://pbuilder.alioth.debian.org/pbuilder-doc.pdf pbuilder documentation]
+
* [https://wiki.ubuntu.com/PbuilderHowto Pbuilder Howto] (Ubuntu-specific)
 +
* [http://pbuilder.alioth.debian.org/pbuilder-doc.pdf Pbuilder documentation] (PDF)
 +
* [http://manpages.ubuntu.com/manpages/precise/man8/pbuilder.8.html pbuilder man page]
 +
* [http://manpages.ubuntu.com/manpages/precise/en/man5/pbuilderrc.5.html pbuilderrc man page]
 +
 
  
 
[[Category:Ubuntu]] [[Category:Package management]]
 
[[Category:Ubuntu]] [[Category:Package management]]

Revision as of 20:55, 16 August 2012

Update: If you are used to building packages on ragweed, note that the current recommendation is to use a Labs instance.

pbuilder is a tool to automatically build packages in a clean chroot of an arbitrary Debian / Ubuntu distribution. By abstracting away the particulars of your environment, it helps ensure that your packages install correctly on other machines.

Contents

Setting up your environment

Start by getting your hands on a Labs instance with a misc::package-builder Puppet role (you can add this role if necessary). This will drop a clean install image in /var/cache/pbuilder/distribution.tgz. (Alternately, you can create a clean install image manually using pbuilder create.)

Create a packaging/ directory in your home directory and copy the image there. Next, configure some useful defaults in ~/.pbuilderrc (creating it if it does not exist):

 DEBEMAIL="Your Name <your.email@wikimedia.org>"
 BASETGZ="/home/yourname/packaging/precise.tgz"  # Path must be canonical and absolute
 APTCONFDIR="/etc/apt" # Use host environment's apt config -- see below for caveat
 DEBBUILDOPTS="-sa"    # Include source

The APTCONFDIR copies your apt configuration to the build environment. This will add the Wikimedia apt repositories, which allows your package to have dependencies on other packages in our repository. However, this only works if your host is the running the same distribution as the one you are targeting. If you added the APTCONFDIR line, you should update the image, which will complete the build environment's apt configuration:

 # sudo pbuilder update --override-config

If you are targeting a different distribution or wish to include other repositories, you can declare them in pbuilderrc (see man pbuilderrc), or you can configure your build environment in an interactive session, by running pbuilder login --save-after-login and making the required modifications by hand.

Build

When you are ready to build a package, use:

# sudo pbuilder build package.dsc

If you would like to use a different base image, you can specify it using the --basetgz command-line argument. (Other defaults are similarly overridable -- see the man page for pbuilder.) If all goes well, you'll find the resulting package(s) in /var/cache/pbuilder/result.

New distribution images

Create a new distribution image using another filename:

# pbuilder create --distribution feisty --debootstrapopts --arch --debootstrapopts i386 --basetgz /var/cache/pbuilder/base-i386.tgz

Then to build a 32 bit package:

# linux32 pbuilder build --basetgz /var/cache/pbuilder/base-i386.tgz --debbuildopts "-sa" package.dsc

The debbuildopts argument forces the inclusion of the package source, a requirement for inclusion in the Wikimedia repository.

Modifying the base image

As noted earlier, the easiest way to change something in the base image is via an interactive session:

# pbuilder login --save-after-login

External documentation

Personal tools
Namespaces

Variants
Actions
Navigation
Ops documentation
Wiki
Toolbox