Skip to content

Instantly share code, notes, and snippets.

@lorello
Last active February 19, 2020 21:04
Show Gist options
  • Select an option

  • Save lorello/40ec6f61ab7936d060a22214a396385e to your computer and use it in GitHub Desktop.

Select an option

Save lorello/40ec6f61ab7936d060a22214a396385e to your computer and use it in GitHub Desktop.
Manage private composer repos during docker build
FROM php:7.2.26-fpm-stretch
# Fixed version with OS Debian strech for the issue here explained
# https://github.com/docker-library/php/issues/865
# Set defaults for variables used by run.sh
ENV COMPOSER_HOME=/root/.composer
# Create Composer directory (cache and auth files) & Get Composer
RUN mkdir -p $COMPOSER_HOME \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www
COPY composer.json composer.lock /var/www/
# the following variable exists only during build-time
# pass the correct value during build:
# $ docker build --build-arg github_token=abcdef123456 # [...]
#
ARG GITHUB_TOKEN=abcdef123456
# Avoid the following line, because leave the environment variable
# in the final image
# ENV GITHUB_TOKEN=$github_token
# The secure way to do it is to prepend the command with the variable definition:
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN echo "Running composer" \
&& composer global require hirak/prestissimo \
&& composer global config github-oauth.github.com "$GITHUB_TOKEN" \
&& composer install --prefer-dist --no-scripts --no-dev \
&& rm -rf /root/.composer
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment