diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000..3a22466 --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,20 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## Upcoming version +### Added +- Add a dev variant with xdebug, blackfire, etc. + +## [1.0.0] - 2-2-18 +Changed +- Update to PHP 7.1. + +Removed +- Remove unused redis extension. + +## [0.1.0] - 2-1-18 +### Added +- imagick PHP extension \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..51609cd --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +Drupal Application Container +============================ + +These [Dockerfiles](https://docs.docker.com/engine/reference/builder/) define the [massgov/drupal-container](https://hub.docker.com/r/massgov/drupal-container) images. These images are automatically built by Docker Hub. + +Variants +-------- +The variants of this image are: + [`ci`](./ci/) - An image appropriate for use in continuous integration environments. Closely mirrors Acquia's application servers, except that mail is disabled. + [`dev`](./dev/) - An image appropriate for use in development environments. Adds Xdebug, Blackfire, ... + +Environment variables +------------------ +1. XDEBUG_ENABLE: Adds xdebug extension which is configured to autostart (assumes Docker for Mac). + +Making changes +-------------- + +1. Make changes to the Dockerfile for the desired variant. +2. Test changes by building the image locally using `docker-compose build` +3. Note changes in [CHANGELOG.txt](./CHANGELOG.txt). +4. Commit and push changes to this repository: + ``` + git commit -m "My message" + git push origin master + ``` +5. Optionally, tag a new release: + ```bash + git tag 1.0.0 + git push origin 1.0.0 + ``` + When you tag a release, you should also update your code to use the new version as soon as it's available. You can check on the availability on the [build details](https://hub.docker.com/r/massgov/drupal-container/builds/) page. + +Changes that are pushed to the `master` branch are built automatically by Docker hub. For example, a change pushed to master affecting the `ci` variant would update `massgov/drupal-container:ci`. Tags are also built automatically and create a new tagged version of the image. For example, a new tag `4.1.0` would create new versions of all variants, which would be available using `massgov/drupal-container:4.1.0-ci` etc. \ No newline at end of file diff --git a/Dockerfile.ci b/ci/Dockerfile similarity index 87% rename from Dockerfile.ci rename to ci/Dockerfile index d37cccb..a12d0a0 100644 --- a/Dockerfile.ci +++ b/ci/Dockerfile @@ -1,7 +1,6 @@ -FROM php:5.6-apache +FROM php:7.1-apache -# common-php56 ENV DEBIAN_FRONTEND noninteractive ENV APACHE_DOCROOT /var/www/html ENV APACHE_RUN_USER www-data @@ -36,7 +35,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ pngquant \ # For imagick imagemagick \ - libfftw3-double3 \ + libmagickwand-dev \ # for yaml libyaml-dev \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -54,7 +53,6 @@ RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-di intl \ ldap \ mcrypt \ - mysql \ mysqli \ opcache \ pcntl \ @@ -66,9 +64,9 @@ RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-di sysvsem \ sysvshm \ zip \ - && pecl install redis-2.2.8 apcu-4.0.11 raphf-1.1.2 propro-1.0.2 yaml-1.3.1 \ - && docker-php-ext-enable redis apcu raphf propro yaml \ - && pecl install pecl_http-2.5.6 \ + && pecl install apcu raphf propro yaml imagick \ + && docker-php-ext-enable apcu raphf propro yaml imagick \ + && pecl install pecl_http \ && docker-php-ext-enable http \ && printf "upload_max_filesize = 128M\npost_max_size = 128M" > $PHP_INI_DIR/conf.d/00-max_filesize.ini @@ -88,13 +86,13 @@ RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/bi && rm -r /root/.composer/cache \ && curl -L https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz | tar -C /usr/local/bin -xzv \ && chmod +x /usr/local/bin/dockerize \ - && ssh-keyscan github.com >> /etc/ssh/ssh_known_hosts + && ssh-keyscan github.com >> /etc/ssh/ssh_known_hosts \ + && git config --global core.safecrlf false -ADD mpm_prefork.conf /etc/apache2/mods-enabled/mpm_prefork.conf -ADD php.ini.ci $PHP_INI_DIR/conf.d/zz-overrides.ini -ADD scripts/* /usr/local/bin/ +ADD etc/mpm_prefork.conf /etc/apache2/mods-enabled/mpm_prefork.conf +ADD etc/php-overrides.ini $PHP_INI_DIR/conf.d/zz-overrides.ini +ADD bin/* /usr/local/bin/ CMD ["apache2-foreground-enhanced"] -# /common-php56 # NodeJS, RUN apt-get update \ diff --git a/scripts/apache2-foreground-enhanced b/ci/bin/apache2-foreground-enhanced similarity index 100% rename from scripts/apache2-foreground-enhanced rename to ci/bin/apache2-foreground-enhanced diff --git a/mpm_prefork.conf b/ci/etc/mpm_prefork.conf similarity index 100% rename from mpm_prefork.conf rename to ci/etc/mpm_prefork.conf diff --git a/php.ini.ci b/ci/etc/php-overrides.ini similarity index 100% rename from php.ini.ci rename to ci/etc/php-overrides.ini diff --git a/dev/Dockerfile b/dev/Dockerfile new file mode 100644 index 0000000..ebfd2c6 --- /dev/null +++ b/dev/Dockerfile @@ -0,0 +1,124 @@ + +FROM php:7.1-apache + +ENV DEBIAN_FRONTEND noninteractive +ENV APACHE_DOCROOT /var/www/html +ENV APACHE_RUN_USER www-data +ENV APACHE_RUN_GROUP www-data +ENV APACHE_REQUEST_WORKERS 150 +ENV PATH=/var/www/mass.local/vendor/bin:$PATH + +RUN apt-get update && apt-get install -y --no-install-recommends \ + # for bz2 + bzip2 libbz2-dev \ + # for ftp + libssl-dev \ + # for gd + libfreetype6-dev libjpeg62-turbo-dev libpng12-dev \ + # for intl + libicu-dev \ + # for dom + libxml2-dev \ + # for ldap + libldap2-dev \ + # for mcrypt + libmcrypt-dev \ + # for mysql + mysql-client \ + # for git + git \ + # for ssh client only + openssh-client \ + # For image optimization + jpegoptim \ + optipng \ + pngquant \ + # For imagick + imagemagick \ + libmagickwand-dev \ + # for yaml + libyaml-dev \ + && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ + && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu \ + && docker-php-ext-install -j$(nproc) \ + bcmath \ + bz2 \ + calendar \ + exif \ + ftp \ + gd \ + gettext \ + intl \ + ldap \ + mcrypt \ + mysqli \ + opcache \ + pcntl \ + pdo_mysql \ + shmop \ + soap \ + sockets \ + sysvmsg \ + sysvsem \ + sysvshm \ + zip \ + && pecl install apcu raphf propro yaml imagick \ + && docker-php-ext-enable apcu raphf propro yaml imagick \ + && pecl install pecl_http \ + && docker-php-ext-enable http \ + && printf "upload_max_filesize = 128M\npost_max_size = 128M" > $PHP_INI_DIR/conf.d/00-max_filesize.ini + +# Configure Apache: +RUN a2enmod rewrite headers expires \ + && sed -i "/User www-data/c\User \$\{APACHE_RUN_USER\}" /etc/apache2/apache2.conf \ + && sed -i "/Group www-data/c\Group \$\{APACHE_RUN_GROUP\}" /etc/apache2/apache2.conf \ + && sed -i "/DocumentRoot \/var\/www\/html/c\\\tDocumentRoot \$\{APACHE_DOCROOT\}" /etc/apache2/sites-enabled/000-default.conf \ + # Preemptively add a user 1000, for use with $APACHE_RUN_USER on osx + && adduser --uid 1000 --gecos 'My OSX User' --disabled-password osxuser + +# Install CLI tools: +RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/bin/composer \ + && mkdir /usr/share/composer \ + && cd /usr/share/composer \ + && composer init --no-interaction && composer config bin-dir /usr/local/bin \ + && rm -r /root/.composer/cache \ + && curl -L https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz | tar -C /usr/local/bin -xzv \ + && chmod +x /usr/local/bin/dockerize \ + && ssh-keyscan github.com >> /etc/ssh/ssh_known_hosts \ + && git config --global core.safecrlf false + +ADD etc/mpm_prefork.conf /etc/apache2/mods-enabled/mpm_prefork.conf +ADD etc/php-overrides.ini $PHP_INI_DIR/conf.d/zz-overrides.ini +ADD bin/* /usr/local/bin/ +CMD ["apache2-foreground-enhanced"] + +# NodeJS, +RUN apt-get update \ + && apt-get install -y apt-transport-https lsb-release > /dev/null 2>&1 \ + && curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \ + && echo 'deb https://deb.nodesource.com/node_6.x jessie main' > /etc/apt/sources.list.d/nodesource.list \ + && echo 'deb-src https://deb.nodesource.com/node_6.x jessie main' >> /etc/apt/sources.list.d/nodesource.list \ + && apt-get update \ + && apt-get install nodejs \ + && npm install -g yarn \ + && npm cache clean --force \ + && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Install development tools. +RUN pecl install xdebug \ + && docker-php-ext-enable xdebug \ + && echo "xdebug.remote_enable=on\nxdebug.remote_host=docker.for.mac.host.internal\nxdebug.remote_autostart=on\nxdebug.idekey=PHPSTORM" > $PHP_INI_DIR/conf.d/xdebug.ini \ + # Install Blackfire Probe + && version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \ + && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \ + && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \ + && mv /tmp/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \ + && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \ + # Install blackfire CLI + && mkdir -p /tmp/blackfire \ + && curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire \ + && mv /tmp/blackfire/blackfire /usr/bin/blackfire \ + && rm -Rf /tmp/blackfire + diff --git a/dev/bin/apache2-foreground-enhanced b/dev/bin/apache2-foreground-enhanced new file mode 100755 index 0000000..f25ecc8 --- /dev/null +++ b/dev/bin/apache2-foreground-enhanced @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +# Allow a specific timezone to be set and passed into PHP +if [ -n "$TZ" ]; then + # Configure PHP to use $TZ variable. + echo "date.timezone=$TZ" > $PHP_INI_DIR/conf.d/timezone.ini +fi + +chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP /var/lock/apache2 /var/run/apache2 /var/log/apache2 + +# Allow a script to run on startup. +if [ -x "/on-docker-boot" ]; then + /on-docker-boot +fi + +# Enable Xdebug by setting XDEBUG_ENABLE=1. +if [ -z "$XDEBUG_ENABLE" ]; then + # Comment out .so include. + sed -i 's/^\(zend_extension=.*xdebug\.so\)$/; \1/' $PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini +else + # Uncomment + sed -i 's/^; \(zend_extension=.*xdebug\.so\)$/\1/' $PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini +fi + +exec apache2-foreground \ No newline at end of file diff --git a/dev/etc/mpm_prefork.conf b/dev/etc/mpm_prefork.conf new file mode 100644 index 0000000..cffaac8 --- /dev/null +++ b/dev/etc/mpm_prefork.conf @@ -0,0 +1,7 @@ + + StartServers 5 + MinSpareServers 5 + MaxSpareServers 10 + MaxRequestWorkers ${APACHE_REQUEST_WORKERS} + MaxConnectionsPerChild 5000 + \ No newline at end of file diff --git a/dev/etc/php-overrides.ini b/dev/etc/php-overrides.ini new file mode 100644 index 0000000..1a5c50b --- /dev/null +++ b/dev/etc/php-overrides.ini @@ -0,0 +1,20 @@ +; This is not a full PHP.ini file. It only contains +; overrides to the default php.ini. It is copied into +; the container at $PHP_INI_DIR/conf.d/zz-overrides.ini + +upload_max_filesize = 128M +post_max_size = 128M +memory_limit = 256M +sendmail_path = /bin/true +date.timezone = UTC + +;This is for APCu. +apc.ttl=7200 + +opcache.fast_shutdown=1 +opcache.interned_strings_buffer=16 +opcache.log_verbosity_level=2 +opcache.max_accelerated_files=4000 +opcache.memory_consumption=96 +opcache.optimization_level=0 +opcache.revalidate_freq=0 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ea644b3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +# This docker-compose file can be used to quickly build containers for testing changes. +# It is not a functional application. +# +# To build these containers, run: +# +# docker-compose build +# +# To build only a single container: +# +# docker-compose build ci +# +version: '3' + +services: + ci: + image: massgov/drupal-container:ci + build: ./ci + + dev: + image: massgov/drupal-container:ci + build: ./dev + ports: + - ${DOCKER_PORTS-80:80} \ No newline at end of file diff --git a/scripts/check-apache-mem b/scripts/check-apache-mem deleted file mode 100755 index a0a7f4d..0000000 --- a/scripts/check-apache-mem +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}' \ No newline at end of file