# Define builder target
ARG DEB_RELEASE
FROM debian:${DEB_RELEASE}-slim as builder

# Environment PATH HOME HOSTNAME
# ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# ENV HOME /

# Define Debian repos
ARG DEB_RELEASE
RUN printf '#------------------------------------------------------------------------------#\
\n#                   OFFICIAL DEBIAN REPOS\
\n#------------------------------------------------------------------------------#\
\n# apt install curl wget apt-transport-https dirmngr\
\n\
\n###### Debian Main Repos\
\ndeb     http://deb.debian.org/debian/		'${DEB_RELEASE}'			main # contrib non-free\
\ndeb-src http://deb.debian.org/debian/		'${DEB_RELEASE}'			main # contrib non-free\
\n\
\n# stretch-updates, previously known as "volatile"\
\ndeb     http://deb.debian.org/debian/		'${DEB_RELEASE}'-updates		main # contrib non-free\
\ndeb-src http://deb.debian.org/debian/		'${DEB_RELEASE}'-updates		main # contrib non-free\
\n\
\ndeb     http://deb.debian.org/debian-security	'${DEB_RELEASE}'/updates		main\
\ndeb-src http://deb.debian.org/debian-security	'${DEB_RELEASE}'/updates		main\
\n\
\n# stretch-backports, previously on backports.debian.org\
\ndeb     http://ftp.debian.org/debian		'${DEB_RELEASE}'-backports	main\
\ndeb-src http://ftp.debian.org/debian		'${DEB_RELEASE}'-backports	main\
\n' > /etc/apt/sources.list

# Build deps and clean up
# Crossbuilding: https://wiki.debian.org/CrossCompiling#Building_with_dpkg-buildpackage
ARG BUILD_DEPS
ARG BUILD_ARCH
RUN export DEBIAN_FRONTEND=noninteractive && \
    for ARCH in ${BUILD_ARCH} ; do \
      dpkg --add-architecture ${ARCH} ; \
    done && \
    apt-get -q  update && \
    apt-get -qy -o Dpkg::Use-Pty=0 upgrade && \
    apt-get -qy -o Dpkg::Use-Pty=0 install --no-install-recommends apt-utils && \
    apt-get -qy -o Dpkg::Use-Pty=0 install --no-install-recommends ${BUILD_DEPS} \
        apt-utils build-essential debhelper ca-certificates curl git iproute2 wget nano && \
    for ARCH in ${BUILD_ARCH} ; do \
      apt-get -qy -o Dpkg::Use-Pty=0 install --no-install-recommends \
        crossbuild-essential-${ARCH} $(printf "%s:${ARCH} " ${BUILD_DEPS}) ; \
    done && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Default command
CMD ["bash"]

