FROM debian:stretch

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
 && apt-get upgrade -y

RUN apt-get install -y \
  sudo wget curl tar expect git \
  devscripts build-essential liblua5.1-0-dev lintian ccache pbuilder aptitude apt-utils apt-transport-https

RUN echo "deb http://deb.debian.org/debian stretch-backports main" >/etc/apt/sources.list.d/backports.list

RUN curl https://packages.icinga.com/icinga.key | apt-key add - \
 && DIST=$(awk -F"[)(]+" '/VERSION=/ {print $2}' /etc/os-release) \
 && echo "deb http://packages.icinga.com/debian icinga-${DIST} main" > /etc/apt/sources.list.d/${DIST}-icinga.list

RUN groupadd -g 1000 build \
 && useradd -u 1000 -g 1000 -m build \
 && echo 'Defaults:build !requiretty' | tee -a /etc/sudoers \
 && echo 'build ALL=(ALL:ALL) NOPASSWD: ALL' | tee -a /etc/sudoers

RUN git clone https://git.icinga.com/build-docker/scripts.git /usr/local/bin
RUN icinga-provide-go
USER build
ENTRYPOINT ["/usr/local/bin/icinga-build-entrypoint"]
CMD ["icinga-build-package"]