FROM debian:stable-slim

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
 && apt-get install -y --no-install-recommends \
        build-essential \
        debhelper \
        devscripts \
        fakeroot \
        lintian \
        libplack-perl \
        libnet-dbus-perl \
        starlet \
 && rm -rf /var/lib/apt/lists/*

# Build happens at /build/src so dpkg-buildpackage can write its outputs
# (.deb, .dsc, .tar.*, .changes, .buildinfo) to the parent (/build/).
# Source tree is bind-mounted at /build/src by the Makefile's bind mount
# at `docker run` time; COPY bakes the same source into the image so
# `docker build` (no bind mount) also produces a working image.
RUN mkdir -p /build /dist
COPY . /build/src/
RUN cd /build/src \
 && dpkg-buildpackage -us -uc -a

COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod 0755 /usr/local/bin/entrypoint.sh

WORKDIR /build/

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]