Chinaunix首页 | 论坛 | 博客
  • 博客访问: 241768
  • 博文数量: 33
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 480
  • 用 户 组: 普通用户
  • 注册时间: 2019-01-22 08:36
个人简介

专注虚拟化性能优化,硬件显卡网卡虚拟加速,面向容器的轻量虚拟化开发 永远的Linux Geeker!

文章分类

全部博文(33)

分类: LINUX

2019-01-25 02:14:04

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=
MIRRORSITE=
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.

阅读(4103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~