|
| 1 | +FROM behance/docker-nginx:6.1 |
| 2 | +MAINTAINER Bryan Latten <latten@adobe.com> |
| 3 | + |
| 4 | +# Set TERM to suppress warning messages. |
| 5 | +ENV CONF_PHPFPM=/etc/php/5.6/fpm/php-fpm.conf \ |
| 6 | + CONF_PHPMODS=/etc/php/5.6/mods-available \ |
| 7 | + CONF_FPMPOOL=/etc/php/5.6/fpm/pool.d/www.conf \ |
| 8 | + CONF_FPMOVERRIDES=/etc/php/5.6/fpm/conf.d/overrides.user.ini \ |
| 9 | + APP_ROOT=/app \ |
| 10 | + PHP_FPM_MAX_CHILDREN=4096 \ |
| 11 | + PHP_FPM_START_SERVERS=20 \ |
| 12 | + PHP_FPM_MAX_REQUESTS=1024 \ |
| 13 | + PHP_FPM_MIN_SPARE_SERVERS=5 \ |
| 14 | + PHP_FPM_MAX_SPARE_SERVERS=128 \ |
| 15 | + PHP_FPM_MEMORY_LIMIT=256M \ |
| 16 | + PHP_FPM_MAX_EXECUTION_TIME=60 \ |
| 17 | + PHP_FPM_UPLOAD_MAX_FILESIZE=1M \ |
| 18 | + NEWRELIC_VERSION=6.7.0.174 |
| 19 | + |
| 20 | +# Ensure cleanup script is available for the next command |
| 21 | +ADD ./container/root/clean.sh /clean.sh |
| 22 | + |
| 23 | +# Ensure the latest base packages are up to date (don't require a parent rebuild) |
| 24 | +RUN apt-get update -q && \ |
| 25 | + apt-get upgrade -yqq && \ |
| 26 | + apt-get install -yqq \ |
| 27 | + git \ |
| 28 | + curl \ |
| 29 | + wget \ |
| 30 | + software-properties-common \ |
| 31 | + && \ |
| 32 | + locale-gen en_US.UTF-8 && export LANG=en_US.UTF-8 && \ |
| 33 | + add-apt-repository ppa:git-core/ppa -y && \ |
| 34 | + add-apt-repository ppa:ondrej/php -y && \ |
| 35 | + echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list && \ |
| 36 | + wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add - && \ |
| 37 | + # Prevent newrelic install from prompting for input \ |
| 38 | + echo newrelic-php5 newrelic-php5/application-name string "REPLACE_NEWRELIC_APP" | debconf-set-selections && \ |
| 39 | + echo newrelic-php5 newrelic-php5/license-key string "REPLACE_NEWRELIC_LICENSE" | debconf-set-selections && \ |
| 40 | + # Perform cleanup \ |
| 41 | + apt-get remove --purge -yq \ |
| 42 | + patch \ |
| 43 | + software-properties-common \ |
| 44 | + wget \ |
| 45 | + && \ |
| 46 | + /clean.sh |
| 47 | + |
| 48 | +# Add PHP and support packages \ |
| 49 | +RUN apt-get update -q && \ |
| 50 | + apt-get -yqq install \ |
| 51 | + php5.6 \ |
| 52 | + php5.6-apcu \ |
| 53 | + php5.6-bz2 \ |
| 54 | + php5.6-curl \ |
| 55 | + php5.6-fpm \ |
| 56 | + php5.6-gd \ |
| 57 | + php5.6-igbinary \ |
| 58 | + php5.6-intl \ |
| 59 | + php5.6-json \ |
| 60 | + php5.6-mbstring \ |
| 61 | + php5.6-mcrypt \ |
| 62 | + php5.6-mysql \ |
| 63 | + php5.6-pgsql \ |
| 64 | + php5.6-gearman \ |
| 65 | + php5.6-memcache \ |
| 66 | + php5.6-memcached \ |
| 67 | + php5.6-redis \ |
| 68 | + php5.6-xdebug \ |
| 69 | + php5.6-xml \ |
| 70 | + php5.6-yaml \ |
| 71 | + php5.6-zip \ |
| 72 | + newrelic-php5=${NEWRELIC_VERSION} \ |
| 73 | + newrelic-php5-common=${NEWRELIC_VERSION} \ |
| 74 | + newrelic-daemon=${NEWRELIC_VERSION} \ |
| 75 | + && \ |
| 76 | + phpdismod pdo_pgsql && \ |
| 77 | + phpdismod pgsql && \ |
| 78 | + phpdismod redis && \ |
| 79 | + phpdismod yaml && \ |
| 80 | + phpdismod xdebug && \ |
| 81 | + curl -sS https://getcomposer.org/installer | php && \ |
| 82 | + mv composer.phar /usr/local/bin/composer && \ |
| 83 | + /clean.sh |
| 84 | + |
| 85 | +# Temporary Hack: unsupported PHP extensions are dumping old PHP pre-reqs into the mix |
| 86 | +# Even marking them to never install doesn't work. Removing for now, until all extensions are supported |
| 87 | +RUN apt-get remove --purge -yq \ |
| 88 | + php5.5 \ |
| 89 | + php7.0 \ |
| 90 | + php7.1 |
| 91 | + |
| 92 | +# - Configure php-fpm to use TCP rather than unix socket (for stability), fastcgi_pass is also set by /etc/nginx/sites-available/default |
| 93 | +# - Set base directory for all php (/app), difficult to use APP_PATH as a replacement, otherwise / breaks command |
| 94 | +# - Baseline "optimizations" before benchmarking succeeded at concurrency of 150 |
| 95 | +# @see http://www.codestance.com/tutorials-archive/install-and-configure-php-fpm-on-nginx-385 |
| 96 | +# - Ensure environment variables aren't cleaned, will make it into FPM workers |
| 97 | +# - php-fpm processes must pick up stdout/stderr from workers, will cause minor performance decrease (but is required) |
| 98 | +# - Disable systemd integration, it is not present nor responsible for running service |
| 99 | +# - Enforce ACL that only 127.0.0.1 may connect |
| 100 | +# - Allow FPM to pick up extra configuration in fpm/conf.d folder |
| 101 | + |
| 102 | +RUN sed -i "s/listen = .*/listen = 127.0.0.1:9000/" $CONF_FPMPOOL && \ |
| 103 | + sed -i "s/;chdir = .*/chdir = \/app/" $CONF_FPMPOOL && \ |
| 104 | + sed -i "s/pm.max_children = .*/pm.max_children = \${PHP_FPM_MAX_CHILDREN}/" $CONF_FPMPOOL && \ |
| 105 | + sed -i "s/pm.start_servers = .*/pm.start_servers = \${PHP_FPM_START_SERVERS}/" $CONF_FPMPOOL && \ |
| 106 | + sed -i "s/;pm.max_requests = .*/pm.max_requests = \${PHP_FPM_MAX_REQUESTS}/" $CONF_FPMPOOL && \ |
| 107 | + sed -i "s/pm.min_spare_servers = .*/pm.min_spare_servers = \${PHP_FPM_MIN_SPARE_SERVERS}/" $CONF_FPMPOOL && \ |
| 108 | + sed -i "s/pm.max_spare_servers = .*/pm.max_spare_servers = \${PHP_FPM_MAX_SPARE_SERVERS}/" $CONF_FPMPOOL && \ |
| 109 | + sed -i "s/;clear_env/clear_env/" $CONF_FPMPOOL && \ |
| 110 | + sed -i "s/;catch_workers_output/catch_workers_output/" $CONF_FPMPOOL && \ |
| 111 | + sed -i "s/error_log = .*/error_log = \/dev\/stdout/" $CONF_PHPFPM && \ |
| 112 | + sed -i "s/;listen.allowed_clients/listen.allowed_clients/" $CONF_PHPFPM && \ |
| 113 | + # Since PHP-FPM will be run without root privileges, comment these lines to prevent any startup warnings \ |
| 114 | + sed -i "s/^user =/;user =/" $CONF_FPMPOOL && \ |
| 115 | + sed -i "s/^group =/;group =/" $CONF_FPMPOOL && \ |
| 116 | + # Allow NewRelic to be partially configured by environment variables, set sane defaults \ |
| 117 | + sed -i "s/newrelic.appname = .*/newrelic.appname = \"\${REPLACE_NEWRELIC_APP}\"/" $CONF_PHPMODS/newrelic.ini && \ |
| 118 | + sed -i "s/newrelic.license = .*/newrelic.license = \"\${REPLACE_NEWRELIC_LICENSE}\"/" $CONF_PHPMODS/newrelic.ini && \ |
| 119 | + sed -i "s/newrelic.logfile = .*/newrelic.logfile = \"\/dev\/stdout\"/" $CONF_PHPMODS/newrelic.ini && \ |
| 120 | + sed -i "s/newrelic.daemon.logfile = .*/newrelic.daemon.logfile = \"\/dev\/stdout\"/" $CONF_PHPMODS/newrelic.ini && \ |
| 121 | + sed -i "s/;newrelic.loglevel = .*/newrelic.loglevel = \"warning\"/" $CONF_PHPMODS/newrelic.ini && \ |
| 122 | + sed -i "s/;newrelic.daemon.loglevel = .*/newrelic.daemon.loglevel = \"warning\"/" $CONF_PHPMODS/newrelic.ini && \ |
| 123 | + # Match FPM timeout directive with .ini max execution time |
| 124 | + sed -i "s/;*request_terminate_timeout = .*/request_terminate_timeout = \${PHP_FPM_MAX_EXECUTION_TIME}/" $CONF_FPMPOOL && \ |
| 125 | + # Required for php-fpm to place .sock file into, fails otherwise \ |
| 126 | + mkdir /var/run/php/ && \ |
| 127 | + chown -R $NOT_ROOT_USER:$NOT_ROOT_USER /var/run/php /var/run/lock /var/log/newrelic |
| 128 | + |
| 129 | +# Overlay the root filesystem from this repo |
| 130 | +COPY ./container/root / |
| 131 | + |
| 132 | +# Make additional hacks to migrate files/config from 7.0 --> 5.6 folder |
| 133 | +RUN cp /etc/php/7.0/mods-available/* $CONF_PHPMODS && \ |
| 134 | + cp /etc/php/7.0/fpm/conf.d/overrides.user.ini $CONF_FPMOVERRIDES && \ |
| 135 | + # Hack: share startup scripts with php 7.0 version by symlinking \ |
| 136 | + ln -s /usr/sbin/php-fpm5.6 /usr/sbin/php-fpm7.0 && \ |
| 137 | + # Override default ini values for both CLI + FPM \ |
| 138 | + phpenmod overrides && \ |
| 139 | + # Set nginx to listen on defined port \ |
| 140 | + sed -i "s/listen [0-9]*;/listen ${CONTAINER_PORT};/" $CONF_NGINX_SITE && \ |
| 141 | + # Enable NewRelic via Ubuntu symlinks, but disable in file. Cross-variant startup script uncomments with env vars. |
| 142 | + phpenmod newrelic && \ |
| 143 | + sed -i 's/extension\s\?=/;extension =/' $CONF_PHPMODS/newrelic.ini && \ |
| 144 | + # Enable status page at "/__status" |
| 145 | + sed -i 's/;pm.status_path = .*/pm.status_path = \/__status/' $CONF_FPMPOOL |
| 146 | + |
| 147 | +RUN goss -g /tests/php-fpm/legacy.goss.yaml validate && \ |
| 148 | + /aufs_hack.sh |
0 commit comments