Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Actimel committed Oct 29, 2019
0 parents commit bae7715
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
98 changes: 98 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
FROM php:7.3.11-fpm-stretch

# install required tools
# git for computing diffs
# wget for installation of other tools
# gnupg and g++ for gd extension
# locales for locale-gen command
# apt-utils so package configuartion does not get delayed
# unzip to ommit composer zip packages corruption
# dialog for apt-get to be
# git for computing diffs and for npm to download packages
# libpng-dev needed by "gd" extension
# libzip-dev needed by "zip" extension
# libicu-dev for intl extension
# libpg-dev for connection to postgres database
# autoconf needed by "redis" extension
RUN apt-get update && \
apt-get install -y \
wget \
gnupg \
g++ \
locales \
unzip \
dialog \
apt-utils \
git \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libzip-dev \
libicu-dev \
libpq-dev \
vim \
nano \
mc \
htop \
autoconf \
&& apt-get clean

# Install NodeJS
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash
RUN apt-get update && apt-get install -y nodejs && apt-get clean

# install Composer
COPY scripts/install-composer.sh /usr/local/bin/docker-install-composer.sh
RUN /usr/local/bin/docker-install-composer.sh

# "gd" extension needs to have specified jpeg and freetype dir for jpg/jpeg images support
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/

# install necessary tools for running application
RUN docker-php-ext-install \
bcmath \
gd \
intl \
opcache \
pgsql \
pdo_pgsql \
zip

# install grunt cli used by frontend developers for continuous generating of css files
RUN npm install -g grunt-cli

# install PostgreSQl client for dumping database
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" > /etc/apt/sources.list.d/PostgreSQL.list' && \
apt-get update && apt-get install -y postgresql-10 postgresql-client-10 && apt-get clean

# install redis extension
RUN pecl install redis-4.1.1 && \
docker-php-ext-enable redis

# install locales and switch to en_US.utf8 in order to enable UTF-8 support
# see http://jaredmarkell.com/docker-and-locales/ from where was this code taken
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# overwrite the original entry-point from the PHP Docker image with our own
COPY scripts/docker-php-entrypoint.sh /usr/local/bin/docker-php-entrypoint.sh
RUN /usr/local/bin/docker-php-entrypoint.sh

# set www-data user his home directory
# the user "www-data" is used when running the image, and therefore should own the workdir
RUN usermod -m -d /home/www-data www-data && \
mkdir -p /var/www/html && \
chown -R www-data:www-data /home/www-data /var/www/html

# Switch to user
USER www-data

# hirak/prestissimo makes the install of Composer dependencies faster by parallel downloading
RUN composer global require hirak/prestissimo

# set COMPOSER_MEMORY_LIMIT to -1 (i.e. unlimited - this is a hotfix until https://github.com/shopsys/shopsys/issues/634 is solved)
ENV COMPOSER_MEMORY_LIMIT=-1
21 changes: 21 additions & 0 deletions scripts/docker-php-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e

# this file is an extension of the original entry-point from the PHP Docker image
# https://github.com/docker-library/php/blob/master/docker-php-entrypoint

# reading from a named pipe and writing to stdout via "tail -f"
# this workaround prevents logs from being output to console during console commands
# multistage build uses different UIDs and logpipe is transformed into something else than pipe so best way is to recreate it
PIPE=/tmp/log-pipe
rm -rf $PIPE
mkfifo $PIPE
chmod 666 $PIPE
tail -f $PIPE &

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi

exec "$@"
20 changes: 20 additions & 0 deletions scripts/install-composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# copied from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
# option --filename=composer is used so it can be called without the .phar extension

EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer
RESULT=$?
rm composer-setup.php
exit $RESULT

0 comments on commit bae7715

Please sign in to comment.