Skip to content
Gianni Moschini edited this page Jun 23, 2013 · 28 revisions

Requirements

You will need

  • ssh
  • vagrant
  • librarian-chef
  • VirtualBox, VMWare or AWS

Will Provision

  • PHP >= 5.3
  • MongoDB >= 2.2
  • Python
  • Apache2
  • RabbitMQ
  • PhantomJS >= 1.5
  • Supervisor

Installation

The easiest way to install is to use chef. This will install all the components for you (works only with ubuntu at the moment, but feel free to adapt this to your favourite distribution)

Install ruby, chef and librarian-chef

sudo apt-get install ruby rubygems
sudo gem install chef
sudo gem install librarian

Create a Cheffile

site 'http://community.opscode.com/api/v1'

cookbook 'git', '>= 2.0.0'
cookbook 'rvm',
   :git => 'https://github.com/fnichol/chef-rvm'
cookbook 'rabbitmq'
cookbook 'mongodb-10gen' 
cookbook 'apache2', '>= 1.0.0'
cookbook 'php', '>= 1.1'
cookbook 'python', '>= 1.2.2'
cookbook 'supervisor', 
    :git => 'https://github.com/escapestudios/chef-supervisor'
cookbook 'phantomjs', '>= 0.0.10'
cookbook 'composer'
cookbook 'symfony2',
    :git => 'git://github.com/geoffreytran/chef-symfony2.git'
cookbook 'nodejs'
cookbook 'npm'
cookbook 'lesscss',
    :git => 'git://github.com/geoffreytran/chef-lesscss.git'

Librarian Chef

Use librarian-chef to download all cookbooks on your machine.

librarian-chef update

You are ready to use these recipes with whatever you choose, for example with Vagrant.

download and install vagrant

VirtualBox specific

vagrant box add raring-64 http://cloud-images.ubuntu.com/raring/current/raring-server-cloudimg-vagrant-amd64-disk1.box
vagrant init raring-64

AWS specific

vagrant plugin install vagrant-aws # to provision with aws
vagrant plugin install vagrant-omnibus # to install chef-solo when provisioning
vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
vagrant init

Copy the content to the file called Vagrantfile (created by vagrant init)

For vagrant 1.0 (Virtual Box)

Vagrant::Config.run do |config|
  # Setup the box
  config.vm.define :perf do |perf_config|
      perf_config.vm.box = "raring-64"
      # Feel free to change the port if you like
      perf_config.vm.forward_port 80, 4567
      # uncomment this line if you want to force the IP address of the VM
      # perf_config.vm.network :hostonly, "10.0.0.5"
      perf_config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
         chef.add_recipe "mongodb-10gen::single"
         chef.add_recipe "apache2"
         chef.add_recipe "apache2::mod_php5"
         chef.add_recipe "rabbitmq"
         chef.add_recipe "git"
         chef.add_recipe "phantomjs"
         chef.add_recipe "nodejs::install_from_package"
         chef.add_recipe "python::package"
         chef.add_recipe "php::package"
         chef.add_recipe "composer"
         chef.add_recipe "perfmonitor"
         chef.add_recipe "supervisor"
         chef.add_recipe "supervisor::programs"
      end
  end
end

For vagrant 1.1+ (Virtual Box)

    Vagrant.configure("2") 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 = "raring-64"
            config.vm.network :forwarded_port, guest: 80, host: 4567
            # this line is optional if you want to force the IP address of your VM
            # config.vm.network :private_network, ip: "10.0.0.5"
            # The rest is the same as the version for vagrant 1.0
            config.vm.provision :chef_solo do |chef|
                    chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
                    # chef.roles_path = "roles"
                    # chef.data_bags_path = "data_bags"
                    chef.add_recipe "mongodb-10gen::single"
                    chef.add_recipe "apache2"
                    chef.add_recipe "apache2::mod_php5"
                    chef.add_recipe "rabbitmq"
                    chef.add_recipe "git"
                    chef.add_recipe "phantomjs"
                    chef.add_recipe "nodejs::install_from_package"
                    chef.add_recipe "python::package"
                    chef.add_recipe "php::package"
                    chef.add_recipe "composer"
                    chef.add_recipe "perfmonitor"
                    chef.add_recipe "supervisor"
                    chef.add_recipe "supervisor::programs"
            end
    end

For vagrant 1.1+ (AWS)

    Vagrant.configure("2") 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 = "dummy"
            # install latest chef-solo binary before provisioning
            config.omnibus.chef_version = :latest
            # The rest is the same as the version for vagrant 1.0
            config.vm.provision :chef_solo do |chef|
                    chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
                    # chef.roles_path = "roles"
                    # chef.data_bags_path = "data_bags"
                    chef.add_recipe "mongodb-10gen::single"
                    chef.add_recipe "apache2"
                    chef.add_recipe "apache2::mod_php5"
                    chef.add_recipe "rabbitmq"
                    chef.add_recipe "git"
                    chef.add_recipe "phantomjs"
                    chef.add_recipe "nodejs::install_from_package"
                    chef.add_recipe "python::package"
                    chef.add_recipe "php::package"
                    chef.add_recipe "composer"
                    chef.add_recipe "perfmonitor"
                    chef.add_recipe "supervisor"
                    chef.add_recipe "supervisor::programs"
            end
            config.vm.provider :aws do |aws, override|
                    aws.access_key_id = "YOUR KEY"
                    aws.secret_access_key = "YOUR SECRET KEY"
                    aws.keypair_name = "KEYPAIR NAME"

                    override.ssh.username = "ubuntu"
                    override.ssh.private_key_path = "/path/to/key.pem"

                    aws.region = "eu-west-1"
                    aws.instance_type = "t1.micro"

                    aws.ami = "ami-3d160149" # this is ubuntu 13.04 in eu-west-1
            end
    end

The line perfmonitor refers to a custom recipe. Place it in a different directory, like site-cookbooks, as otherwise librarian-chef will delete it when you run librarian-chef install/update.

site-cookbooks/perfmonitor/recipes/default.rb

execute "installphpmongo" do
  command "sudo pecl install -f mongo"
  action :run
end

git "/var/www/perfmonitor" do
  repository "git://github.com/leibowitz/perfmonitor.git"
  reference "master"
  action :sync
end

execute "updatecomposer" do 
  command "cd /var/www/perfmonitor && sudo composer install"
  action :run
end

execute "installless" do
  command "sudo npm install less -g"
  action :run
end

execute "fixpermissions" do
  command "cd /var/www/perfmonitor/app && sudo chgrp -R www-data cache logs && sudo chmod -R g+rw cache logs"
  action :run
end

node[:symfony2][:user] = 'root'

symfony2_console "Generate assets" do
  action :cmd

  command "assetic:dump"

  path '/var/www/perfmonitor'
end

node['supervisor']['programs'] = {
    'queue'=> {
        'name' => 'queue',
        'command' => 'python /var/www/perfmonitor/bin/receive.py',
        'autostart' => true,
        'autorestart' => true,
        'user' => 'vagrant',
        'startsecs' => 2,
        'numprocs' => 1,
    } 
}

package "python-pip" do
    action :install
end

execute "installpythonlibs" do
  command "sudo pip install pymongo pika"
  action :run
end

execute "installphpmongo" do
  command "sudo echo 'extension=mongo.so' >> /etc/php5/apache2/php.ini"
  action :run
end

execute "restartapache" do 
  command "sudo service apache2 restart"
  action :run
end

Now you are ready to create your box with vagrant.

Virtual Box

vagrant up

When it's done, browse the app at http://localhost:4567/perfmonitor/web/app.php

AWS

vagrant up --provider=aws