Setting Up A Drupal 8 Container on CircleCI with CircleCI 2.0 Syntax

August 19, 2017

Submitted by twfahey on Fri, 08/18/2017 - 21:15

I recently went through a learning process I want to share, since I found it somewhat difficult to find the pieces to make this work. That is, having CircleCI 2.0 style testing run on a Drupal 8 installation. For the environment setup, I wanted to use PHP 7.1, and MySQL 5.7. I also knew that I wanted to get drush working, and therefore would need composer, and I wanted to be able to leverage drush as I started this initial test environment. For this first run, I also wanted to execute a PHPUnit test 'FilterQualtricsTest' from our custom utexas_qualtrics_filter module. Here's how I wound up getting it setup.

NOTE: We are using a /web folder for our docroot, and composer with some defined composer-types that install into our web/ directory. If you aren't using this kind of structure, you should modify the code accordingly.

In the root of the project, have a .circleci folder with the following file structure: 


Here's the code for these files. You may not necessarily need ALL the commands I'm using, and as I mentioned above, you may need to tweak the /web path depending on your Drupal site configuration. But it should serve as a great starting point for lots of different setups.


version: 2
    working_directory: ~/site_build
      - image: circleci/php:7.1-apache-node
          - MYSQL_HOST=
      - image: mysql:5.7
          - MYSQL_USER=root
          - MYSQL_ROOT_PASSWORD=ubuntu
          - MYSQL_PASSWORD=
          - MYSQL_DATABASE=circle_test
          - MYSQL_ROOT_HOST=%
      - image: selenium/standalone-chrome:3.1.0
      - run:
          name: Install PHP extensions
          command: sudo docker-php-ext-install pdo_mysql
      - run:
          name: Install extension
          command: sudo apt-get install -y libpng-dev
      - run:
          name: Install PHP Extensions
          command: sudo docker-php-ext-install gd
      - run:
          name: Install Composer
          command: 'curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer'
      - run:
          name: Display versions
          command: |
            php -v
            composer --version
      - run:
          name: Install mysql-client
          command: |
            sudo apt-get install mysql-client
      - checkout
      - run: php -v
      - run: sudo cp .circleci/tests/circle/circle.conf /etc/apache2/sites-available
      - run: sudo a2ensite circle.conf
      - run: sudo a2enmod rewrite
      - run: composer global require drush/drush:8.*
      - run: sudo service apache2 restart
      # Set up Drupal
      - run: bash
      - run: echo 'export PATH=~/.composer/vendor/bin:$PATH' >> $BASH_ENV
      - run: cp .circleci/tests/circle/settings.php web/sites/default/settings.local.php
      - run: ls web/sites/default
      # Add alias to drush configuration.
      - run: mkdir ~/.drush
      - run: echo '<?php' > ~/.drush/test.aliases.drushrc.php
      - run: drush status
      - run: pwd
      - run: drush site-alias @self --root=/home/circleci/site_build/web --full --with-optional
      - run: drush site-alias @self --root=/home/circleci/site_build/web --full --with-optional >> ~/.drush/test.aliases.drushrc.php
      - run: drush status --root=/home/circleci/site_build/web
      # Install Drupal.
      - run:
          name: Install site
          # We add 'install_configure_form.enable_update_status_module=NULL" to disable email being sent.
          command: drush @test si standard install_configure_form.enable_update_status_module=NULL -y
      - run:
          name: Run tests
          command: cd web/core; ../../vendor/bin/phpunit ../modules/custom/utexas_qualtrics_filter/tests/src/Unit/FilterQualtricsTest.php




 * @file
 * CircleCI generic database connection details.
 * Values could be placed in the environment variables, but these are
 * general-knowledge credentials.

$databases['default']['default'] = array(
  'driver' => 'mysql',
  'database' => 'circle_test',
  'username' => 'root',
  'password' => 'ubuntu',
  'host' => '',
  'port' => 3306,
  'prefix' => '',

$settings['theme_debug'] = TRUE;
$settings['hash_salt'] = '[email protected]#!~askdo';
$settings['container_yamls'][] = '';
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;


Listen 8080

<VirtualHost *:8080>

  UseCanonicalName Off
  DocumentRoot home/circleci/site_build/web

  <Directory "home/circleci/site_build/web">
    Options FollowSymLinks
    AllowOverride All
    Require all granted


Now when CircleCI tests your site, you should see all the steps execute, and get that nice, satisfying: