diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e161517 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +vagrant/* +.vagrant +.ey_local_data +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 6f47973..b2b61ae 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # vagrantwrapper A directory structure to support reuse of the vagrantpress vagrant setup + +This is how the directory structure should be used: +dev +--> plugins + Should contain any plugins that are required during development. +--> puppet + The puppet scripts for providing any custom puppet commands on top of vagrantpress. +--> scripts + Any scripts to run on the host. +--> theme + Your theme which your are developing which should be cloned into a subtree. \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..6bcf09d --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,41 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + config.vm.box = "trusty64" + config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" + + # allows running commands globally in shell for installed composer libraries + config.vm.provision :shell, path: "vagrant/files/scripts/setup.sh" + + # setup virtual hostname and provision local IP + config.vm.hostname = "vagrantpress.dev" + config.vm.network :private_network, :ip => "192.168.50.4" + config.hostsupdater.aliases = %w{www.vagrantpress.dev} + config.hostsupdater.remove_on_suspend = true + + config.vm.provision :puppet do |puppet| + puppet.manifests_path = "vagrant/puppet/manifests" + puppet.module_path = "vagrant/puppet/modules" + puppet.manifest_file = "setup.pp" + end + + config.vm.provision :puppet do |puppet| + puppet.manifests_path = "vagrant/puppet/manifests" + puppet.module_path = "vagrant/puppet/modules" + puppet.manifest_file = "init.pp" + puppet.options="--verbose --debug" + end + + config.vm.provision :puppet do |puppet| + puppet.manifests_path = "dev/puppet/manifests" + puppet.module_path = "dev/puppet/modules" + puppet.manifest_file = "init.pp" + end + + # Fix for slow external network connections + config.vm.provider :virtualbox do |vb| + vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] + vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] + end +end diff --git a/dev/puppet/manifests/init.pp b/dev/puppet/manifests/init.pp new file mode 100644 index 0000000..5b554e7 --- /dev/null +++ b/dev/puppet/manifests/init.pp @@ -0,0 +1 @@ +class { 'custom::install': } \ No newline at end of file diff --git a/dev/puppet/modules/custom/files/save-db-changes.sh b/dev/puppet/modules/custom/files/save-db-changes.sh new file mode 100644 index 0000000..837a70b --- /dev/null +++ b/dev/puppet/modules/custom/files/save-db-changes.sh @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/mysqldump -u wordpress -pwordpress wordpress > /working/puppet/modules/custom/files/wordpress-backup.sql \ No newline at end of file diff --git a/dev/puppet/modules/custom/manifests/init.pp b/dev/puppet/modules/custom/manifests/init.pp new file mode 100644 index 0000000..3074853 --- /dev/null +++ b/dev/puppet/modules/custom/manifests/init.pp @@ -0,0 +1,46 @@ +class custom::install { + + exec { 'wordpress_exists': + command => '/bin/true', + onlyif => '/usr/bin/test -e /vagrant/wordpress/wp-content/themes', + } + + # Create a symlink of theme folder + file { '/vagrant/wordpress/wp-content/themes/test/': + ensure => 'link', + target => '/working/theme', + require => Exec['wordpress_exists'], + } + + # Create a symlink of plugins folder + file { '/vagrant/wordpress/wp-content/plugins/': + ensure => 'link', + target => '/working/plugins', + force => true, + require => Exec['wordpress_exists'], + } + + # Create a symlink of uploads folder + file { '/vagrant/wordpress/wp-content/uploads/': + ensure => 'link', + target => '/working/puppet/modules/custom/files/uploads', + force => true, + require => Exec['wordpress_exists'], + } + + exec { 'npm install': + command => '/usr/bin/npm install', + cwd => '/working/theme/', + require => File['/vagrant/wordpress/wp-content/themes/test/'], + } + + #file { '/tmp/wordpress-backup.sql': + # source => 'puppet:///modules/custom/wordpress-backup.sql' + #} + + #exec { 'load-db': + # command => '/usr/bin/mysql -u wordpress -pwordpress wordpress < /tmp/wordpress-backup.sql && touch /home/vagrant/db-updated', + # creates => '/home/vagrant/db-updated', + # require => File['/tmp/wordpress-backup.sql'], + #} +} \ No newline at end of file diff --git a/dev/scripts/save-db-host.sh b/dev/scripts/save-db-host.sh new file mode 100644 index 0000000..656c66a --- /dev/null +++ b/dev/scripts/save-db-host.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +vagrant ssh -c "/working/puppet/modules/custom/files/save-db-changes.sh"