From ce292fbe6aa5012532975ad89cdb9f83b2aea428 Mon Sep 17 00:00:00 2001 From: Daryn Warriner Date: Thu, 29 Aug 2019 12:09:52 -0500 Subject: [PATCH 1/6] Add opcache env defaults --- Dockerfile | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 82f9848..4c00cbb 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,21 @@ FROM php:7.2-apache-stretch MAINTAINER Firespring "info.dev@firespring.com" -ENV DEBIAN_FRONTEND noninteractive -ENV SERVER_NAME=localhost -ENV APACHE_RUN_USER=www-data -ENV APACHE_RUN_GROUP=www-data -ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid -ENV APACHE_RUN_DIR=/var/run/apache2 -ENV APACHE_LOCK_DIR=/var/lock/apache2 -ENV APACHE_LOG_DIR=/var/log/apache2 -ENV APACHE_LOG_LEVEL=warn -ENV APACHE_CUSTOM_LOG_FILE=/proc/self/fd/1 -ENV APACHE_ERROR_LOG_FILE=/proc/self/fd/2 +ENV DEBIAN_FRONTEND="noninteractive" \ + SERVER_NAME="localhost" \ + APACHE_RUN_USER="www-data" \ + APACHE_RUN_GROUP="www-data" \ + APACHE_PID_FILE="/var/run/apache2/apache2.pid" \ + APACHE_RUN_DIR="/var/run/apache2" \ + APACHE_LOCK_DIR="/var/lock/apache2" \ + APACHE_LOG_DIR="/var/log/apache2" \ + APACHE_LOG_LEVEL="warn" \ + APACHE_CUSTOM_LOG_FILE="/proc/self/fd/1" \ + APACHE_ERROR_LOG_FILE="/proc/self/fd/2" \ + PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \ + PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \ + PHP_OPCACHE_MEMORY_CONSUMPTION="192" \ + PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" RUN mkdir -p /var/run/apache2 /var/lock/apache2 From e655583bd358e3c85717bd41af783f7c156efbb6 Mon Sep 17 00:00:00 2001 From: Daryn Warriner Date: Thu, 29 Aug 2019 12:10:42 -0500 Subject: [PATCH 2/6] docker install opcache php extension --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 4c00cbb..cf04e94 100755 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,7 @@ RUN pecl config-set php_ini "$PHP_INI_DIR" \ && docker-php-ext-enable redis \ && docker-php-ext-install mysqli \ && docker-php-ext-install zip \ + && docker-php-ext-install opcache \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd From 20d0edce9b010232bffed9826ba131dc43f05424 Mon Sep 17 00:00:00 2001 From: Daryn Warriner Date: Thu, 29 Aug 2019 12:11:46 -0500 Subject: [PATCH 3/6] Copy in opcache php ini config with default settings --- Dockerfile | 1 + php/conf.d/opcache.ini | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 php/conf.d/opcache.ini diff --git a/Dockerfile b/Dockerfile index cf04e94..a0f43ea 100755 --- a/Dockerfile +++ b/Dockerfile @@ -84,6 +84,7 @@ ENV APACHE_RUN_DIR /var/run/apache2 ENV APPLICATION_ENV local COPY apache2/apache2.conf /etc/apache2/ +COPY php/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini COPY apache2-foreground /usr/local/bin/ diff --git a/php/conf.d/opcache.ini b/php/conf.d/opcache.ini new file mode 100644 index 0000000..557b57d --- /dev/null +++ b/php/conf.d/opcache.ini @@ -0,0 +1,11 @@ +[opcache] + +opcache.enable=1 +opcache.revalidate_freq=0 +opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS} +opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES} +opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION} +opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE} +opcache.interned_strings_buffer=16 + +opcache.fast_shutdown=1 From 6bd4ec6c61ee815c23b36dbdd15c29da6f809eaa Mon Sep 17 00:00:00 2001 From: Daryn Warriner Date: Thu, 29 Aug 2019 12:13:52 -0500 Subject: [PATCH 4/6] Move package and tmp file cleanup to right after use to reduce layer size. Otherwise all the layers in between are aware of and have unnecessary access to the files. --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a0f43ea..ff76062 100755 --- a/Dockerfile +++ b/Dockerfile @@ -40,8 +40,12 @@ RUN apt-get update && apt-get install -y --force-yes \ # Build Deps build-essential curl make \ # Other Deps - pdftk zip git libpng-dev libjpeg-dev libjpeg62-turbo-dev libfreetype6-dev libwebp-dev libxpm-dev + pdftk zip git libpng-dev libjpeg-dev libjpeg62-turbo-dev libfreetype6-dev libwebp-dev libxpm-dev \ + # clean up packages here otherwise the files will be in every layer + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# install and configure php modules RUN pecl config-set php_ini "$PHP_INI_DIR" \ && pear install PHP_CodeSniffer \ && pecl install xdebug-2.6.1 \ @@ -75,9 +79,6 @@ RUN git clone https://github.com/nrk/phpiredis.git \ RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer -RUN apt-get clean \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - # Apache Config ENV APACHE_LOCK_DIR /var/lock/apache2 ENV APACHE_RUN_DIR /var/run/apache2 From 5f341bfe876ee21485272d66caf98406c0c67ef2 Mon Sep 17 00:00:00 2001 From: Daryn Warriner Date: Thu, 29 Aug 2019 12:14:41 -0500 Subject: [PATCH 5/6] Remove php-xcache extension. It doesn't work for 7.2 and isn't needed since opcache is built in --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ff76062..8d48fd8 100755 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN set -eux; \ RUN apt-get update && apt-get install -y --force-yes \ # Apache\PHP php-mysql php-dev php-gd php-redis libhiredis-dev libhiredis0.13 libphp-predis \ - libapache2-mod-gnutls php-zip php-cli php-xcache \ + libapache2-mod-gnutls php-zip php-cli \ # Build Deps build-essential curl make \ # Other Deps From b8120c9d9b615b6bfa7e46e04a795b0a6ffa4ced Mon Sep 17 00:00:00 2001 From: Daryn Warriner Date: Thu, 29 Aug 2019 12:16:46 -0500 Subject: [PATCH 6/6] Reorganize package installs so we can just run apt-get update once and cleanup after installing. --- Dockerfile | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8d48fd8..d8dc2b9 100755 --- a/Dockerfile +++ b/Dockerfile @@ -19,21 +19,18 @@ ENV DEBIAN_FRONTEND="noninteractive" \ RUN mkdir -p /var/run/apache2 /var/lock/apache2 -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install apt-utils apt-transport-https software-properties-common gnupg - -RUN apt-get update && LC_ALL=C.UTF-8 add-apt-repository 'deb https://packages.sury.org/php/ stretch main' \ - && apt-key adv --fetch-keys https://packages.sury.org/php/apt.gpg - -# Use the default production configuration -# except Prioritize Sury php-gd package -RUN set -eux; \ +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install apt-utils apt-transport-https software-properties-common gnupg \ + && LC_ALL=C.UTF-8 add-apt-repository 'deb https://packages.sury.org/php/ stretch main' \ + && apt-key adv --fetch-keys https://packages.sury.org/php/apt.gpg \ + # Use the default production configuration + # except Prioritize Sury php-gd package + && set -eux; \ { \ echo 'Package: php*-gd'; \ echo 'Pin: release *'; \ echo 'Pin-Priority: 1'; \ - } >> /etc/apt/preferences.d/no-debian-php - -RUN apt-get update && apt-get install -y --force-yes \ + } >> /etc/apt/preferences.d/no-debian-php \ + && apt-get update && apt-get install -y --force-yes \ # Apache\PHP php-mysql php-dev php-gd php-redis libhiredis-dev libhiredis0.13 libphp-predis \ libapache2-mod-gnutls php-zip php-cli \