Debian Packaging 2018-12-10
Managing servers is way easier if you package up your projects as packages. This is a list of steps that results in a Debian package.
Build machine setup
- Make sure you have the required dependencies:
apt install build-essential dh-make git-buildpackage
- Optionally install a custom package key to your apt repo:
curl https://example.org/example.asc | apt-key add -
- Optionally add a custom repository to the pbuilder config:
echo 'OTHERMIRROR="deb https://example.org/debian buster main"' >> /etc/pbuilderrc
- Make sure you have a build environment in the right distribution:
cowbuilder create --distribution buster --basepath /var/cache/pbuilder/base-buster.cow --keyring /etc/apt/trusted.gpg --debootstrapopts "--include=apt-transport-https,ca-certificates"
Package configuration
- Make sure the repository has a Makefile in the root directory which accepts the following targets:
- build
- test
- clean
- install (make sure to install all files relative to
${DESTDIR}
- Tag the first release with the version number:
git tag v1.2.3
- Create a branch for the debian version you're targeting:
git checkout -b debian/buster
- Set your name:
export DEBFULLNAME="John Doe"
- Set your email:
export EMAIL=yourmail@example.org
- Create template debian control files:
dh_make --single --createorig --packagename yourpackagename-with-hypens_1.2.3
- Create the pristine-tar branch:
pristine-tar commit ../yourpackagename-with-hypens_1.2.3.orig.tar.xz master
- Remove the files you don't need in the debian folder. Make sure you keep the following ones: changelog, compat, control, rules, source/format.
- Fill in the changelog
- Fill in the control file: https://www.debian.org/doc/manuals/maint-guide/dreq.en.html
- Commit the debian folder to the debian/buster branch.
- Build:
gbp buildpackage --git-pristine-tar --git-pristine-tar-commit --git-upstream-tag='v%(version)s' --git-pbuilder --git-debian-branch=debian/buster --git-dist=buster
New version
- Update the cowbuilder base system:
DIST=buster git-pbuilder --update
- Tag the new version on develop:
git tag v1.2.4
- Switch to the debian branch:
git checkout debian/buster
- Merge develop in:
git merge develop
- Update the changelog, make sure you update the top version number to be the same as the tag:
gbp dch --release --auto --debian-branch=debian/buster
- Commit the changelog:
git commit debian/changelog
- Build:
gbp buildpackage --git-pristine-tar --git-pristine-tar-commit --git-upstream-tag='v%(version)s' --git-pbuilder --git-debian-branch=debian/buster --git-dist=buster