Skip to content

Commit 1aa95f1

Browse files
committed
Build package in Docker (tested for Stretch)
1 parent a320320 commit 1aa95f1

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

Dockerfile.build

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Build Debian package using dh-virtualenv
2+
#
3+
# To create a package for Stretch in `dist/`, call:
4+
#
5+
# ./build.sh debian:stretch
6+
7+
# Build arguments, as provided by 'build.sh'
8+
ARG DIST_ID="debian"
9+
ARG CODENAME="stretch"
10+
ARG PYVERSION=""
11+
ARG PKGNAME
12+
13+
# Other build arguments (adapt as needed)
14+
ARG DEB_POOL="http://ftp.nl.debian.org/debian/pool/main"
15+
16+
## Start package builder image for the chosen platform
17+
FROM ${DIST_ID}:${CODENAME} AS dpkg-build
18+
19+
# Pass build args into image scope
20+
ARG CODENAME
21+
ARG PYVERSION
22+
ARG PKGNAME
23+
ARG DEB_POOL
24+
25+
# Install build tools and package build deps including nodejs
26+
RUN env LANG=C apt-get update -qq -o Acquire::Languages=none \
27+
&& env LANG=C DEBIAN_FRONTEND=noninteractive apt-get install \
28+
-yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
29+
\
30+
apt-utils \
31+
build-essential \
32+
curl \
33+
debhelper \
34+
devscripts \
35+
equivs \
36+
gzip \
37+
libjs-sphinxdoc \
38+
libparse-debianchangelog-perl \
39+
lsb-release \
40+
python${PYVERSION} \
41+
python${PYVERSION}-dev \
42+
python${PYVERSION}-pip \
43+
python${PYVERSION}-pkg-resources \
44+
python${PYVERSION}-setuptools \
45+
python-virtualenv \
46+
sphinx-rtd-theme-common \
47+
tar \
48+
\
49+
libcurl4-openssl-dev \
50+
libffi-dev \
51+
libfontconfig1 \
52+
libjpeg-dev \
53+
libncurses5-dev \
54+
libncursesw5-dev \
55+
libssl-dev \
56+
libxml2-dev \
57+
libxslt1-dev \
58+
libyaml-dev \
59+
libz-dev \
60+
\
61+
clang \
62+
cmake \
63+
libldap2-dev \
64+
libpq-dev \
65+
libsasl2-dev \
66+
&& apt-get clean && rm -rf "/var/lib/apt/lists"/*
67+
68+
# Uncomment and adapt these ENV instructions to use a local PyPI mirror
69+
# (examples for devpi and JFrog Artifactory)
70+
#ENV PIP_TRUSTED_HOST="devpi.local"
71+
#ENV PIP_INDEX_URL="http://${PIP_TRUSTED_HOST}:3141/root/pypi/+simple/"
72+
#ENV PIP_TRUSTED_HOST="artifactory.local"
73+
#ENV PIP_INDEX_URL="https://${PIP_TRUSTED_HOST}/artifactory/api/pypi/pypi.python.org/simple"
74+
75+
# Install updated Python tooling and a current 'dh-virtualenv'
76+
WORKDIR /dpkg-build
77+
ADD "${DEB_POOL}/d/dh-virtualenv/dh-virtualenv_1.1-1_all.deb" ./
78+
RUN dpkg -i --force-unsafe-io --ignore-depends=sphinx-rtd-theme-common *_all.deb \
79+
&& python${PYVERSION} -m pip install -U pip \
80+
&& python${PYVERSION} -m pip install -U setuptools wheel virtualenv
81+
82+
# Build project and show metadata of built package
83+
COPY ./ ./
84+
RUN hr() { printf '\n %-74s\n' "[$1]" | tr ' ' = ; } \
85+
&& hr Versions && python${PYVERSION} -m pip --version && dh_virtualenv --version \
86+
&& sed -i -r \
87+
-e "1s/(UNRELEASED|unstable|jessie|stretch|xenial|bionic)/$(lsb_release -cs)/g" \
88+
debian/changelog \
89+
&& dpkg-buildpackage -us -uc -b && mkdir -p /dpkg && cp -pl /${PKGNAME}[-_]* /dpkg \
90+
&& hr DPKG-Info && dpkg-deb -I /dpkg/${PKGNAME}_*.deb

build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#! /usr/bin/env bash
2+
#
3+
# Build Debian package in a Docker container
4+
#
5+
6+
set -e
7+
8+
# Get build platform as 1st argument, and collect project metadata
9+
image="${1:?You MUST provide a docker image name}"; shift
10+
dist_id=${image%%:*}
11+
codename=${image#*:}
12+
pypi_name="$(./setup.py --name)"
13+
pypi_version="$(./setup.py --version)"
14+
pkgname="$(dh_listpackages)"
15+
tag=$pypi_name-$dist_id-$codename
16+
17+
build_opts=(
18+
-f Dockerfile.build
19+
--tag $tag
20+
--build-arg "DIST_ID=$dist_id"
21+
--build-arg "CODENAME=$codename"
22+
--build-arg "PKGNAME=$pkgname"
23+
)
24+
25+
# Build in Docker container, save results, and show package info
26+
rm -f dist/${pkgname}?*${pypi_version//./?}*${codename}*.*
27+
docker build "${build_opts[@]}" "$@" .
28+
mkdir -p dist
29+
docker run --rm $tag tar -C /dpkg -c . | tar -C dist -x
30+
ls -lh dist/${pkgname}?*${pypi_version//./?}*${codename}*.*

0 commit comments

Comments
 (0)