├── Dockerfile-ubuntu-18.04 ├── Dockerfile-Debian-bullseye-11 ├── Dockerfile-Debian-buster-10 ├── Dockerfile-Debian-bookworm-12 ├── Dockerfile-ubuntu-20.04 ├── Dockerfile-ubuntu-22.04 ├── Dockerfile-ubuntu-23.04 ├── Dockerfile-Debian-sid-unstable ├── Dockerfile-Debian-trixie-13 ├── LICENSE └── README.md /Dockerfile-ubuntu-18.04: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list 4 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 5 | RUN set -ex \ 6 | && apt-get update \ 7 | && apt-get upgrade -y --no-install-recommends \ 8 | && apt-get install -y --no-install-recommends \ 9 | build-essential \ 10 | cdbs \ 11 | devscripts \ 12 | equivs \ 13 | fakeroot \ 14 | && apt-get clean 15 | RUN rm /etc/apt/apt.conf.d/docker-clean 16 | RUN rm -rf /tmp/* /var/tmp/ 17 | RUN ln -s /tmp /var/tmp 18 | -------------------------------------------------------------------------------- /Dockerfile-Debian-bullseye-11: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye 2 | 3 | RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list 4 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 5 | RUN set -ex \ 6 | && apt-get update \ 7 | && apt-get upgrade -y --no-install-recommends \ 8 | && apt-get install -y --no-install-recommends \ 9 | build-essential \ 10 | cdbs \ 11 | devscripts \ 12 | equivs \ 13 | fakeroot \ 14 | && apt-mark minimize-manual -y \ 15 | && apt-get autopurge -y \ 16 | && apt-get clean 17 | RUN rm /etc/apt/apt.conf.d/docker-clean 18 | RUN rm -rf /tmp/* /var/tmp/ 19 | RUN ln -s /tmp /var/tmp 20 | -------------------------------------------------------------------------------- /Dockerfile-Debian-buster-10: -------------------------------------------------------------------------------- 1 | FROM debian:buster 2 | 3 | RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list 4 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 5 | RUN set -ex \ 6 | && apt-get update \ 7 | && apt-get upgrade -y --no-install-recommends \ 8 | && apt-get install -y --no-install-recommends \ 9 | build-essential \ 10 | cdbs \ 11 | devscripts \ 12 | equivs \ 13 | fakeroot \ 14 | && apt-mark minimize-manual -y \ 15 | && apt-get autopurge -y \ 16 | && apt-get clean 17 | RUN rm /etc/apt/apt.conf.d/docker-clean 18 | RUN rm -rf /tmp/* /var/tmp/ 19 | RUN ln -s /tmp /var/tmp 20 | -------------------------------------------------------------------------------- /Dockerfile-Debian-bookworm-12: -------------------------------------------------------------------------------- 1 | FROM debian:bookworm 2 | 3 | RUN sed -i -- 's/Types: deb/Types: deb deb-src/g' /etc/apt/sources.list.d/debian.sources 4 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 5 | RUN set -ex \ 6 | && apt-get update \ 7 | && apt-get upgrade -y --no-install-recommends \ 8 | && apt-get install -y --no-install-recommends \ 9 | build-essential \ 10 | cdbs \ 11 | devscripts \ 12 | equivs \ 13 | fakeroot \ 14 | && apt-mark minimize-manual -y \ 15 | && apt-get autopurge -y \ 16 | && apt-get clean 17 | RUN rm /etc/apt/apt.conf.d/docker-clean 18 | RUN rm -rf /tmp/* /var/tmp/ 19 | RUN ln -s /tmp /var/tmp 20 | -------------------------------------------------------------------------------- /Dockerfile-ubuntu-20.04: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | ARG DEBIAN_FRONTEND=noninteractive 4 | 5 | RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list 6 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 7 | RUN set -ex \ 8 | && apt-get update \ 9 | && apt-get upgrade -y --no-install-recommends \ 10 | && apt-get install -y --no-install-recommends \ 11 | build-essential \ 12 | cdbs \ 13 | devscripts \ 14 | equivs \ 15 | fakeroot \ 16 | && apt-mark minimize-manual -y \ 17 | && apt-get autopurge -y \ 18 | && apt-get clean 19 | RUN rm /etc/apt/apt.conf.d/docker-clean 20 | RUN rm -rf /tmp/* /var/tmp/ 21 | RUN ln -s /tmp /var/tmp 22 | -------------------------------------------------------------------------------- /Dockerfile-ubuntu-22.04: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | ARG DEBIAN_FRONTEND=noninteractive 4 | 5 | RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list 6 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 7 | RUN set -ex \ 8 | && apt-get update \ 9 | && apt-get upgrade -y --no-install-recommends \ 10 | && apt-get install -y --no-install-recommends \ 11 | build-essential \ 12 | cdbs \ 13 | devscripts \ 14 | equivs \ 15 | fakeroot \ 16 | && apt-mark minimize-manual -y \ 17 | && apt-get autopurge -y \ 18 | && apt-get clean 19 | RUN rm /etc/apt/apt.conf.d/docker-clean 20 | RUN rm -rf /tmp/* /var/tmp/ 21 | RUN ln -s /tmp /var/tmp 22 | -------------------------------------------------------------------------------- /Dockerfile-ubuntu-23.04: -------------------------------------------------------------------------------- 1 | FROM ubuntu:23.04 2 | 3 | ARG DEBIAN_FRONTEND=noninteractive 4 | 5 | RUN sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list 6 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 7 | RUN set -ex \ 8 | && apt-get update \ 9 | && apt-get upgrade -y --no-install-recommends \ 10 | && apt-get install -y --no-install-recommends \ 11 | build-essential \ 12 | cdbs \ 13 | devscripts \ 14 | equivs \ 15 | fakeroot \ 16 | && apt-mark minimize-manual -y \ 17 | && apt-get autopurge -y \ 18 | && apt-get clean 19 | RUN rm /etc/apt/apt.conf.d/docker-clean 20 | RUN rm -rf /tmp/* /var/tmp/ 21 | RUN ln -s /tmp /var/tmp 22 | -------------------------------------------------------------------------------- /Dockerfile-Debian-sid-unstable: -------------------------------------------------------------------------------- 1 | FROM debian:sid 2 | 3 | RUN sed -i -- 's/Types: deb/Types: deb deb-src/g' /etc/apt/sources.list.d/debian.sources 4 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 5 | RUN set -ex \ 6 | && apt-get update \ 7 | && apt-get upgrade -y --no-install-recommends --purge \ 8 | && apt-get dist-upgrade -y --no-install-recommends --purge \ 9 | && apt-get install -y --no-install-recommends --purge \ 10 | build-essential \ 11 | cdbs \ 12 | devscripts \ 13 | equivs \ 14 | fakeroot \ 15 | && apt-mark minimize-manual -y \ 16 | && apt-get autopurge -y \ 17 | && apt-get clean 18 | RUN rm /etc/apt/apt.conf.d/docker-clean 19 | RUN rm -rf /tmp/* /var/tmp/ 20 | RUN ln -s /tmp /var/tmp 21 | -------------------------------------------------------------------------------- /Dockerfile-Debian-trixie-13: -------------------------------------------------------------------------------- 1 | FROM debian:trixie 2 | 3 | RUN sed -i -- 's/Types: deb/Types: deb deb-src/g' /etc/apt/sources.list.d/debian.sources 4 | RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections 5 | RUN set -ex \ 6 | && apt-get update \ 7 | && apt-get upgrade -y --no-install-recommends --purge \ 8 | && apt-get dist-upgrade -y --no-install-recommends --purge \ 9 | && apt-get install -y --no-install-recommends --purge \ 10 | build-essential \ 11 | cdbs \ 12 | devscripts \ 13 | equivs \ 14 | fakeroot \ 15 | && apt-mark minimize-manual -y \ 16 | && apt-get autopurge -y \ 17 | && apt-get clean 18 | RUN rm /etc/apt/apt.conf.d/docker-clean 19 | RUN rm -rf /tmp/* /var/tmp/ 20 | RUN ln -s /tmp /var/tmp 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Tero Saarni 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Creating Debian packages in container 2 | 3 | ## Overview 4 | 5 | Container engines, in particular docker and podman, can be used for Debian 6 | packaging. Building inside a container avoids installing build dependencies on 7 | the host, ensures a clean and reproducible environment, and in case of podman 8 | allows to perform the build as unprivileged user. 9 | 10 | Fork of [docker-deb-builder](https://github.com/tsaarni/docker-deb-builder), 11 | created by Tero Saarni. 12 | 13 | ## Create build environment 14 | 15 | The build environment is setup in advance by creating a container image to 16 | speed up builds. It only contains essential build dependencies, like gcc, thus 17 | one can be used to build different Debian packages. For each distribution a 18 | separate build environment needs to be created. 19 | 20 | In this example the target is Ubuntu 22.04 and Debian sid, other distributions 21 | can be created by their respective Dockerfile: 22 | 23 | docker build -t container-deb-builder:22.04 -f Dockerfile-ubuntu-22.04 . 24 | podman build -t container-deb-builder:sid -f Dockerfile-Debian-sid-unstable . 25 | 26 | The image name (`container-deb-builder:22.04`) is later used while building a 27 | Debian package. 28 | 29 | ## Building packages 30 | 31 | First download or git clone the source code of the package to build: 32 | 33 | git clone ... ~/my-package-source 34 | 35 | The source code should contain subdirectory called `debian` with at 36 | least a minimum set of packaging files: `control`, `copyright`, 37 | `changelog` and `rules`. 38 | 39 | Run the build script to see its usage: 40 | 41 | $ ./build -h 42 | usage: build [options...] SOURCEDIR 43 | Options: 44 | -i IMAGE Name of the docker image (including tag) to use as package build environment. 45 | -c PROGRAM Use a custom container engine. 46 | -o DIR Destination directory to store packages to. 47 | -d DIR Directory that contains other deb packages that need to be installed before build. 48 | -p profiles Specify the profiles to build (e.g. nocheck). Takes a comma separated list. 49 | -C Use ccache to cache compiled objects. 50 | -L Run Lintian after a successful build. 51 | -B Run blhc after a successful build. 52 | -t Reset file modification timestamps to changelog entry. 53 | 54 | To build Debian packages run following commands: 55 | 56 | # create destination directory to store the build results 57 | mkdir output 58 | 59 | # build package from source directory 60 | ./build -i container-deb-builder:22.04 -o output ~/my-package-source 61 | 62 | After a successful build the build results will be copied from the container 63 | into the `output` directory. The container itself is discarded. 64 | 65 | Sometimes builds might require dependencies that cannot be installed with 66 | `apt-get build-dep`, e.g. when the required version of the dependency is not 67 | yet available. Those can be installed into the build environment by passing 68 | the option `-d DIR`, where *DIR* is a directory with `*.deb` files in it. 69 | 70 | ./build -i container-deb-builder:22.04 -o output -d dependencies ~/my-package-source 71 | 72 | ### Native builds for foreign architectures 73 | 74 | By default all packages are build for the architecture the host is running on. 75 | Docker and Podman however support running containers under a foreign 76 | architecture via QEMU. This emulation is quite slower than standard cross- 77 | compiling but enables native builds, which for example includes running tests. 78 | 79 | First install the required system packages: 80 | 81 | apt install binfmt-support qemu-user-static 82 | 83 | Distinct images needs to be build for each architecture via the flag 84 | `--platform`, e.g. for arm64: 85 | 86 | podman build -t container-deb-builder-arm64:sid -f Dockerfile-Debian-bookworm-12 --platform arm64 . 87 | 88 | --- 89 | **Note**: 90 | 91 | Podman remembers the last architecture used for a local image, so be sure to 92 | specify the correct platform for further usage (especially if the name of the 93 | image is used multiple times). 94 | 95 | --- 96 | 97 | Building packages then works just by using the particular images. 98 | 99 | ## Maintenance 100 | 101 | The data for apt archives and ccache is stored in volumes. These volumes have 102 | the naming scheme `cdebb__${ImageName}__(apt|ccache)` and can be removed if 103 | the respective image does no longer exists or the disk space is needed. 104 | --------------------------------------------------------------------------------