Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle xdebug on and off at startup #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 10 additions & 12 deletions Dockerfile.ci → ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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/*
Expand All @@ -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 \
Expand All @@ -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

Expand All @@ -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 \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
124 changes: 124 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

26 changes: 26 additions & 0 deletions dev/bin/apache2-foreground-enhanced
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions dev/etc/mpm_prefork.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers ${APACHE_REQUEST_WORKERS}
MaxConnectionsPerChild 5000
</IfModule>
20 changes: 20 additions & 0 deletions dev/etc/php-overrides.ini
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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}
3 changes: 0 additions & 3 deletions scripts/check-apache-mem

This file was deleted.