drupal vm for drupal 8 dev - midcamp 2017

41
DRUPAL VM A VM for Drupal development, built with Vagrant + Ansible #MidCamp 2017 – Jeff Geerling

Upload: jeff-geerling

Post on 22-Jan-2018

754 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Drupal VM for Drupal 8 Dev - MidCamp 2017

DRUPAL VM

A VM for Drupal development, built with Vagrant + Ansible

#MidCamp 2017 – Jeff Geerling

Page 2: Drupal VM for Drupal 8 Dev - MidCamp 2017

@geerlingguy

• Drupalist

...of genus Acquian

• Writer

• Automator of things

Page 3: Drupal VM for Drupal 8 Dev - MidCamp 2017
Page 4: Drupal VM for Drupal 8 Dev - MidCamp 2017

DRUPAL VM

• Info: www.drupalvm.com

• Docs: docs.drupalvm.com

• Code: GitHub

Page 5: Drupal VM for Drupal 8 Dev - MidCamp 2017

DRUPAL VM

• Quick Start:

1. Install VirtualBox and Vagrant

2. Download Drupal VM

3. vagrant up

Page 6: Drupal VM for Drupal 8 Dev - MidCamp 2017

HOW DO I BUILD AND MAINTAIN DRUPAL 8

PROJECTS?

Page 7: Drupal VM for Drupal 8 Dev - MidCamp 2017

Drush was never designed as a dependency management tool.

Page 8: Drupal VM for Drupal 8 Dev - MidCamp 2017

Page 9: Drupal VM for Drupal 8 Dev - MidCamp 2017

DRUPAL-PROJECT

$ composer create-project drupal-composer/drupal-project:8.x-dev \ bacon \ --stability dev \ --no-interaction

Page 10: Drupal VM for Drupal 8 Dev - MidCamp 2017

DRUPAL VM

composer require --dev geerlingguy/drupal-vm

Page 11: Drupal VM for Drupal 8 Dev - MidCamp 2017

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{

Page 12: Drupal VM for Drupal 8 Dev - MidCamp 2017

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{

Page 13: Drupal VM for Drupal 8 Dev - MidCamp 2017

vagrant up

Page 14: Drupal VM for Drupal 8 Dev - MidCamp 2017

WHAT ABOUT PROD?

Page 15: Drupal VM for Drupal 8 Dev - MidCamp 2017

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{

Page 16: Drupal VM for Drupal 8 Dev - MidCamp 2017

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

Page 17: Drupal VM for Drupal 8 Dev - MidCamp 2017

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

Page 18: Drupal VM for Drupal 8 Dev - MidCamp 2017
Page 19: Drupal VM for Drupal 8 Dev - MidCamp 2017

GOING DEEPER

Page 20: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: SOLR SEARCH

Page 21: Drupal VM for Drupal 8 Dev - MidCamp 2017

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"

Page 22: Drupal VM for Drupal 8 Dev - MidCamp 2017

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

Page 23: Drupal VM for Drupal 8 Dev - MidCamp 2017

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!

Page 24: Drupal VM for Drupal 8 Dev - MidCamp 2017
Page 25: Drupal VM for Drupal 8 Dev - MidCamp 2017

It's alive!!!

Page 26: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

Page 27: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

Page 28: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

• Step 1: Add Selenium to Drupal VM

• Add selenium to installed_extras

Page 29: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

• Step 2: Add Drupal Extension

composer require --dev drupal/drupal-extension

Page 30: Drupal VM for Drupal 8 Dev - MidCamp 2017

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

Page 31: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

• Step 4: Initialize Behat

• Log into VM

• cd into tests

• Run ../vendor/bin/behat init

Page 32: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

• Step 5: Test ALL THE THINGS!

• Create feature files in tests/features/web

• Example: HomeContent.feature

Page 33: Drupal VM for Drupal 8 Dev - MidCamp 2017

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"

Page 34: Drupal VM for Drupal 8 Dev - MidCamp 2017

EXAMPLE: BEHAT TESTS

Page 35: Drupal VM for Drupal 8 Dev - MidCamp 2017

WINDOWS

Page 36: Drupal VM for Drupal 8 Dev - MidCamp 2017

WINDOWS

😭

Page 37: Drupal VM for Drupal 8 Dev - MidCamp 2017

WINDOWS

🤗

Page 38: Drupal VM for Drupal 8 Dev - MidCamp 2017

WINDOWS

• Use SMB, rsync, or reverse-mount shared folders

• Use WSL/Ubuntu Bash and/or Cmder

• Use Unix line endings

• Read the docs

Page 39: Drupal VM for Drupal 8 Dev - MidCamp 2017

• 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!

Page 40: Drupal VM for Drupal 8 Dev - MidCamp 2017

THE FUTURE

• Docker & Libvirt/KVM

• Easier config template customization

• Certbot + LetsEncrypt (TLS FTW)

• MOAR Composer

• MOAR Windows

Page 41: Drupal VM for Drupal 8 Dev - MidCamp 2017

THANKS!

• Review this session: https://joind.in/talk/8f8fa

• Support my work on Patreon: https://www.patreon.com/geerlingguy