# Build dh-virtualenv's Debian package within a container for any platform
#
#   docker build --tag dh-venv-builder --build-arg distro=debian:testing .
#
#   mkdir -p dist && command docker run --rm dh-venv-builder tar -C /dpkg -c . | tar -C dist -xv
#
# Add '--build-arg opts=nodoc' to skip the Sphinx documentation and its dependencies.

ARG distro="debian:stable"

FROM ${distro} AS dpkg-build
ARG opts=""
ENV DEB_BUILD_OPTIONS=${opts}
ENV DEB_BUILD_PROFILES=${opts}
WORKDIR /dpkg-build
COPY ./ ./
RUN apt-get update -qq -o Acquire::Languages=none \
    && env DEBIAN_FRONTEND=noninteractive apt-get build-dep \
        -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io ./ \
    && apt-get clean && rm -rf "/var/lib/apt/lists"/*


RUN . /etc/os-release && codename="${VERSION_CODENAME:-unstable}" \
    && sed -i -re "1s/..unstable/~${codename}) ${codename}/" debian/changelog \
    && chmod a-x debian/dh-virtualenv.* \
    && dpkg-buildpackage -us -uc -b && mkdir -p /dpkg && cp -pl /dh-virtualenv[-_]* /dpkg \
    && dpkg-deb -I /dpkg/dh-virtualenv_*.deb
