drupal vm for drupal 8 dev - midcamp 2017
TRANSCRIPT
DRUPAL VM
A VM for Drupal development, built with Vagrant + Ansible
★
#MidCamp 2017 – Jeff Geerling
@geerlingguy
• Drupalist
...of genus Acquian
• Writer
• Automator of things
DRUPAL VM
• Info: www.drupalvm.com
• Docs: docs.drupalvm.com
• Code: GitHub
DRUPAL VM
• Quick Start:
1. Install VirtualBox and Vagrant
2. Download Drupal VM
3. vagrant up
HOW DO I BUILD AND MAINTAIN DRUPAL 8
PROJECTS?
Drush was never designed as a dependency management tool.
❤
DRUPAL-PROJECT
$ composer create-project drupal-composer/drupal-project:8.x-dev \ bacon \ --stability dev \ --no-interaction
DRUPAL VM
composer require --dev geerlingguy/drupal-vm
PREP THE VM---vagrant_hostname: local.bacon.com
drupal_build_composer_project: falsedrupal_build_composer: falsedrupal_composer_dependencies: []
installed_extras: - drush - drupalconsole - mailhog - nodejs - xdebug - varnish
vm/config.yml{
PREP DRUPAL PROJECT
ENV['DRUPALVM_PROJECT_ROOT'] = "#{__dir__}"ENV['DRUPALVM_CONFIG_DIR'] = "vm"ENV['DRUPALVM_DIR'] = "vendor/geerlingguy/drupal-vm"
# Load Drupal VM's Vagrantfileload "#{__dir__}/#{ENV['DRUPALVM_DIR']}/Vagrantfile"
Vagrantfile{
vagrant up
WHAT ABOUT PROD?
WHAT ABOUT PROD?
---# Deploy from the project's Git repository.drupal_deploy: truedrupal_deploy_repo: "[email protected]:my/bacon.git"drupal_deploy_dir: /var/www/drupal
# Set the domain for this site appropriately.drupal_domain: "prod.bacon.com"vagrant_hostname: "{{ drupal_domain }}"
vm/prod.config.yml{
WHAT ABOUT PROD?
$ DRUPALVM_ENV=prod \ ansible-playbook -i vm/inventory \ vendor/geerlingguy/drupal-vm/provisioning/playbook.yml \ -e "config_dir=$(pwd)/vm" \ --become --ask-become-pass \ --ask-vault-pass
WHAT ABOUT PROD?
• Dogfooding: project is on GitHub
• Everybody loves secrets (.yml)
• Full writeup on my blog: https://www.jeffgeerling.com/drupal-vm-local-prod
GOING DEEPER
EXAMPLE: SOLR SEARCH
EXAMPLE: SOLR SEARCH
• Step 1: Add Solr to Drupal VM
• Add solr to installed_extras
• Copy Drupal VM's example configure-solr.sh to scripts/configure-solr.sh
• Add script to vm/config.yml:
post_provision_scripts: - "../../../../scripts/configure-solr.sh"
EXAMPLE: SOLR SEARCH
• Step 2: Add Drupal modules
composer require drupal/search_api:^1.0 drupal/search_api_solr:^1.0
drush @local.example.com en -y search_api search_api_solr search_api_solr_defaults
EXAMPLE: SOLR SEARCH
• Step 3: Export the config and deploy!
• Disable Search API Solr Defaults module
• Export: drush @local.bacon.com cex -y
• Commit and push
• Deploy: Run the playbook on prod!
It's alive!!!
EXAMPLE: BEHAT TESTS
EXAMPLE: BEHAT TESTS
EXAMPLE: BEHAT TESTS
• Step 1: Add Selenium to Drupal VM
• Add selenium to installed_extras
EXAMPLE: BEHAT TESTS
• Step 2: Add Drupal Extension
composer require --dev drupal/drupal-extension
EXAMPLE: BEHAT TESTS
• Step 3: Configure Behat (behat.yml)
• Add tests directory
• Copy the config from Drupal VM's docs
• Paste into new tests/behat.yml
EXAMPLE: BEHAT TESTS
• Step 4: Initialize Behat
• Log into VM
• cd into tests
• Run ../vendor/bin/behat init
EXAMPLE: BEHAT TESTS
• Step 5: Test ALL THE THINGS!
• Create feature files in tests/features/web
• Example: HomeContent.feature
EXAMPLE: BEHAT TESTS
Feature: Test DrupalContext
In order to prove Behat is working correctly in Drupal VM As a developer I need to run a simple interface test
Scenario: Viewing content in a region Given I am on the homepage Then I should see "This is a demonstration" in the "content"
EXAMPLE: BEHAT TESTS
WINDOWS
WINDOWS
😭
WINDOWS
🤗
WINDOWS
• Use SMB, rsync, or reverse-mount shared folders
• Use WSL/Ubuntu Bash and/or Cmder
• Use Unix line endings
• Read the docs
• DRUPALVM_ANSIBLE_TAGS=xdebug vagrant provision
• Tideways is the new XHProf
• Configure ALL THE THINGS in Vagrantfile.local
• Add custom pre/post-provision playbooks
• Test your modules with PAReview.sh
BONUS ROUND!
THE FUTURE
• Docker & Libvirt/KVM
• Easier config template customization
• Certbot + LetsEncrypt (TLS FTW)
• MOAR Composer
• MOAR Windows
THANKS!
• Review this session: https://joind.in/talk/8f8fa
• Support my work on Patreon: https://www.patreon.com/geerlingguy