Developing directly on live sites or in subfolders of live sites • Developing in subfolders locally • Setting up local development environments that are so different to the eventual live server that there is no confidence when going live • Working in teams where everyone has a slightly different setup
take a look at • A really simple way to get started with Vagrant and Puppet for those of you who haven’t used these tools before. • Vagrant and Puppet fundamentals, how to start writing your own manifests. • How you can take this knowledge into production, even if you manage just one or two servers.
to develop multiple websites on our own computer. • to know that our live server and local server support the same things. • to deploy our site and have confidence that what is on the live server is identical to our local version. • to have everyone who works on a site using the same development environment so we aren’t creating problems for each other.
your live server • PHP Version • Installed modules such as gd for image processing • post_max_size and upload_max_filesize determine the size of files that can be uploaded • max_input_vars is the number of form fields allowed in a post
tell Vagrant we will be provisioning with Puppet. # Enable the Puppet provisioner, point it to our files config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "site.pp" puppet.module_path = "puppet/modules" puppet.hiera_config_path = "puppet/hiera.yaml" end
A Configuration Management solution • Allows you to define in code the state of a server including • Packages that should be installed • Services that should be running • Files and folders • Permissions • Cron jobs
a VM and then install everything by hand using the package manager for your distribution. > sudo apt-get install apache2 > sudo apt-get install mysql-server > sudo apt-get install php5 php5-mysql
a file that contains Puppet code • Resource: a thing that needs configuring, Apache is a resource, and so is a virtual-host. Resources have types - for example file, package, cron. • Module: a collection of manifests, templates and other files organised around a particular purpose.
init.pp manifest. It is used when the module is included. In the apache init.pp - install the apache package - make sure apache is running - install the rewrite module class apache { package { "apache2": ensure => present, } service { "apache2": ensure => running, require => Package["apache2"], } file { "/etc/apache2/mods-enabled/rewrite.load": ensure => link, target => "/etc/apache2/mods-available/rewrite.load", require => Package["apache2"] } }
sets up a VirtualHost by creating a file in sites- available and symlinking it into sites-enabled. We notify the apache2 service, which will then reload to pick up the new config. define apache::vhost( $vhost_docroot = false, $vhost_name = false, $vhost_options =['Indexes','FollowSymLinks','MultiViews'], ) { file {"/etc/apache2/sites-available/${vhost_name}": content => template("apache/vhost-default.conf.erb"), owner => 'root', group => 'root', mode => '755', require => Package['apache2'], notify => Service['apache2']; "/etc/apache2/sites-enabled/${vhost_name}": ensure => link, target => "/etc/apache2/sites-available/${vhost_name}", notify => Service['apache2']; } }
a VirtualHost includes variables which will be replaced out by the details for each host. # ************************************ # Default template for vhosts # Managed by Puppet # ************************************ <VirtualHost *:80> ServerName <%= @vhost_name %> DocumentRoot <%= @vhost_docroot %> <Directory <%= @vhost_docroot %>> Options <%= @vhost_options %> AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/<%= @vhost_name %>_error.log LogLevel warn CustomLog /var/log/apache2/<%= @vhost_name %>_access.log combined ServerSignature Off </VirtualHost>
tell Vagrant we will be provisioning with Puppet. # Enable the Puppet provisioner, point it to our files config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "site.pp" puppet.module_path = "puppet/modules" puppet.hiera_config_path = "puppet/hiera.yaml" end
special and kicks off the whole process. In my case it includes the modules we want to run. stage { 'setup': before => Stage['main'] } class { 'base': stage => 'setup' } include base, apache, mysql, php, bootstrap
tell Vagrant we will be provisioning with Puppet. # Enable the Puppet provisioner, point it to our files config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "site.pp" puppet.module_path = "puppet/modules" puppet.hiera_config_path = "puppet/hiera.yaml" end
defines a YAML backend and gives the location of the configuration data. In my project that is in the manifest directory, in a folder named hiera. --- :backends: yaml :yaml: :datadir: "%{settings::manifestdir}/ hiera" :hierarchy: - "%{::clientcert}" - "%{::environment}" - config :logger: console
I have a list of PHP Modules. File: manifests/hiera/config.yaml php_modules: - "php5" - "php5-cli" - "php5-mysql" - "php5-gd" - "php5-imagick" - "php5-curl" - "libapache2-mod-php5"
a VirtualHost includes variables which will be replaced out by the details for each host. # ************************************ # Default template for vhosts # Managed by Puppet # ************************************ <VirtualHost *:80> ServerName <%= @vhost_name %> DocumentRoot <%= @vhost_docroot %> <Directory <%= @vhost_docroot %>> Options <%= @vhost_options %> AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/<%= @vhost_name %>_error.log LogLevel warn CustomLog /var/log/apache2/<%= @vhost_name %>_access.log combined ServerSignature Off </VirtualHost>
to get my site information and pass it to create_resources. The create_resources function then calls my host manifest with that hash as the data. class bootstrap { # Make sure everything is installed $sites = hiera_hash('apache_vhosts') create_resources('apache::vhost',$sites) $databases = hiera_hash('mysql_db') create_resources('mysql::db',$databases) }
latest files and database dump from Github • Deploy the three sites with the current Perch version and add-ons • Run the upgrade and change any templates as needed • Produce the db dump with placeholders for Github and a Ruby db template with placeholders for the demo server • Produce zipped archives for use by the demo server
one of our three demos. It includes the Git repo, local path, database details and Perch license key. I also detail the Perch Add-ons that need to be installed along with Perch Core. demo2: repo_uri: 'https://github.com/PerchCMS/ perchdemo-swift' vhost_path: '/var/www/perchdemos/demo-swift' db_name: 'db_demo_swift' db_user: 'vagrant' db_password: 'vagrant' key: ‘xxxx-xxxx-xxxx-xxxx‘ sql_path: '/sql/swift_demo.sql' install_addons: demo2_blog: addon_name: 'perch_blog' addon_type: 'apps' demo2_forms: addon_name: 'perch_forms' addon_type: 'apps' demo2_questions: addon_name: 'perch_questions' addon_type: 'apps'
and sites but also set off a build of the demos. class bootstrap { $databases = hiera_hash('mysql_db') create_resources(‘mysql::db',$databases) $demos = hiera_hash('demo_deploy') create_resources(‘perchdemo::deploy',$demos) $sites = hiera_hash('apache_vhosts') create_resources('apache::vhost',$sites) }
Core and add-ons are in a local file store. I use a Ruby .erb template for the Perch Config so I can add the database details and license key. I use create_resources to add the add-ons specified in the YAML for this site. file { "${vhost_path}/public_html/perch/core": ensure => present, source => "${file_store}/core", recurse => true, } file { "${vhost_path}/public_html/perch/config/ config.private.php": ensure => present, content => template('perchdemo/config.private.php.erb'), } create_resources('perchdemo::copy_addons',$install_addons, {'vhost_path'=>$vhost_path,'file_store'=>$file_store})
you can run puppet apply to run a manifest. In this case I am running builder.pp which builds me an archive to upload for each site. > puppet apply --modulepath=/vagrant/ puppet/modules --hiera_config /vagrant/ puppet/hiera.yaml -e "include perchdemo::builder"