FROM php:{{phpVersion}}-cli
{{#if authorName}}LABEL maintainer="{{authorName}}{{#if authorEmail}} <{{authorEmail}}>{{/if}}"{{/if}}

\{{#DOCKER_DEVBOX_CA_CERTIFICATES}}
COPY .ca-certificates/* /usr/local/share/ca-certificates/
RUN update-ca-certificates
\{{/DOCKER_DEVBOX_CA_CERTIFICATES}}

# Register the COMPOSER_HOME environment variable
ENV COMPOSER_HOME /composer

# Add global binary directory to PATH and make sure to re-export it
ENV PATH /composer/vendor/bin:$PATH

# Allow Composer to be run as root
ENV COMPOSER_ALLOW_SUPERUSER 1

# Setup the Composer installer
RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
  && curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \
  && php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }"

# Install Composer
RUN php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --snapshot && rm -rf /tmp/composer-setup.php
RUN apt-get update -y && apt-get install -y git zip unzip && rm -rf /var/lib/apt/lists/*

# Github token
RUN composer config -g github-oauth.github.com db14c113decece351f1e20cf012ce0b3c8612cd5

# Install prestissimo
RUN composer global require hirak/prestissimo

# Install phing
RUN composer global require phing/phing pear/archive_tar --prefer-dist --no-progress --no-suggest
RUN chmod +x ${COMPOSER_HOME}/vendor/phing/phing/bin/phing && chown ${HOST_UID:-1000}:${HOST_GID:-1000} ${COMPOSER_HOME}/vendor/phing/phing/bin/phing

# Docker CLI
ARG DOCKER_VERSION=18.03.1-ce
RUN curl -L -O https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz \
  && tar xzvf ${DOCKER_VERSION}.tgz \
  && cp docker/* /usr/bin/ \
  && chmod +x /usr/bin/docker

RUN groupadd -g 998 docker
RUN usermod -a -G docker www-data

# Docker compose
ARG DOCKER_COMPOSE_VERSION=1.21.2
RUN curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
RUN chmod +x /usr/bin/docker-compose

RUN usermod -u ${HOST_UID:-1000} www-data
RUN groupmod -g ${HOST_GID:-1000} www-data
RUN chown -R ${HOST_UID:-1000}:${HOST_GID:-1000} $COMPOSER_HOME

ENTRYPOINT "/composer/vendor/phing/phing/bin/phing"
