Modular software, modular Infrastructure - let's build base Docker images together.

Jakub Piasecki

Diamond Sponsor

Platinum Sponsor

Gold Sponsor

Who am I

  • @zaporylie
  • CTO @Linkfactory A/S
  • drupal-docker lead
  • Drupal contributor

What is this session about

  • Infrastructure as a code
  • Infrastructure's modularity
  • Best practices
  • Brainstorming

What is this session NOT about

  • Giving simple recipes
  • Running Docker on production :)

Glossary

  • Application - the (Drupal) project you want to/are running
  • Infrastructure - the environment in which the application is running

Application heavily depends on the infrastructure, therefore infrastructure must be committed to the application.

Infrastructure as Code. It must follow basic coding principles.

  • Vagrantfile
  • Ansible
  • Docker
  • more...

Dockerfile


              FROM php:7.0-fpm-alpine
              MAINTAINER drupal-docker

              RUN apk add --no-cache --virtual .dd-build-deps libpng-dev libjpeg-turbo-dev postgresql-dev libxml2-dev $PHPIZE_DEPS \
              && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
              && docker-php-ext-install gd mbstring pdo_mysql pdo_pgsql zip \
              && docker-php-ext-install opcache bcmath soap \
              && pecl install redis-3.1.1 \
              && docker-php-ext-enable redis \
              && apk add --no-cache libpng libjpeg libpq libxml2 \
              && apk del .dd-build-deps

              COPY drupal-*.ini /usr/local/etc/php/conf.d/
            

Does Docker follow programming design principles?

Let's find out together

DRY

Do not repeat yourself

Dockerfile


              FROM php:7.0-fpm-alpine
              MAINTAINER drupal-docker

              RUN apk add --no-cache --virtual .dd-build-deps libpng-dev libjpeg-turbo-dev postgresql-dev libxml2-dev $PHPIZE_DEPS \
              && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
              && docker-php-ext-install gd mbstring pdo_mysql pdo_pgsql zip \
              && docker-php-ext-install opcache bcmath soap \
              && pecl install redis-3.1.1 \
              && docker-php-ext-enable redis \
              && apk add --no-cache libpng libjpeg libpq libxml2 \
              && apk del .dd-build-deps

              COPY drupal-*.ini /usr/local/etc/php/conf.d/
            
  • Images
    • Inheritance
    • ADD/COPY
  • Repositories
  • more?

KISS

Keep it simple stupid

Dockerfile


              FROM drupaldocker/php:7.0-fpm-2.x
              MAINTAINER drupal-docker

              RUN apk add --no-cache --virtual .dd-build-deps $PHPIZE_DEPS \
               && pecl install xdebug-2.6.0beta1 \
               && docker-php-ext-enable xdebug \
               && apk del .dd-build-deps

              COPY drupal-*.ini /usr/local/etc/php/conf.d/
            
  • just 7 lines
  • 4 instructions
  • 3 effective instructions
  • easy ro read and write

YAGNI

You ain't gonna need it

Dockerfile - php-fpm


              FROM php:7.0-fpm-alpine
              MAINTAINER drupal-docker

              RUN apk add --no-cache --virtual .dd-build-deps libpng-dev libjpeg-turbo-dev postgresql-dev libxml2-dev $PHPIZE_DEPS \
                 && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
                 && docker-php-ext-install gd mbstring pdo_mysql pdo_pgsql zip \
                 && docker-php-ext-install opcache bcmath soap \
                 && pecl install redis-3.1.1 \
                 && docker-php-ext-enable redis \
                 && apk add --no-cache libpng libjpeg libpq libxml2 \
                 && apk del .dd-build-deps

              COPY drupal-*.ini /usr/local/etc/php/conf.d/
            
  • Only instructions absolutely required to run service/container added to Dockerfile
  • apk cache emptied
  • php extensions limitted to those required by core and/or most popular distributions

SOLID

  • S - Single responsibility principle
  • O - Open/closed principle
  • L - Liskov substitution principle
  • I - Interface segregation principle
  • D - Dependency inversion principle

Dockerfile


              FROM php:7.0-fpm-alpine
              MAINTAINER drupal-docker

              RUN apk add --no-cache --virtual .dd-build-deps libpng-dev libjpeg-turbo-dev postgresql-dev libxml2-dev $PHPIZE_DEPS \
                 && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
                 && docker-php-ext-install gd mbstring pdo_mysql pdo_pgsql zip \
                 && docker-php-ext-install opcache bcmath soap \
                 && pecl install redis-3.1.1 \
                 && docker-php-ext-enable redis \
                 && apk add --no-cache libpng libjpeg libpq libxml2 \
                 && apk del .dd-build-deps

              COPY drupal-*.ini /usr/local/etc/php/conf.d/
            

Så: Can we think of infrastructure as of code?

My answer: YES!

Så: Should we start thinking of infrastructure as of code!

My answer: DEFINITELY!

Starting now!

Best practices

  • run single process per container
  • decouple infrastructure
  • don’t install unnecessary packages
  • think about image size
    • share parent images to minimize overall size
    • clear the cache
    • think layers

How Docker can be used for Drupal applications

Docker+™

  • Lando
  • DDEV
  • Docksal
  • more...

Docker4Drupal (Wodby)

  • good separation between services
  • amazing adoption
  • ...but to much can be configured via ENV (!OCP :()
  • ...but in private hands

amazee.io

  • production ready
  • opensource
  • documentation++
  • ...but overcomplicated?
  • ...but in private hands

What should we do?

Static service container wrapper


              // Returns a Drupal\Core\Datetime\Date object.
              $date = \Drupal::service('date');
            

Improve documentation

Supervisor


              FROM ubuntu:latest
              RUN apt-get update && apt-get install -y supervisor
              RUN mkdir -p /var/log/supervisor
              COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
              COPY my_first_process my_first_process
              COPY my_second_process my_second_process
              CMD ["/usr/bin/supervisord"]
            

Enforce best practices

Run it as a community initiative. Which already exists. And it is called drupaldocker.org

Goals:

  • curated list of parent images with best practices in mind
  • outstanding documentation
  • verbose
  • single entrypoint for drupal devs aiming for modern Infrastructure as Code
  • stupid simple
  • owned by community
  • distributed on same licence as Drupal

Structure:

I love the idea, how can I help?

- you, right now

Questions?

Thank you!