From 13e064b71406521c5a6e5c062b6c253ccb56f230 Mon Sep 17 00:00:00 2001
From: Antonio De Marco <antonio@nuvole.org>
Date: Fri, 26 Jan 2018 11:57:16 +0100
Subject: [PATCH] Issue #169: Integrate OpenEuropa Task Runner and add Docker
 Compose integration

---
 .ruby-version          |  1 -
 .travis.yml            | 48 ++++++++++++------------------
 behat.yml.dist         | 10 +++----
 composer.json          |  8 ++---
 docker-compose.yml     | 67 ++++++++++++++++++++++++++++++++++++++++++
 docs/content/tests.rst | 24 +++++++++++++++
 grumphp.yml.dist       |  2 +-
 phpunit.xml.dist       |  3 +-
 runner.yml.dist        | 23 +++++++++++++++
 9 files changed, 142 insertions(+), 44 deletions(-)
 delete mode 100644 .ruby-version
 create mode 100644 docker-compose.yml
 create mode 100644 runner.yml.dist

diff --git a/.ruby-version b/.ruby-version
deleted file mode 100644
index b1b25a5ff..000000000
--- a/.ruby-version
+++ /dev/null
@@ -1 +0,0 @@
-2.2.2
diff --git a/.travis.yml b/.travis.yml
index db2a61445..070b57013 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,14 +1,12 @@
-language: php
-dist: precise
+sudo: required
 
-php:
-  - 7.0
+services:
+  - docker
+  - docker-compose
 
 env:
   global:
-env:
-  global:
-    - PATH=$PATH:/home/travis/.composer/vendor/bin:$TRAVIS_BUILD_DIR/vendor/bin
+    - DOCKER_COMPOSE_VERSION=1.17.1
   matrix:
     - DRUPAL_VERSION=8.3.x-dev
     - DRUPAL_VERSION=8.4.x-dev
@@ -16,34 +14,24 @@ env:
 
 matrix:
   allow_failures:
-    - php: 7.0
-      env: DRUPAL_VERSION=8.5.x-dev
+    - env: DRUPAL_VERSION=8.5.x-dev
+
+before_install:
+  - docker-compose up -d
+  - docker ps
 
 install:
-  - composer self-update
-  - composer require drupal/core:$DRUPAL_VERSION --dev --prefer-dist
+  - docker-compose exec -u root php composer require drupal/core:$DRUPAL_VERSION --dev --prefer-dist
 
 before_script:
-  # Start PhantomJS server.
-  - phantomjs --webdriver=4444 > /dev/null &
-  # Set sendmail so drush doesn't throw an error during site install.
-  - echo "sendmail_path=`which true`" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
-  # Create database.
-  - mysql -e 'create database drupal'
-  # Install Drupal 8 target site.
-  - drush --root=$PWD/build si standard -y --db-url=mysql://travis:@127.0.0.1/drupal
-  # Force exit status to true so expected patterns validation error will not stop Travis build.
-  - drush --root=$PWD/build en ui_patterns_test -y || true
-  - drush --root=$PWD/build cr
-  # Run Drush web server.
-  - drush --root=$PWD/build --debug runserver :8888 > ~/debug.txt 2>&1 &
-  - sleep 4s
+  - docker-compose exec -u root php ./vendor/bin/run drupal:site-setup
+  - docker-compose exec -u root php ./vendor/bin/run drupal:site-install
+  - docker-compose exec -u root php chown -R www-data:www-data build
 
 script:
-  - cd $TRAVIS_BUILD_DIR
-  - phpunit
-  - behat
-  - grumphp run
+  - docker-compose exec -u root php ./vendor/bin/grumphp run
+  - docker-compose exec -u root php ./vendor/bin/phpunit
+  - docker-compose exec -u root php ./vendor/bin/behat
 
 notifications:
-  email: false
+  email: false
\ No newline at end of file
diff --git a/behat.yml.dist b/behat.yml.dist
index d6b84db2c..d207f10df 100644
--- a/behat.yml.dist
+++ b/behat.yml.dist
@@ -19,14 +19,14 @@ default:
   extensions:
     Behat\MinkExtension:
       goutte: ~
-      selenium2: ~
+      selenium2:
+        wd_host: 'http://selenium:4444/wd/hub'
       javascript_session: selenium2
-      base_url: http://127.0.0.1:8888
+      base_url: "${drupal.base_url}"
     NuvoleWeb\Drupal\DrupalExtension:
       api_driver: 'drupal'
       drupal:
-        # Change this to the absolute path to Drupal install.
-        drupal_root: 'build'
+        drupal_root: "${drupal.root}"
       region_map:
         left sidebar: '#sidebar-first'
         content: '#content'
@@ -39,7 +39,5 @@ default:
         error_message_selector: '.alert.alert-danger'
       text:
         node_submit_label: 'Save and publish'
-    Bex\Behat\ScreenshotExtension:
-      active_image_drivers: img42
   formatters:
     progress: ~
diff --git a/composer.json b/composer.json
index efd0269a4..9daf853e6 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
     "drupal/console": "~1",
     "drush/drush": "*",
     "drupal/coder": "8.2.8",
-    "drupal/core": "~8",
+    "drupal/core": "8.4.x-dev",
     "drupal/ds": "~3",
     "drupal/field_group": "~1",
     "drupal/coffee": "~1",
@@ -31,12 +31,10 @@
     "phpunit/phpunit": "5.5.*",
     "nuvoleweb/drupal-behat": "~1.1.0",
     "mikey179/vfsStream": "*",
-    "bex/behat-screenshot": "^1.2",
-    "bex/behat-screenshot-image-driver-img42": "^1.0",
-    "bex/behat-extension-driver-locator": "^1.0",
     "phpro/grumphp": "0.11.4",
     "squizlabs/php_codesniffer": "~2.9",
-    "peridot-php/leo": "^1.6"
+    "peridot-php/leo": "^1.6",
+    "ec-europa/oe-task-runner": "^0.3"
   },
   "repositories": [
     {
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 000000000..fa87d3b0e
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,67 @@
+version: "2"
+
+services:
+  mariadb:
+    image: wodby/mariadb:10.1-2.3.5
+    environment:
+      MYSQL_ROOT_PASSWORD: password
+      MYSQL_DATABASE: drupal
+      MYSQL_USER: drupal
+      MYSQL_PASSWORD: drupal
+
+  php:
+    image: wodby/drupal-php:7.0-3.0.0
+    environment:
+      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
+      PHP_FPM_CLEAR_ENV: "no"
+      DB_HOST: mariadb
+      DB_USER: drupal
+      DB_PASSWORD: drupal
+      DB_NAME: drupal
+      DB_DRIVER: mysql
+      PHP_XDEBUG: 1
+      PHP_XDEBUG_DEFAULT_ENABLE: 1
+      PHP_XDEBUG_REMOTE_CONNECT_BACK: 1
+      PHP_XDEBUG_REMOTE_HOST: "10.254.254.254"
+      PHP_XDEBUG_IDEKEY: "PHPSTORM"
+      PHP_IDE_CONFIG: "serverName=ui_patterns"
+      COMPOSER_HOME: "/composer"
+    volumes:
+      - ./:/var/www/html
+      - ~/.bash_history:/root/.bash_history
+      - ~/.bashrc.aliases:/root/.bashrc
+      - ~/.composer/cache:/composer/cache
+
+  nginx:
+    image: wodby/drupal-nginx:8-1.13-3.0.1
+    depends_on:
+      - php
+    environment:
+      NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"
+      NGINX_ERROR_LOG_LEVEL: debug
+      NGINX_BACKEND_HOST: php
+      NGINX_SERVER_ROOT: /var/www/html/build
+    volumes:
+      - ./:/var/www/html
+    labels:
+      - 'traefik.backend=nginx'
+      - 'traefik.port=80'
+      - 'traefik.frontend.rule=Host:ui_patterns.localhost'
+
+  traefik:
+    image: traefik
+    command: -c /dev/null --web --docker --logLevel=INFO
+    ports:
+      - '80:80'
+    volumes:
+      - /var/run/docker.sock:/var/run/docker.sock
+
+  selenium:
+    image: selenium/standalone-firefox-debug:2.53.1-beryllium
+    ports:
+      - "5900:5900"
+    expose:
+      - '4444'
+
+volumes:
+  codebase:
diff --git a/docs/content/tests.rst b/docs/content/tests.rst
index 2dbf7e209..e0fa9ca46 100644
--- a/docs/content/tests.rst
+++ b/docs/content/tests.rst
@@ -52,3 +52,27 @@ you'll still need to manually disable Twig and other Drupal 8 caching by un-comm
    #   include $app_root . '/' . $site_path . '/settings.local.php';
    # }
 
+Docker Compose
+--------------
+
+UI Patterns ships with a ``docker-compose.yml`` file which can be used to streamline local development and tests execution.
+
+In the project root run:
+
+.. code-block:: bash
+
+   $ docker-compose up -d
+   $ docker-compose exec -u root php composer install
+   $ docker-compose exec -u root php ./vendor/bin/run drupal:site-setup
+   $ docker-compose exec -u root php ./vendor/bin/run drupal:site-install
+   $ docker-compose exec -u root php chown -R www-data:www-data build
+
+You'll then have a fully functional test site at `http://ui_patterns.localhost <http://ui_patterns.localhost>`_.
+
+You can then run all tests as follows:
+
+.. code-block:: bash
+
+   $ docker-compose exec -u root php ./vendor/bin/grumphp run
+   $ docker-compose exec -u root php ./vendor/bin/phpunit
+   $ docker-compose exec -u root php ./vendor/bin/behat
diff --git a/grumphp.yml.dist b/grumphp.yml.dist
index 139be7233..0c5afb381 100644
--- a/grumphp.yml.dist
+++ b/grumphp.yml.dist
@@ -9,7 +9,7 @@ parameters:
         - build/
         - vendor/
         - tests/
-        - ui_patterns/modules/ui_patterns_test/
+        - modules/ui_patterns_test/
       triggered_by:
         - php
         - module
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 1e64194ad..5ca615c51 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -4,7 +4,8 @@
     <ini name="error_reporting" value="32767"/>
     <var name="namespaces" value=""/>
     <ini name="memory_limit" value="-1"/>
-    <env name="SIMPLETEST_DB" value="mysql://travis:@127.0.0.1/drupal"/>
+    <env name="SIMPLETEST_BASE_URL" value="${drupal.base_url}"/>
+    <env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/>
   </php>
   <testsuites>
     <testsuite name="unit">
diff --git a/runner.yml.dist b/runner.yml.dist
new file mode 100644
index 000000000..c9331a267
--- /dev/null
+++ b/runner.yml.dist
@@ -0,0 +1,23 @@
+drupal:
+  root: "build"
+  base_url: "http://nginx"
+  database:
+    host: "mariadb"
+    port: "3306"
+    name: "drupal"
+    user: "drupal"
+    password: "drupal"
+  post_install:
+    - "./vendor/bin/drush en -y ui_patterns_test"
+    - "./vendor/bin/drush cr"
+
+commands:
+  drupal:site-setup:
+    - { task: "run", command: "drupal:drush-setup" }
+    - { task: "run", command: "drupal:settings-setup" }
+    - { task: "run", command: "setup:behat" }
+    - { task: "run", command: "setup:phpunit" }
+  setup:behat:
+    - { task: "process", source: "behat.yml.dist", destination: "behat.yml" }
+  setup:phpunit:
+    - { task: "process", source: "phpunit.xml.dist", destination: "phpunit.xml" }
-- 
GitLab