Debian packaging/Package your software as deb

From Wikitech

Introduction

When software we develop at Wikimedia needs to be packaged for Debian, you typically want minimal disruption to your development process. This means that, for instance, maintaining a per-distribution branch where you'll build the software for different Debian versions is inconvenient, if the only thing that has to change is the debian/changelog entry.

Additionally, when developing software, you will typically have project-specific CI pipelines, and any additional pipeline will have to merged into it.

To this end, we've developed a specialized pipeline that builds a Debian package every time that both of the following conditions are true:

  • a commit is pushed or merged onto your main branch
  • there is a change to debian/changelog

The deb package will be built for the distribution indicated in the latest entry in the debian/changelog (which must be in the format $distro-wikimedia, or the CI pipeline will fail).

How to enable automatic build of debian packages

Typically, you have your own CI tasks for your code already. So, just modify your .gitlab-ci.yml file to include the following:

# you can have more stages, but these are mandatory or CI will fail
stages:
  - prepare
  - build
  - upload
  - release

# Again this just needs to be added to your own set of variables if you have them.
# Please note: this needs to be declared before the include.
variables:
  # Use backports when building debs
  USEBACKPORTS: "1"
  # Change to "1" if you want your deb to be published as a gitlab release,
  # see https://gitlab.wikimedia.org/repos/sre/vopsbot/-/releases/0.3.8-3.2-bookworm
  # as an example of the result
  WMF_CI_RELEASE_DEB: "0"

include:
  - project: 'repos/sre/wmf-debci'
    ref: main
    file:
      - 'wmfdeb.yml'

A typical workflow

Let's see how a typical workflow will pan out:

Let's say we want to make a new release for vopsbot, and we want to package the software for both Debian Bullseye and Debian Bookworm.

Bookworm

  • First, we'll add an entry to debian/changelog for Bookworm, eg.
 vopsbot (0.3.8-4) bookworm-wikimedia; urgency=medium
 [...]
  • push the change to main
  • The bookworm package will be built:
dch -v 0.3.8-4
git add debian/changelog
git commit -m 'Build 0.3.8-4 for bookworm'
git push
# This triggers a pipeline like https://gitlab.wikimedia.org/repos/sre/vopsbot/-/pipelines/37699
# and results in the release https://gitlab.wikimedia.org/repos/sre/vopsbot/-/releases/0.3.8-4-bookworm

Bullseye

 vopsbot (0.3.8-4~deb11u1) bullseye-wikimedia; urgency=medium
 [...]
  • push the change to the main branch of the repository.
  • The bullseye package will be built:
dch -v '0.3.8-4~deb11u1'
git add debian/changelog
git commit -m 'Build 0.3.8-4 for bullseye'
git push

# This triggers a pipeline like https://gitlab.wikimedia.org/repos/sre/vopsbot/-/pipelines/37702
# and results in the release https://gitlab.wikimedia.org/repos/sre/vopsbot/-/releases/0.3.8-4~deb11u1-bullseye

The important detail is that you need to perform separate push operations for each of the distributions you want to build for, as the pipeline only looks for the latest changelog entry.