We're using spotify's opensourced dh-virtualenv to provide Debian packaging and deployment of our Python code inside a virtualenv.
dh-virtualenv is essentially a wrapper or a set of extensions around existing debian tooling. You can find the official page here.
Our goal is to use dh-virtualenv for accomplishing things like packaging, symlinks, installing configuration files, systemd service installation, and virtualization at deployment.
On your build host, install the build tools. This could be a laptop, virtual machine, Raspberry Pi, Mac running Asahi, etc. These are only needed on your build host:
sudo apt-get install build-essential debhelper devscripts equivs python3-pip python3-all-dev python3-setuptools dh-virtualenvInstall Python depends:
python3 -m pip install mockUpdate pip, setuptools, and install wheels:
python3 -m pip install -U pip setuptools wheelThis is required, otherwise the tooling will fail when tries to evaluate which tests to run.
sudo mk-build-deps -riFrom the root directory of this repository run:
dpkg-buildpackage -us -uc -bNote that -us -uc disables signing the package with GPG.
So, if your goal is to build, test with lintian, and sign with GPG:
debuildIf you are found favorable by the packaging gods, you should see some output files at ../wlanpi-app like this:
dpkg-deb: building package 'wlanpi-app-dbgsym' in '../wlanpi-app-dbgsym_0.0.1~rc1_arm64.deb'.
dpkg-deb: building package 'wlanpi-app' in '../wlanpi-app_0.0.1~rc1_arm64.deb'.
dpkg-genbuildinfo --build=binary
dpkg-genchanges --build=binary >../wlanpi-app_0.0.1~rc1_arm64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
dpkg-source --after-build .
dpkg-buildpackage: info: binary-only upload (no source included)
(venv) wlanpi@rbpi4b-8gb:[~/dev/wlanpi-app]: ls .. | grep wlanpi-app_
wlanpi-app_0.0.1~rc1_arm64.buildinfo
wlanpi-app_0.0.1~rc1_arm64.changes
wlanpi-app_0.0.1~rc1_arm64.debTo update the version number of a newly updated package, the debchange (dch) utility from devscripts should be used. Check out the dch document for more.
Lintian is a static analyzer which we can use to check our debian package.
lintian
lintian -i
lintian -EviIL +pedanticIf we "remove" our package, it will leave behind the config file in /etc:
sudo apt remove wlanpi-app
If we want to clean /etc we should "purge":
sudo apt purge wlanpi-app
changelog: Contains changelog information and sets the version of the package. date must be in RFC 5322 format.control: provides dependencies, package name, and other package meta data. tols like apt uses these to build dependencies, etc.copyright: copyright information for upstream source and packagingcompat: sets compatibility level for debhelperrules: this is the build recipe for make. it does the work for creating our package. it is a makefile with targets to compile and install the application, then create the .deb file.wlanpi-app.service:dhautomatically picks up and installs this systemd servicewlanpi-app.triggers: tells dpkg what packages we're interested in
postinst- this runs after the install and handles setting up a few things. dh_installdeb will replace this with shell code automatically.postrm- this runs and handlesremoveandpurgeargs when uninstalling or purging the package. dh_installdeb will replace this with shell code automatically.
Some OS repositories have packages already.
sudo apt install dh-virtualenvIf not available, you can build it from source:
cd ~
# Install needed packages
sudo apt-get install devscripts python3-virtualenv python3-sphinx \
python3-sphinx-rtd-theme git equivs
# Clone git repository
git clone https://github.com/spotify/dh-virtualenv.git
# Change into working directory
cd dh-virtualenv
# This will install build dependencies
sudo mk-build-deps -ri
# Build the *dh-virtualenv* package
dpkg-buildpackage -us -uc -b
# And finally, install it (you might have to solve some
# dependencies when doing this)
sudo dpkg -i ../dh-virtualenv_<version>.deb