FROM python:3.5-slim-jessie

ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY

ENV PYTHONUNBUFFERED=1 \
	DEBIAN_FRONTEND=noninteractive \
	NODEJS_VERSION=10.x \
	GOSU_VERSION=1.10

RUN \
	echo "Install base packages" \
	&& ([ -z "$HTTP_PROXY" ] || echo "Acquire::http::Proxy \"${HTTP_PROXY}\";" > /etc/apt/apt.conf.d/99HttpProxy) \
	&& apt-get update \
	&& apt-get install -y --no-install-recommends \
		apt-transport-https \
		make \
		curl \
		git \
		build-essential \
		libxml2-dev \
		libxslt-dev \
		zlib1g-dev \
		zip \
		rlwrap \
		python-dev \
		libffi-dev \
		libssl-dev \
		libexif-dev \
		libfreetype6-dev \
		libjpeg-dev \
		liblcms2-2 \
		libtiff5-dev \
		zlib1g-dev \
		libpango1.0-dev \
		libcairo2-dev \
		libmagickwand-dev \
		ghostscript \
		jq \
		libjpeg62 \

	&& echo "Install nodejs" \
	&& cd /tmp \
	&& curl -x "$HTTP_PROXY" -sL https://deb.nodesource.com/setup_${NODEJS_VERSION} | bash - \
	&& apt-get install -y --no-install-recommends nodejs \

	&& echo "Clean up" \
	&& rm -rf /var/lib/apt/lists/* /tmp/*

RUN \
	echo "Install global pip packages" \
	&& pip install \
		virtualenv \
		awscli \
		wheel

RUN \
	echo "Install Cloud Foundry CLI" \
	&& curl -sSL "https://cli.run.pivotal.io/stable?release=debian64&source=github" -o /tmp/cloudfoundry-cli.deb \
	&& dpkg -i /tmp/cloudfoundry-cli.deb

COPY tianon.gpg /tmp/tianon.gpg

RUN \
	echo "Install gosu" \
	&& curl -sSL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
	&& curl -sSL -o /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
	&& export GNUPGHOME="$(mktemp -d)" \
	&& gpg --import /tmp/tianon.gpg \
	&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
	&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
	&& chmod +x /usr/local/bin/gosu \
	&& gosu nobody true

WORKDIR /var/project

COPY entrypoint.sh /usr/local/bin/docker-entrypoint

ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
