VAGRANT+PUPPET
= TRUE
Who, Me?
Mikke Schirén
Developer at Wunderkraut Sweden
(former actor, journalist, whatever)
Worked with Drupal since 4.7
d.o: MiSc , Twitter: mikkdroid
advanced
because
it's simple
WE NEED A
CONTROLLED
DEVELOPMENT
ENVIRONMENT
So WHY THE
NEED FOR VAGRANT
AND PUPPET?
MOST COMMON DRUPAL
DEVELOPMENT ENVIRONMENT
(I'm guessing here...)
MOST COMMON DRUPAL
PRODUCTION
ENVIRONMENT
(That we know for a fact)
AND THAT'S NO PROBLEM,
OR?
DEVELOPMENT ENVIRONMENT SHOULD BE LIKE PRODUCTION
AND IT SHOULD
BE EASY TO SETUP
NODEONE STORY
What we had before
One Virtual machine that should fit
all projects and developers,
the Virtualnode.
NODEONE STORY
Problem
Developers fixing their VMs so it fitted them
(updated php version, mysql, special vhost entries etc.),
OR
(For a while we even had an internal project - "Problem with local enviroment")
SOLUTION
Easy to set-up local environment
- Vagrant
- Plus provisioner(s)
VAGRANT
Vagrant is free and open-source software for creating and configuring virtual development environments. (Wikipedia)
Supports Virtualbox, VMWare, Amazon EC2 etc.
Written in Ruby.
AND A PROVISIONER
Puppet, CHEF, ANSIBLE, SALT, DOCKER?
PUPPET
- We are using on production servers to control them
- We had better knowledge in Puppet than Chef
- We could reuse what we are using for production
VAGRANTFILE
Vagrant.configure("2") do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
config.vm.synced_folder '.', '/vagrant', :id => 'vagrant-root', :disabled => true
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
VAGRANTFILE
# Assign this VM to a host only network IP, allowing you to access it
# via the IP.
config.vm.network :private_network, ip: "192.168.50.91"
config.vm.hostname = "marvin.dev.com"
config.vm.provider "virtualbox" do |v|
v.name = config.vm.hostname
v.customize ["modifyvm", :id, "--memory", "2048"]
v.customize ["modifyvm", :id, "--cpus", "1"]
end
VAGRANTFILE
# Provisioning settings.
config.vm.provision :puppet do |puppet|
puppet.facter = {
'drupal_root' => '/srv/www/marvin/web'
}
puppet.manifests_path = "./"
puppet.manifest_file = "manifests/manifest.pp"
puppet.module_path = "./manifests/modules"
end
# The path to the platform
config.vm.synced_folder "./", "/srv/www/marvin", :nfs => true
end
VAGRANTFILE - PROVISION SCRIPT
Some extra provision could be done with shell scriptingconfig.vm.provision :shell do |shell|
shell.inline = "drush dl drush-7.x-5.9 -y"
end
inside the virtualmachine.
VAGRANTFILE - PROVISION SCRIPT
config.vm.provision :shell do |shell|
shell.path = "script.sh"
end
[script.sh]
#!/bin/bash
if [ ! -d foo ]; then
mkdir foo
fi
VAGRANTFILE - PROVISION SCRIPT
And whatever you could do with a script, like:
Create database
Add ssh-keys
Download databasedumps
- Etc.
But better to use...
PUPPET manifest
class { 'systools': }
class { 'apache':
port => 8081
}
class { 'php':
development => true
}
class { 'drush': }
class { 'varnish': }
class { 'phpmyadmin': }
class { 'postfix': }
class { 'memcached':
max_memory => '30%',
}
MANIFEST.PP
class { 'mysql':
local_only => true,
hostname => $fqdn
}
apache::vhost { "drupal":
document_root => $drupal_root
}
AND THE PUPPET MODULES
Like
apache drush jetty memcached mysql php phpmyadmin postfix solr systools varnish
And whatever you need to have.
EXAMPLE - PHP MODULE
class php (
$packages = [
'php5',
'php5-cli',
'php5-common',
'php5-mysql',
'php5-gd',
'php5-curl',
'php5-dev',
'php5-mcrypt',
'php-pear',
'php5-sqlite',
'build-essential',
'php5-ldap',
'libapache2-mod-php5',
'php5-memcache',
],
And DEV SETTINGS
; Development flags.
error_reporting = E_ALL | E_STRICT
display_errors = On
display_startup_errors = On
html_errors = 1
memory_limit = 256M
max_execution_time = 0
zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=192.168.50.91
xdebug.remote_port=9000
xdebug.profiler_enable_trigger=1
AND MORE
- Development environment in repository (but not the virtualbox itself)
- Version controlled
- No more local development
-
No more Homebrew, XAMP, WAMP. etc.
NO MORE
"It worked in my environment!"
(Or not so much of it)
Tools and links
Geppetto to edit Puppetfiles
AND....
We are hiring
Wunderkraut Sweden is looking for senior Drupal developers, working in Sweden or remote.
Mail: mikke.schiren@wunderkraut.com
VAGRANT+PUPPET
By Mikke Schirén
VAGRANT+PUPPET
- 4,658