Pbuilder Setup in Debian

One of main duty of Debian mainter is build package, there are so many ways to doing so. I am here just introduce pbuilder, a simple and straightforwad package tool in Debian.

Installing pbuilder

Use apt to install pbuilder and the hlinux-archive-keyring so we can verify the GPG signature on the archive

$ sudo apt-get install pbuilder debian-archive-keyring

Creating build chroot image

The first step is to create a chroot image that will be used by pbuilder to perform clean builds:

Create a $HOME/.pbuilderrc file with a couple of useful arguments:

# Uncomment and modify if you have a local HTTP proxy
#export http_proxy=http://your-web-proxy:8123
MIRRORSITE=http://ftp.debian.us/debian
DEBBUILDOPTS="-sa"

Building the initial chroot takes a while, but does not need to be performed very many times. Run pbduiler create to create the initial chroot:

$ sudo -E pbuilder create --distribution sid \
     --debootstrapopts --keyring=/usr/share/keyrings/debian-archive-keyring.gpg \
     --debootstrapopts --include=debian-archive-keyring

We use "sudo -E" to preserve the environment variables of the invoking shell, mainly so that the user's local .pbuilderrc is read and not root's .pbuilderrc. We also install the debian-archive-keyring package inside the chroot so that we can verify debian packages installing inside the chroot.

Pre-populate some packages from incoming

Some packages have not made it to the repo yet but are needed to build Go packages properly. Download the debs and copy them to the pbuilder cache:

$ sudo cp *.deb /var/cache/pbuilder/aptcache
$ sudo -E pbuilder --login --save-after-login
# apt-get install -y debhelper apt-utils lintian
# cd /var/cache/apt/archives
# logout

This step will not be necessary once these packages are imported into debian top-of-tree.

Configure pbuilder to include local packages

We will be building packages that have dependencies on previous things we have built. To make this work, we need to tell pbuilder to configure an apt repository for all the packages found in the pbuilder results directory in /var/cache/pbuilder/result. Add the following lines to $HOME/.pbuilderrc:

BINDMOUNTS="/var/cache/pbuilder/result"
HOOKDIR="/var/cache/pbuilder/hooks"
OTHERMIRROR="deb [trusted=yes] /var/cache/pbuilder/result ./"

Create a hook to create the apt repository files:

# mkdir /var/cache/pbuilder/hooks
# cat > /var/cache/pbuilder/hooks/D70results << __EOF__
#!/bin/sh
cd /var/cache/pbuilder/result
apt-ftparchive packages . > Packages
apt-get update
__EOF__
# chmod +x /var/cache/pbuilder/hooks/D70results

We can also create a hook to run lintian over the build results. This will help the upload process by displaying lintian errors earlier in the development process

# cat > /var/cache/pbuilder/hooks/B90lintian << __EOF__
#!/bin/bash

set -e

install_packages() {
    apt-get -y "${APTGETOPT[@]}" install "$@"
}

install_packages lintian
echo "+++ lintian output +++"

#su -c "lintian -I --show-overrides /tmp/buildd/*.changes" - pbuilder
# use this version if you don't want lintian to fail the build
su -c "lintian -I --show-overrides /tmp/buildd/*.changes; :" - pbuilder

echo "+++ end of lintian output +++"
__EOF__
# chmod +x /var/cache/pbuilder/hooks/B90lintian

Test building a package using the pbuilder

$ gbp clone git@github.com:yanxiaoliang/golang-robfig-config.git
$ cd golang-robfig-config
$ gbp buildpackage --git-builder=pdebuild

The last command checks out the source code for the package from the pristine-tar branch, and then calls pdebuild to build the package.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

认真的柯南

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值