From 4e91de2a4e56ec5491fd3e412175756922cd36c5 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 11 Oct 2015 19:37:24 +0200 Subject: [PATCH] implemented new developer environment for the symfony-cmf - vagrant with an ubuntu trusty - stack with customizable parameters (hostname/ip/php version) - support for the jackrabbit and doctrine-dbal implementations of jackalope --- .gitignore | 6 + README.md | 84 +++++++++++- Vagrantfile | 82 ++++++++++++ jack | 2 +- vagrant/README.md | 29 ---- vagrant/Vagrantfile | 41 ------ vagrant/composer.sh | 35 +++++ vagrant/cookbook/recipes/default.rb | 125 ------------------ .../cookbook/templates/default/jackrabbit.erb | 89 ------------- .../cookbook/templates/default/vhost.conf.erb | 13 -- vagrant/hiera.yaml | 17 +++ vagrant/hieradata/common.yaml | 35 +++++ vagrant/hieradata/puppet.yaml | 7 + vagrant/machine.yaml | 8 ++ vagrant/manifests/site.pp | 1 + vagrant/puppet.sh | 18 +++ .../cmf/manifests/application/parameters.pp | 37 ++++++ .../puppet/cmf/manifests/application/php.pp | 55 ++++++++ .../cmf/manifests/application/symfony.pp | 24 ++++ .../cmf/manifests/infrastructure/packages.pp | 9 ++ .../cmf/manifests/infrastructure/phpcr.pp | 45 +++++++ .../infrastructure/phpcr/jack_wrapper.pp | 18 +++ .../infrastructure/phpcr/mysql_wrapper.pp | 32 +++++ vagrant/puppet/cmf/templates/cmf_vhost.erb | 24 ++++ vagrant/puppet/cmf/templates/parameters.erb | 28 ++++ web/app_dev.php | 2 +- 26 files changed, 565 insertions(+), 301 deletions(-) create mode 100644 Vagrantfile delete mode 100644 vagrant/README.md delete mode 100644 vagrant/Vagrantfile create mode 100644 vagrant/composer.sh delete mode 100644 vagrant/cookbook/recipes/default.rb delete mode 100644 vagrant/cookbook/templates/default/jackrabbit.erb delete mode 100644 vagrant/cookbook/templates/default/vhost.conf.erb create mode 100644 vagrant/hiera.yaml create mode 100644 vagrant/hieradata/common.yaml create mode 100644 vagrant/hieradata/puppet.yaml create mode 100644 vagrant/machine.yaml create mode 100644 vagrant/manifests/site.pp create mode 100644 vagrant/puppet.sh create mode 100644 vagrant/puppet/cmf/manifests/application/parameters.pp create mode 100644 vagrant/puppet/cmf/manifests/application/php.pp create mode 100644 vagrant/puppet/cmf/manifests/application/symfony.pp create mode 100644 vagrant/puppet/cmf/manifests/infrastructure/packages.pp create mode 100644 vagrant/puppet/cmf/manifests/infrastructure/phpcr.pp create mode 100644 vagrant/puppet/cmf/manifests/infrastructure/phpcr/jack_wrapper.pp create mode 100644 vagrant/puppet/cmf/manifests/infrastructure/phpcr/mysql_wrapper.pp create mode 100644 vagrant/puppet/cmf/templates/cmf_vhost.erb create mode 100644 vagrant/puppet/cmf/templates/parameters.erb diff --git a/.gitignore b/.gitignore index 0c44de91..20ccdeff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +# CMF composer.phar app/cache/* app/logs/* @@ -18,3 +19,8 @@ jackrabbit/ jackrabbit-standalone-*.jar vagrant/.vagrant bin/ + +# Vagrant Environment +vagrant/hieradata/local.yaml +.vagrant/ +vagrant/local_machine.yaml diff --git a/README.md b/README.md index d5d8d0af..c3504149 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Symfony Content Management Framework Sandbox -[![Build Status](https://secure.travis-ci.org/symfony-cmf/cmf-sandbox.png?branch=master)](http://travis-ci.org/symfony-cmf/cmf-sandbox) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/01a6d3b6-a2b4-4a0a-b3cd-2b46a62d6ed9/mini.png)](https://insight.sensiolabs.com/projects/01a6d3b6-a2b4-4a0a-b3cd-2b46a62d6ed9) +[![Build Status](https://secure.travis-ci.org/symfony-cmf/cmf-sandbox.png?branch=master)](http://travis-ci.org/symfony-cmf/cmf-sandbox) +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/01a6d3b6-a2b4-4a0a-b3cd-2b46a62d6ed9/mini.png)](https://insight.sensiolabs.com/projects/01a6d3b6-a2b4-4a0a-b3cd-2b46a62d6ed9) [![Dependency Status](https://www.versioneye.com/php/symfony-cmf:sandbox/badge.svg)](https://www.versioneye.com/php/symfony-cmf:sandbox) This sandbox is a testing ground for the cmf bundles being developed. @@ -23,6 +24,85 @@ You can run the sandbox on your system, or in a virtualbox VM using Vagrant. For * phpunit 3.6+ (optional) * composer +## Setup with vagrant + +In order to have a simple VM with a database configuration for Jackalope, you simply need to run **vagrant up**. + +### Advanced usage + +#### Enhanced machine configuration + +When having multiple cmf databases, you'll have conflicts with the IP address and the VM name. +These parameters are changeable. You simply need to uncomment the values in the *vagrant/machine.yaml*: + +This table contains all parameters and their default values: + +| Parameter | Description | Default Value | +| --------- | ---------------------------------------------------- | -------------- | +| ip | IP of the VM inside the private network | 192.168.66.211 | +| cpus | The amount of available cpus for the virtual machine | 1 | +| memory | Maximum memory of the virtual machine | 1024 | +| name | Name of the virtual machine | Symfony-CMF VM | +| hostname | Hostname of the virtual machine | symfony-cmf | + +Unless these parameters are present, the given default value will be used. + +You can add a file named *local_machine.yaml* inside the *vagrant/* directory that is able to override these parameters. +This can be useful if any project member needs another ip as the default ip is reserved by another vm. + +__Note:__ you __must__ edit the *web/app_dev.php* file since there's a white list with IPs that are allowed to access the dev environment. + +#### Puppet configuration + +The configuration is done with [Hiera](http://docs.puppetlabs.com/hiera/1/): +We have several configuration files inside the *vagrant/hieradata* directory. + +Configuration files: + - puppet.yaml: This file contains all classes that needs to be included and the environment + - common.yaml: Contains all default values + - local.yaml: This file is ignored by git and can be used in order to adjust custom parameters + +##### Use jackrabbit + +By default the Doctrine implementation of Jackalope is used. When using the jackrabbit implementation, you just need to do the following things: + +- set the value *cmf::infrastructure::phpcr::mysql* to false +- set the value *cmf::infrastructure::phpcr::jack* to true +- uncomment the value *jackrabbit::versin* +- comment all values prefixed with *cmf::infrastructure::phpcr::mysql_wrapper::* +- run *vagrant provision* (or *vagrant up* if the machine isn't created yet) + +Then the jackrabbit-standalone-2.6.0.jar will be downloaded automatically and will be started in the background. + +__NOTE__: Please don't change the *jackrabbit::version* parameter unless you've changed the version inside the __jack__ shell script or you'll run into unexpected conflicts! + +##### Change the php version + +The parameter *cmf::application::php::version* needs to be changed in order to change the version. +The following values are allowed: + +- 5.5 +- 5.6 + +##### Add required packages + +The parameter *cmf::infrastructure::packages::installs* contains a list of all packages that will be installed inside the vm. + +You simple need to add more package names (or created a new list in the *local.yaml* that will be merged with the values of the *common.yaml*) + +##### Changing vhost name + +When having multiple projects using the CMF, we need multiple vhost names: + +The parameter *cmf::application::symfony::vhost_name* in the file *vagrant/hieradata/common.yaml* needs to be changed in order to change the vhost name. + +##### Accessing the page in the browser + +In order to edit the */etc/hosts* file which is mandatory in order to access the page using the actual server name (e.g. *cmf.dev*), +the usage of the [Vagrant Hostmanager Plugin](https://github.com/smdahlen/vagrant-hostmanager) is highly recommended. + +Otherwise it is possible to access the page using the ip (e.g. 192.166.68.211) + ## Initial setup and configuration git clone git://github.com/symfony-cmf/cmf-sandbox.git @@ -59,7 +139,7 @@ at the ``app/config/parameters.yml`` and adjust as needed. ### Install the Doctrine DBAL provider (optional) -Instead of `phpcr_jackrabbit.yml.dist`, use the `phpcr_doctrine_dbal*.yml.dist` +Instead of `phpcr_jackrabbit.yml.dist`, use the `phpcr_doctrine_dbal.yml.dist` files and create the database accordingly. If you have the PHP sqlite extension available, this is the simplest to quickly try out the CMF. Copy the file and then install the dependencies: diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..5b03308b --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,82 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +require 'yaml' + +Vagrant.configure(2) do |cmf| + config = get_validated_vm_config + + # Basic box settings + cmf.vm.box = "ubuntu/trusty64" + cmf.vm.hostname = config['hostname'] + + cmf.vm.synced_folder ".", "/var/www/cmf", :nfs => true + + # Custom virtualbox settings + cmf.vm.provider "virtualbox" do |vb| + # vb settings + vb.name = config['name'] + + # vb customizations + vb.customize ['modifyvm', :id, '--cpus', config['cpus']] + vb.customize ['modifyvm', :id, '--memory', config['memory']] + vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] + end + + # Private network + cmf.vm.network :private_network, :ip => config['ip'] + + # Provisioners: + # 1.: installs all mandatory puppet modules + # 2.: setup of the machine (php, apache vhost, mysql/jackrabbit, parameter files) + # 3.: setup of the application (phpcr setup using app/console commands) + cmf.vm.provision :shell, path: "vagrant/puppet.sh" + cmf.vm.provision :puppet do |puppet| + puppet.manifests_path = "vagrant/manifests" + puppet.module_path = ['vagrant/puppet'] + puppet.manifest_file = 'site.pp' + puppet.options = ["--verbose"] + puppet.hiera_config_path = 'vagrant/hiera.yaml' + end + + cmf.vm.provision :shell, path: "vagrant/composer.sh" +end + +def get_validated_vm_config() + filename = 'vagrant/machine.yaml' + + unless File.exists?(filename) + abort "File #{filename} does not exist!" + end + + config = YAML::load(File.open(filename)) + unless config + config = {} + end + + if File.exists?('vagrant/local_machine.yaml') + config = config.merge(YAML::load(File.open('vagrant/local_machine.yaml'))) + end + + if config['ip'].nil? + abort "The configuration parameter 'ip' is necessary!" + end + + if config['cpus'].nil? + config['cpus'] = 1 + end + + if config['memory'].nil? + config['memory'] = 1024 + end + + if config['name'].nil? + config['name'] = 'Symfony-CMF VM' + end + + if config['hostname'].nil? + config['hostname'] = 'symfony-cmf' + end + + return config +end diff --git a/jack b/jack index f2c67636..5ac3cbac 100755 --- a/jack +++ b/jack @@ -2,7 +2,7 @@ cd $(dirname $0) -VERSION=2.6.0 +VERSION=2.6.5 JAR=jackrabbit-standalone-$VERSION.jar # one per line diff --git a/vagrant/README.md b/vagrant/README.md deleted file mode 100644 index 0b0e7008..00000000 --- a/vagrant/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Getting started using Vagrant - -## You will need: - * Git 1.6+ - * NFS (MacOS works OOB, on Debian based linux distributions install nfs-kernel-server package) - * [Vagrant](http://vagrantup.com) - -## Get the code - - git clone git://github.com/symfony-cmf/cmf-sandbox.git - cd cmf-sandbox/vagrant - vagrant up - -Now everything is getting prepared. -In the meantime you can optionally add an entry to your `/etc/hosts` file like so: - - 172.22.22.22 cmf.lo - -## Access by web browser - -If you have added the entry to `/etc/hosts` you should be able to access the Sandbox like this: - - - -Otherwise you can also use the IP address: - - - - diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile deleted file mode 100644 index 995743a0..00000000 --- a/vagrant/Vagrantfile +++ /dev/null @@ -1,41 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant::Config.run do |config| - # All Vagrant configuration is done here. The most common configuration - # options are documented and commented below. For a complete reference, - # please see the online documentation at vagrantup.com. - - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "precise32" - config.vm.host_name = "cmfsandbox" - config.vm.customize ["modifyvm", :id, "--memory", 768] - - # 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/precise32.box" - - # Boot with a GUI so you can see the screen. (Default is headless) - # config.vm.boot_mode = :gui - - config.vm.network :hostonly, "172.22.22.22" - config.vm.share_folder "v-root", "/vagrant", ".." , :nfs => true - # without this symlinks can't be created on the shared folder - config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] - - - # create jackrabbit folder in repo and uncomment line if you want to keep your - # repository outside the vm - # config.vm.share_folder "jackrabbit", "/opt/jackrabbit/repository", "../jackrabbit" - - # chef solo configuration - config.vm.provision :chef_solo do |chef| - chef.cookbooks_path = "./" - # chef debug level, start vagrant like this to debug: - # $ CHEF_LOG_LEVEL=debug vagrant - chef.log_level = ENV['CHEF_LOG'] || "info" - - # chef recipes - chef.add_recipe("cookbook") - end -end diff --git a/vagrant/composer.sh b/vagrant/composer.sh new file mode 100644 index 00000000..f92c788d --- /dev/null +++ b/vagrant/composer.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +exec_cmf_command() { + su -l vagrant -c "(cd /var/www/cmf && $1)" +} + +init_mysql() { + exec_cmf_command "php app/console doctrine:database:create" + exec_cmf_command "php app/console doctrine:phpcr:init:dbal" +} + +init_jackrabbit() { + exec_cmf_command "./jack start" +} + +main() { + storage_type=`cat /etc/storage_type.txt` + + exec_cmf_command "composer install" + + if [ $storage_type = 'mysql' ]; then + init_mysql + else + init_jackrabbit + fi + + exec_cmf_command "php app/console doctrine:phpcr:workspace:create default" + exec_cmf_command "php app/console doctrine:phpcr:repository:init" + exec_cmf_command "php app/console -v doctrine:phpcr:fixtures:load --no-interaction" + exec_cmf_command "php app/console assetic:dump" + + export $storage_type +} + +main diff --git a/vagrant/cookbook/recipes/default.rb b/vagrant/cookbook/recipes/default.rb deleted file mode 100644 index 9a2f6ab9..00000000 --- a/vagrant/cookbook/recipes/default.rb +++ /dev/null @@ -1,125 +0,0 @@ -# Run apt-get update to create the stamp file -execute "apt-get-update" do - command "apt-get update" - ignore_failure true - not_if do ::File.exists?('/var/lib/apt/periodic/update-success-stamp') end -end - -# For other recipes to call to force an update -execute "apt-get update" do - command "apt-get update" - ignore_failure true - action :nothing -end - -# provides /var/lib/apt/periodic/update-success-stamp on apt-get update -package "update-notifier-common" do - notifies :run, resources(:execute => "apt-get-update"), :immediately -end - -execute "apt-get-update-periodic" do - command "apt-get update" - ignore_failure true - only_if do - File.exists?('/var/lib/apt/periodic/update-success-stamp') && - File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now - 86400 - end -end - -# install the software we need -%w( -openjdk-6-jre-headless -curl -tmux -vim -emacs23-nox -git -libapache2-mod-php5 -php5-cli -php5-curl -php5-gd -php5-sqlite -php5-intl -php-apc -).each { | pkg | package pkg } - - -template "/etc/apache2/sites-enabled/vhost.conf" do - user "root" - mode "0644" - source "vhost.conf.erb" - notifies :reload, "service[apache2]" -end - -service "apache2" do - supports :restart => true, :reload => true, :status => true - action [ :enable, :start ] -end - -directory "/opt/jackrabbit" do - owner "root" - group "root" -end - -remote_file "/opt/jackrabbit/jackrabbit.jar" do - source "http://archive.apache.org/dist/jackrabbit/2.4.3/jackrabbit-standalone-2.4.3.jar" - mode "0644" - checksum "e65d2677a9514cf9f8cd216d6a331c2253fd37a2e8daab9a6ca928d602aa83b7" -end - -template "/etc/init.d/jackrabbit" do - mode "0755" - source "jackrabbit.erb" -end - -service "jackrabbit" do - action :start -end - -{ "/vagrant/app/config/parameters.yml.dist" => "/vagrant/app/config/parameters.yml", - "/vagrant/app/config/phpcr_jackrabbit.yml.dist" => "/vagrant/app/config/phpcr.yml" }.each do | src, dest | - file dest do - content IO.read(src) - end -end - -execute "check if short_open_tag is Off in /etc/php5/apache2/php.ini?" do - user "root" - not_if "grep 'short_open_tag = Off' /etc/php5/apache2/php.ini" - command "sed -i 's/short_open_tag = On/short_open_tag = Off/g' /etc/php5/apache2/php.ini" -end - -execute "check if short_open_tag is Off in /etc/php5/cli/php.ini?" do - user "root" - not_if "grep 'short_open_tag = Off' /etc/php5/cli/php.ini" - command "sed -i 's/short_open_tag = On/short_open_tag = Off/g' /etc/php5/cli/php.ini" -end - -execute "check if date.timezone is Europe/Paris in /etc/php5/apache2/php.ini?" do - user "root" - not_if "grep '^date.timezone = Europe/Paris' /etc/php5/apache2/php.ini" - command "sed -i 's/;date.timezone =.*/date.timezone = Europe\\/Paris/g' /etc/php5/apache2/php.ini" -end - -execute "check if date.timezone is Europe/Paris in /etc/php5/cli/php.ini?" do - user "root" - not_if "grep '^date.timezone = Europe/Paris' /etc/php5/cli/php.ini" - command "sed -i 's/;date.timezone =.*/date.timezone = Europe\\/Paris/g' /etc/php5/cli/php.ini" -end - -bash "Running composer install and preparing the phpcr repository" do - not_if "test -e /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public" - user "vagrant" - cwd "/vagrant" - code <<-EOH - set -e - ln -sf /var/tmp/vendor - curl -s https://getcomposer.org/installer | php - COMPOSER_VENDOR_DIR="/var/tmp/vendor" php composer.phar install - echo "Waiting for Jackrabbit:" - while [[ -z `curl -s "http://localhost:8080"` ]] ; do sleep 1s; echo -n "."; done - app/console doctrine:phpcr:workspace:create sandbox - app/console doctrine:phpcr:repository:init - app/console doctrine:phpcr:fixtures:load - EOH -end diff --git a/vagrant/cookbook/templates/default/jackrabbit.erb b/vagrant/cookbook/templates/default/jackrabbit.erb deleted file mode 100644 index ac5db8a8..00000000 --- a/vagrant/cookbook/templates/default/jackrabbit.erb +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: jackrabbit -# Short-Description: Start/stop Jackrabbit JCR server. -# -# Description: This relies on a PID file to check if Jackrabbit is running. -# If you kill Jackrabbit without removing the PID file, you -# will not be able to start Jackrabbit with this script until -# you manually remove the PID file. -# Edit the variables below to configure Jackrabbit -# Depending on the storage backend, you might want to adjust -# the required start / stop lines. -# -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Required-Start: -# Required-Stop: -# -# Author: Daniel Barsotti -# Bastian Widmer -# -# Modified by -### END INIT INFO - - -### PLEASE EDIT THESE VALUES FOR YOUR SETUP -# Directory in which jackrabbit will store local data, must be writeable -BASEDIR=/opt/jackrabbit -# Full filename of jackrabbit standalone .jar to run -JACKRABBIT_JAR=$BASEDIR/jackrabbit.jar -# IP address for jackrabbit to listen on. you can make jackrabbit listen on all -# interfaces by using 0.0.0.0 here. -JACKRABBIT_HOST=0.0.0.0 -# Port number to listen on. 8080 is default, you can use something else -JACKRABBIT_PORT=8080 -# Java memory allocation -MEMORY="-XX:MaxPermSize=128m -Xmx512M -Xms128M" -# Full filename to the logfile to output console output of jackrabbit -# additionally, jackrabbit has its own logfile -LOGFILE=$BASEDIR/jackrabbit.log -### - -PID=$(pgrep -f "java $MEMORY -jar $JACKRABBIT_JAR -h $JACKRABBIT_HOST -p $JACKRABBIT_PORT") - -do_start() { - if [ -z "$PID" ] ; then - cd $BASEDIR - nohup java $MEMORY -jar $JACKRABBIT_JAR -h $JACKRABBIT_HOST -p $JACKRABBIT_PORT >> $LOGFILE 2>&1 & - # Wait until the server is ready (from an idea of Christoph Luehr) - echo "Jackrabbit started in the background" - else - echo "Jackrabbit is already running" - fi -} - -do_stop() { - if ! [ -z "$PID" ] ; then - kill "$PID" - echo "Jackrabbit stopped" - else - echo "Jackrabbit is not running" - fi - exit 3 -} - -do_status() { - if ! [ -z "$PID" ]; then - echo "Jackrabbit is running [ pid = "$PID"]" - else - echo "Jackrabbit is not running" - exit 3 - fi -} - -case "$1" in - start) - do_start - ;; - stop) - do_stop - ;; - status) - do_status - ;; - *) - echo "Usage: $SCRIPTNAME {start|stop|status}" >&2 - exit 3 - ;; -esac diff --git a/vagrant/cookbook/templates/default/vhost.conf.erb b/vagrant/cookbook/templates/default/vhost.conf.erb deleted file mode 100644 index 60754a14..00000000 --- a/vagrant/cookbook/templates/default/vhost.conf.erb +++ /dev/null @@ -1,13 +0,0 @@ -# Override the Apache User (vhosts are included at the end of apache2.conf) -User vagrant -Group vagrant - - - Servername cmf.lo - Serveralias 172.22.22.22 - DocumentRoot /vagrant/web - - AllowOverride All - - - diff --git a/vagrant/hiera.yaml b/vagrant/hiera.yaml new file mode 100644 index 00000000..86b88508 --- /dev/null +++ b/vagrant/hiera.yaml @@ -0,0 +1,17 @@ +# INTERNAL: +# This file contains the paths of the configuration files for the puppet provisioner. +# This should NOT be edited! + +--- +:backends: + - yaml + +:yaml: + :datadir: /var/www/cmf/vagrant + +:hierarchy: + - hieradata/puppet + - hieradata/common + - hieradata/local + - machine + - local_machine diff --git a/vagrant/hieradata/common.yaml b/vagrant/hieradata/common.yaml new file mode 100644 index 00000000..a6c04448 --- /dev/null +++ b/vagrant/hieradata/common.yaml @@ -0,0 +1,35 @@ +## Infrastructure +cmf::infrastructure::packages::installs: + - vim + - git + - wget + - bash-completion + - ruby-dev + - software-properties-common + - python-software-properties + +## Application +cmf::application::php::version: "5.6" # Available are "5.5" and "5.6" +#cmf::application::php::use_apc: false +#cmf::application::php::use_xdebug: true +#cmf::application::php::environment: dev + +#cmf::application::symfony::environment: dev +#cmf::application::symfony::allow_override: None +cmf::application::symfony::front: app_dev.php +cmf::application::symfony::vhost_name: cmf.dev + +## PHPCR +cmf::infrastructure::phpcr::mysql: true +cmf::infrastructure::phpcr::jack: false + +## MySQL +cmf::infrastructure::phpcr::mysql_wrapper::root_password: root +cmf::infrastructure::phpcr::mysql_wrapper::database_name: cmf-database +cmf::infrastructure::phpcr::mysql_wrapper::database_credentials: + user: dev + password: dev + host: localhost + +## Jackrabbit +#cmf::infrastructure::phpcr::jack_wrapper::version: "2.6.5" diff --git a/vagrant/hieradata/puppet.yaml b/vagrant/hieradata/puppet.yaml new file mode 100644 index 00000000..2b31a660 --- /dev/null +++ b/vagrant/hieradata/puppet.yaml @@ -0,0 +1,7 @@ +classes: + - cmf::infrastructure::packages + - cmf::infrastructure::phpcr + - cmf::application::symfony + - cmf::application::php + +environment: dev diff --git a/vagrant/machine.yaml b/vagrant/machine.yaml new file mode 100644 index 00000000..768d89ea --- /dev/null +++ b/vagrant/machine.yaml @@ -0,0 +1,8 @@ +# Machine configuration parameters + +ip: 192.168.66.211 + +#cpus: 1 +#memory: 1024 +#name: Symfony-CMF VM +#hostname: symfony-cmf diff --git a/vagrant/manifests/site.pp b/vagrant/manifests/site.pp new file mode 100644 index 00000000..7959e7b1 --- /dev/null +++ b/vagrant/manifests/site.pp @@ -0,0 +1 @@ +hiera_include('classes') diff --git a/vagrant/puppet.sh b/vagrant/puppet.sh new file mode 100644 index 00000000..1f0412a8 --- /dev/null +++ b/vagrant/puppet.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# preparing +mkdir -p /etc/puppet/modules +sudo apt-get update + +# install modules +puppet module install puppetlabs/stdlib --force +puppet module install puppetlabs/apt --force +puppet module install puppetlabs/mysql --force +puppet module install puppetlabs-gcc --force +puppet module install puppetlabs-java --force +puppet module install example42/puppi --force +puppet module install example42/apache --force +puppet module install example42/php --force +puppet module install willdurand/composer --force +puppet module install maestrodev/wget --force +puppet module install ripienaar/concat --force diff --git a/vagrant/puppet/cmf/manifests/application/parameters.pp b/vagrant/puppet/cmf/manifests/application/parameters.pp new file mode 100644 index 00000000..043ec09d --- /dev/null +++ b/vagrant/puppet/cmf/manifests/application/parameters.pp @@ -0,0 +1,37 @@ +class cmf::application::parameters( + $dist_template = undef, + $credentials = undef +) { + if $credentials == undef { + if $dist_template != undef { + fail('The dist template requires the credentials hash!') + } + + $db_credentials = {} + } + else { + validate_hash($credentials) + + $db_credentials = $credentials + } + + if $dist_template != undef { + $host = $credentials[host] + $user = $credentials[user] + $password = $credentials[password] + $dbname = $credentials[db] + + $compiled_parameter_file = template($dist_template) + + file { '/var/www/cmf/app/config/parameters.yml': + ensure => present, + content => $compiled_parameter_file, + } + } + else { + file { '/var/www/cmf/app/config/parameters.yml': + ensure => present, + source => '/var/www/cmf/app/config/parameters.yml.dist', + } + } +} diff --git a/vagrant/puppet/cmf/manifests/application/php.pp b/vagrant/puppet/cmf/manifests/application/php.pp new file mode 100644 index 00000000..1e8f92e5 --- /dev/null +++ b/vagrant/puppet/cmf/manifests/application/php.pp @@ -0,0 +1,55 @@ +class cmf::application::php( + $version = '5.5', + $use_apc = undef, + $use_xdebug = undef, + $environment = hiera('environment', 'dev') +) { + validate_string($environment) + + case $version { + '5.5': { $ppaVersion = 'php5' } + '5.6': { $ppaVersion = 'php5-5.6' } + default: { + $supported = join(['5.5', '5.6'], ',') + + fail( + "Invalid parameter for cmf::application::php::version given! The values ${$supported} are supported only!" + ) + } + } + + ::apt::ppa { "ppa:ondrej/${ppaVersion}": } + + exec { 'php::apt-get-upgrade': + command => '/usr/bin/apt-get -y upgrade', + } + + class { '::php': + service => 'apache', + } + + ::php::module { 'gd': } + ::php::module { 'cli': } + ::php::module { 'mysql': } + ::php::module { 'curl': } + ::php::module { 'intl': } + ::php::module { 'mcrypt': } + ::php::module { 'sqlite': } + + if $environment == 'dev' or $use_xdebug == true { + ::php::module { 'xdebug': } + } + + if $environment == 'prod' or $use_apc == true { + ::php::module { 'apc': + module_prefix => 'php-', + } + } + + class { '::composer': + command_name => 'composer', + auto_update => true, + require => Package['php5'], + target_dir => '/usr/local/bin', + } +} diff --git a/vagrant/puppet/cmf/manifests/application/symfony.pp b/vagrant/puppet/cmf/manifests/application/symfony.pp new file mode 100644 index 00000000..b0bf6912 --- /dev/null +++ b/vagrant/puppet/cmf/manifests/application/symfony.pp @@ -0,0 +1,24 @@ +class cmf::application::symfony( + $environment = hiera('environment', 'dev'), + $allow_override = undef, + $front, + $vhost_name = 'cmf.dev' +) { + $override = $allow_override ? { + undef => 'None', + default => $allow_override + } + + validate_string($override) + validate_string($front) + validate_string($vhost_name) + + class { '::apache': } + + ::apache::module { 'rewrite': } + ::apache::vhost { $vhost_name: + template => 'cmf/cmf_vhost.erb', + directory_allow_override => $override, + server_name => $vhost_name + } +} diff --git a/vagrant/puppet/cmf/manifests/infrastructure/packages.pp b/vagrant/puppet/cmf/manifests/infrastructure/packages.pp new file mode 100644 index 00000000..893f82db --- /dev/null +++ b/vagrant/puppet/cmf/manifests/infrastructure/packages.pp @@ -0,0 +1,9 @@ +class cmf::infrastructure::packages($installs) { + validate_array($installs) + + class { '::apt': } + + package { $installs: + ensure => installed, + } +} diff --git a/vagrant/puppet/cmf/manifests/infrastructure/phpcr.pp b/vagrant/puppet/cmf/manifests/infrastructure/phpcr.pp new file mode 100644 index 00000000..60852ba7 --- /dev/null +++ b/vagrant/puppet/cmf/manifests/infrastructure/phpcr.pp @@ -0,0 +1,45 @@ +class cmf::infrastructure::phpcr($mysql, $jack) { + validate_bool($mysql) + validate_bool($jack) + + if $mysql == true { + if $jack == true { + fail('$mysql AND $jack cannot be true!') + } + + include ::cmf::infrastructure::phpcr::mysql_wrapper + + $db_hash = {'db' => hiera('cmf::infrastructure::phpcr::mysql_wrapper::database_name', {})} + $credential_hash = hiera('cmf::infrastructure::phpcr::mysql_wrapper::database_credentials', {}) + + $type = 'mysql' + $yml_file = 'phpcr_doctrine_dbal.yml.dist' + $dist_template = 'cmf/parameters.erb' + $credentials = merge($db_hash, $credential_hash) + } + elsif $jack == true { + include ::cmf::infrastructure::phpcr::jack_wrapper + + $type = 'jack' + $yml_file = 'phpcr_jackrabbit.yml.dist' + $dist_template = undef + $credentials = undef + } + else { + fail('Either $mysql or $jack must be true!') + } + + class { '::cmf::application::parameters': + dist_template => $dist_template, + credentials => $credentials + } + + file { '/etc/storage_type.txt': + content => $type, + } + + file { '/var/www/cmf/app/config/phpcr.yml': + ensure => present, + source => "/var/www/cmf/app/config/${yml_file}", + } +} diff --git a/vagrant/puppet/cmf/manifests/infrastructure/phpcr/jack_wrapper.pp b/vagrant/puppet/cmf/manifests/infrastructure/phpcr/jack_wrapper.pp new file mode 100644 index 00000000..51200079 --- /dev/null +++ b/vagrant/puppet/cmf/manifests/infrastructure/phpcr/jack_wrapper.pp @@ -0,0 +1,18 @@ +class cmf::infrastructure::phpcr::jack_wrapper($version) { + validate_string($version) + + $target = "http://mirror.switch.ch/mirror/apache/dist/jackrabbit/${version}/jackrabbit-standalone-${version}.jar" + $file = "/var/www/cmf/jackrabbit-standalone-${version}.jar" + + class { '::java': + distribution => 'jre', + } -> + exec { 'retrieve_jackrabbit_jar': + command => "/usr/bin/wget ${target} -O ${file}", + creates => $file, + } -> + file { $file: + mode => 0755, + require => Exec['retrieve_jackrabbit_jar'], + } +} diff --git a/vagrant/puppet/cmf/manifests/infrastructure/phpcr/mysql_wrapper.pp b/vagrant/puppet/cmf/manifests/infrastructure/phpcr/mysql_wrapper.pp new file mode 100644 index 00000000..a6bde2ca --- /dev/null +++ b/vagrant/puppet/cmf/manifests/infrastructure/phpcr/mysql_wrapper.pp @@ -0,0 +1,32 @@ +class cmf::infrastructure::phpcr::mysql_wrapper( + $root_password, + $database_name, + $database_credentials +) { + validate_string($root_password) + validate_string($database_name) + validate_hash($database_credentials) + + if $database_credentials[host] == undef { + fail('Database host must not be null!') + } + + if $database_credentials[user] == undef { + fail('Database user must not be null!') + } + + if $database_credentials[password] == undef { + fail('Database password must not be null!') + } + + class { '::mysql::server': + override_options => { 'root_password' => $root_password, }, + } + + ::mysql::db { $database_name: + host => $database_credentials[host], + user => $database_credentials[user], + password => $database_credentials[password], + grant => ['ALL'] + } +} diff --git a/vagrant/puppet/cmf/templates/cmf_vhost.erb b/vagrant/puppet/cmf/templates/cmf_vhost.erb new file mode 100644 index 00000000..60dd171e --- /dev/null +++ b/vagrant/puppet/cmf/templates/cmf_vhost.erb @@ -0,0 +1,24 @@ +# Custom vhost for puppet + + + ServerName <%= @server_name_value %> + DocumentRoot /var/www/cmf/web +<% if scope.lookupvar('ip') == nil %> + ServerAlias 192.168.66.211 +<% else %> + ServerAlias <%= scope.lookupvar('ip') %> +<% end %> + + ErrorLog <%= scope.lookupvar('apache::log_dir') %>/<%= @name %>-error_log + CustomLog <%= scope.lookupvar('apache::log_dir') %>/<%= @name %>-access_log common + + + AllowOverride <%= @directory_allow_override %> + + DirectoryIndex <%= scope.lookupvar('cmf::application::symfony::front') %> + + RewriteEngine on + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ <%= scope.lookupvar('cmf::application::symfony::front') %> [QSA,L] + + diff --git a/vagrant/puppet/cmf/templates/parameters.erb b/vagrant/puppet/cmf/templates/parameters.erb new file mode 100644 index 00000000..f9a86bb6 --- /dev/null +++ b/vagrant/puppet/cmf/templates/parameters.erb @@ -0,0 +1,28 @@ +parameters: + locale: en + locales: [en, fr, de] + + secret: ThisTokenIsNotSoSecretChangeIt + + # a little hack to avoid errors on missing node/coffeescript. + # remove -disabled if you want coffee. + coffee.extension: "\.coffee-disabled$" + coffee.bin: '' + coffee.node: '' + + database_driver: pdo_mysql + database_host: <%= @host %> + database_port: ~ + database_name: <%= @dbname %> + database_user: <%= @user %> + database_password: <%= @password %> + database_path: ~ + + mailer_transport: smtp + mailer_host: localhost + mailer_user: ~ + mailer_password: ~ + + security_users: + user: { password: user, roles: [ 'ROLE_USER' ] } + admin: { password: admin, roles: [ 'ROLE_ADMIN' ] } diff --git a/web/app_dev.php b/web/app_dev.php index 8bf9190b..06339317 100644 --- a/web/app_dev.php +++ b/web/app_dev.php @@ -11,7 +11,7 @@ || !in_array(@$_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1', - '172.22.22.1', + '192.168.66.1', // ip of the vagrant machine (needs to be changed when having another ip) )) ) { header('HTTP/1.0 403 Forbidden');