jinjaturtle/Dockerfile.debbuild
Miguel Jacq a9d56b66c5
All checks were successful
CI / test (push) Successful in 46s
CI / test (debian, docker.io/library/debian:13, python3) (push) Successful in 1m18s
Lint / test (push) Successful in 38s
Fixes for releasing
2026-06-23 18:03:29 +10:00

102 lines
2.7 KiB
Text

# syntax=docker/dockerfile:1
ARG BASE_IMAGE=debian:bookworm
FROM ${BASE_IMAGE}
ENV DEBIAN_FRONTEND=noninteractive
# If Ubuntu, ensure Universe is enabled.
RUN set -eux; \
. /etc/os-release; \
if [ "${ID:-}" = "ubuntu" ]; then \
apt-get update; \
apt-get install -y --no-install-recommends software-properties-common ca-certificates; \
add-apt-repository -y universe; \
fi; \
if [ "${VERSION_CODENAME:-}" = "jammy" ]; then \
apt-get update; \
apt-get install -y --no-install-recommends python3-tomli; \
fi
# Build deps
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
build-essential \
devscripts \
debhelper \
dh-python \
pybuild-plugin-pyproject \
python3-all \
python3-poetry-core \
python3-yaml \
python3-defusedxml \
python3-jinja2 \
python3-toml \
rsync \
ca-certificates \
; \
rm -rf /var/lib/apt/lists/*
# Build runner script
RUN set -eux; \
cat > /usr/local/bin/build-deb <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
SRC="${SRC:-/src}"
WORKROOT="${WORKROOT:-/work}"
WORK="${WORKROOT}/src"
OUT="${OUT:-/out}"
mkdir -p "$WORK" "$OUT"
rsync -a --delete \
--exclude '.git' \
--exclude '.venv' \
--exclude 'dist' \
--exclude 'build' \
--exclude '__pycache__' \
--exclude '.pytest_cache' \
--exclude '.mypy_cache' \
"${SRC}/" "${WORK}/"
cd "${WORK}"
# This project's pyproject.toml uses the PEP 621 [project] table, which needs
# poetry-core >= 2.0. Debian bookworm and Ubuntu jammy/noble ship an older
# poetry-core that cannot parse it. On those, swap in the legacy Poetry 1.x
# formatted metadata (kept in sync at pyproject.poetry1.toml) for the build.
# trixie and newer ship poetry-core 2.x and keep the PEP 621 file.
if [ -f pyproject.poetry1.toml ]; then
core_ver="$(python3 -c 'import poetry.core as c; print(c.__version__)' 2>/dev/null || echo 0)"
core_major="${core_ver%%.*}"
if [ "${core_major:-0}" -lt 2 ]; then
echo "poetry-core ${core_ver} < 2.0: using legacy pyproject.poetry1.toml"
cp pyproject.poetry1.toml pyproject.toml
else
echo "poetry-core ${core_ver} >= 2.0: using PEP 621 pyproject.toml"
fi
fi
if [ -n "${SUITE:-}" ]; then
export DEBEMAIL="mig@mig5.net"
export DEBFULLNAME="Miguel Jacq"
dch --distribution "$SUITE" --local "~${SUITE}" "CI build for $SUITE"
fi
dpkg-buildpackage -us -uc -b
shopt -s nullglob
cp -v "${WORKROOT}"/*.deb \
"${WORKROOT}"/*.changes \
"${WORKROOT}"/*.buildinfo \
"${WORKROOT}"/*.dsc \
"${WORKROOT}"/*.tar.* \
"${OUT}/" || true
echo "Artifacts copied to ${OUT}"
EOF
RUN chmod +x /usr/local/bin/build-deb
WORKDIR /work
ENTRYPOINT ["/usr/local/bin/build-deb"]