Skip to content

Instantly share code, notes, and snippets.

@rachellawson
Created July 7, 2017 21:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rachellawson/75dcb9d1c6cf706b6d9909740def7668 to your computer and use it in GitHub Desktop.
Save rachellawson/75dcb9d1c6cf706b6d9909740def7668 to your computer and use it in GitHub Desktop.
CircleCI for Drupal 8 and Behat
version: 2
jobs:
build:
docker:
- image: circleci/php:7.1-apache-browsers
working_directory: ~/working
steps:
- checkout
- run:
name: Add PHP module prerequisites
command: |
sudo apt-get update -y
sudo apt-get install -y libpng-dev
sudo docker-php-ext-install gd
- run:
name: Start Xvfb
command: |
sudo Xvfb :7055
export DISPLAY=:7055
background: true
- run:
name: Start Selenium
command: |
sudo apt-get install -y default-jre
wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar -O selenium-server.jar
java -jar selenium-server.jar
background: true
- run:
name: PhantomJS install
command: |
sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
- run:
name: Configure & Start Apache
command: |
sudo cp ~/working/.circleci/sia.conf /etc/apache2/sites-available/sia.conf
sudo a2ensite sia
sudo service apache2 start
- run:
name: Install composer and then project
command: |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer invalid'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar self-update
php composer.phar install -n --prefer-dist
- run:
name: Site Install
command: |
cd ~/working/web
../vendor/bin/drush site-install config_installer --yes --db-url=sqlite://sites/default/files/.circleci.sqlite config_installer_sync _configure_form.sync_directory=../config/sync
sudo chmod go+w ~/working/web/sites/default/files/.circleci.sqlite
- run:
name: Test
command: |
cd ~/working/tests
mkdir ~/working/test-reports
mkdir ~/working/test-reports/cucumber
./behat --no-snippets -f pretty -o std -f junit -o ~/working/test-reports/cucumber/junit.xml
- store_artifacts:
path: web/sites/default/files/screenshots
prefix: screenshots
- store_test_results:
path: test-reports
<VirtualHost *:80>
DocumentRoot "/home/circleci/working/web"
ServerName sia.dev
<Directory /home/circleci/working/web >
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
@ohthehugemanatee
Copy link

Hi Rachel - thanks for this! Saved me a lot of time tonight. :)

A couple of notes:

  • Drupal will fail to do config-import with this setup, because the image is missing the sqlite3 client. Easy to fix by adding apt install -y sqlite3 anywhere before that step.
  • This doesn't do any caching. You very likely want to restore cache right before "composer install", with
     - restore_cache:
                key: deps1-{{ .Branch }}-{{ checksum "working/composer.lock" }}

And save it right after composer install, with:

     - save_cache:
          key: deps1-{{ .Branch }}-{{ checksum "~/working/composer.lock" }}
          paths:
            - "~/working/vendor"
            - "~/working/web/core"
            - "~/working/web/modules/contrib"
            - "~/working/web/profiles/contrib"
            - "~/working/web/themes/contrib"
            - "~/working/drush/contrib"
            - "~/working/libraries"
            - "~/.composer"

You could probably even get clever and cache an sqlite database of a fresh "minimal" install, and use drush cim instead of si.

Anyway thank you!

@leymannx
Copy link

leymannx commented Feb 12, 2018

Since around beginning of Feb 2018 you have to update /etc/hosts manually to have Behat resolve the URL:

      - run:
          name: Update host file
          command: |
            echo 127.0.0.1 example.localhost | sudo tee -a /etc/hosts
            cat /etc/hosts

Otherwise you'll get cURL error 6: Could not resolve host: example.localhost.
Source: https://discuss.circleci.com/t/apache-conf-could-not-resolve-host/19994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment