Browse files

Initial version

  • Loading branch information...
1 parent 3b3d8a8 commit 6787118a647b2d315e3672ac3c527db1f3c356aa @patrickheeney patrickheeney committed Nov 26, 2013
View
11 .gitignore
@@ -1,15 +1,12 @@
-# Vagrant
+# Vagrant Files
.vagrant
package.box
-# Data / Config
-/files/*
-!/files/config/.gitkeep
-!/files/www/.gitkeep
+# Web Files
+index.html
# Sublime Text
-.sublime-project
-.sublime-workspace
+*.sublime*
# OS or Editor folders
.DS_Store
View
20 LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 Patrick Heeney
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
58 README.md
@@ -0,0 +1,58 @@
+# Protobox #
+
+Protobox is the only [Vagrant](http://vagrantup.com) development box you will ever need. A single YAML file controls all configuration and software installed on the box. It was originally based off of [puphpet](https://puphpet.com) configuration but has since diverged to add more functionality onto the box. It also contains automatic installation of applications from composer or git.
+
+Protobox easily allows you to setup a development environment with PHP, Apache, MySQL, Grunt and quickly switch to developing the same application in PHP, Nginx, Mongodb, Redis. If you need Node, Beakstalkd, or any other package just turn it on in the configuration file and `vagrant up`.
+
+## Examples ##
+
+ mkdir protobox && cd protobox
+ git clone git@github.com/protobox/protobox.git .
+ cp data/vagrant/common.yaml-dist data/vagrant/common.yaml
+ vagrant up
+
+## Configuration ##
+
+The protobox configuration file is found at `data/vagrant/common.yaml`. You can easily install new services by setting `install: 1` under any of the software in the configuration file.
+
+## Functionality ##
+
+Protobox has built in support for the following functionality:
+
+- **Puppet Infrastructure**: Protobox uses librarian-puppet to manage your puppet module infrastructure. Its all controlled from a single yaml file so you can easily add new module dependencies.
+- **Application Installing**: Set the path to a git repo (public or private) or a composer project and upon vagrant up it will be installed for you.
+- **User Preferences**: Upon boot up your dot files in data/dot will be copied to the virtual machine.
+- **SSH Keys**: Place your ssh keys in the data/ssh and reference them from the configuration file to be copied to the virtual machine to easily access any remote servers or github.
+- **SQL Import**: You can add any sql files in data/sql and reference them in the configuration file to be imported upon the bootup of the virtual machine.
+- **Mailcatching**: The mailcatcher package can catch any mail leaving the system for debugging and testing.
+- **Vast Module Selection**: Protobox comes bundled with 15+ of the most common modules that PHP developer use everyday.
+
+## Modules ##
+
+Protobox has built in support for the following modules:
+
+- Any Distro
+- PHP
+- Apache
+- Nginx
+- Mongodb
+- Composer
+- XDebug
+- Xhprof
+- Mailcatcher
+- MySQL
+- PostgreSQL
+- Redis
+- Beanstalkd
+- Ngrok
+- Node
+- Bower
+- Grunt
+
+## License ##
+
+Protobox is licensed under the [MIT license](http://opensource.org/licenses/mit-license.php) and all third-party Puppet Modules are licensed under [Apache License v2.0](http://www.apache.org/licenses/LICENSE-2.0) or [MIT license](http://opensource.org/licenses/mit-license.php).
+
+## Authors ##
+
+Created by [Patrick Heeney](https://github.com/patrickheeney). Original code and concept based on [PuPHPet](https://puphpet.com).
View
140 Vagrantfile
@@ -0,0 +1,140 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+require 'yaml'
+
+dir = Dir.pwd
+vagrant_dir = File.expand_path(File.dirname(__FILE__))
+vagrant_file = 'data/vagrant/common.yaml'
+
+if !File.file?(vagrant_file)
+ puts "Data file is missing: #{vagrant_file}\n"
+ exit
+end
+
+settings = YAML.load_file(vagrant_file)
+
+Vagrant.configure("2") do |config|
+
+ # Store the current version of Vagrant for use in conditionals when dealing
+ # with possible backward compatible issues.
+ vagrant_version = Vagrant::VERSION.sub(/^v/, '')
+
+ vagrant_vm = 'vagrantfile-local'
+
+ # Default Box
+ config.vm.box = settings[vagrant_vm]['vm']['box']
+ config.vm.box_url = settings[vagrant_vm]['vm']['box_url']
+
+ if !settings[vagrant_vm]['vm']['hostname'].nil?
+ config.vm.hostname = settings[vagrant_vm]['vm']['hostname']
+ end
+
+ # Ports and IP Address
+ if !settings[vagrant_vm]['vm']['usable_port_range'].nil?
+ ends = settings[vagrant_vm]['vm']['usable_port_range'].to_s.split('..').map{|d| Integer(d)}
+ config.vm.usable_port_range = (ends[0]..ends[1])
+ end
+
+ config.vm.network :private_network, ip: settings[vagrant_vm]['vm']['network']['private_network'].to_s
+
+ settings[vagrant_vm]['vm']['network']['forwarded_port'].each do |item, port|
+ if !port['guest'].nil? and
+ !port['host'].nil? and
+ !port['guest'].empty? and
+ !port['host'].empty?
+ config.vm.network :forwarded_port, guest: Integer(port['guest']), host: Integer(port['host'])
+ end
+ end
+
+ # Synced Folders
+ settings[vagrant_vm]['vm']['synced_folder'].each do |item, folder|
+ if !folder['source'].nil? and !folder['target'].nil?
+ id = !folder['id'].nil? ? folder['id'] : ''
+ nfs = !folder['nfs'].nil? ? folder['nfs'] : false
+ dis = !folder['disabled'].nil? ? folder['disabled'] : false
+ own = !folder['owner'].nil? ? folder['owner'] : ''
+ grp = !folder['group'].nil? ? folder['group'] : ''
+ opt = !folder['mount_options'].nil? ? folder['mount_options'] : Array.new
+
+ config.vm.synced_folder folder['source'], folder['target'], id: id, disabled: dis, owner: own, group: grp, :nfs => nfs, :mount_options => opt
+ end
+ end
+
+ # Virtual Box Configuration
+ settings[vagrant_vm]['vm']['provider'].each do |prov, options|
+ config.vm.provider prov.to_sym do |params|
+ options.each do |type, values|
+ values.each do |key, value|
+ params.customize [type, :id, "--#{key}", value]
+ end
+ end
+ end
+ end
+
+ # Time Zone
+ #config.vm.provision :shell, :inline => "echo \"America/Chicago\" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
+
+ # Shell Provisioning
+ config.vm.provision :shell, :path => "puppet/shell/initial-setup.sh"
+ config.vm.provision :shell, :path => "puppet/shell/update-puppet.sh"
+ config.vm.provision :shell, :path => "puppet/shell/librarian-puppet-vagrant.sh"
+
+ # Puppet Provisioning
+ settings[vagrant_vm]['vm']['provision'].each do |prov, options|
+ config.vm.provision prov.to_sym do |item|
+ if prov == "puppet"
+ item.facter = {
+ "ssh_username" => "vagrant"
+ }
+ end
+
+ if !options['manifests_path'].nil?
+ item.manifests_path = options['manifests_path']
+ end
+
+ if !options['module_path'].nil?
+ item.module_path = options['module_path']
+ end
+
+ if !options['manifest_file'].nil?
+ item.manifest_file = options['manifest_file']
+ end
+
+ if !options['options'].nil?
+ opt = options['options']
+ else
+ opt = Array.new
+ end
+
+ if !opt.any? { |o| o.include? "--hiera_config" }
+ opt.push('--hiera_config /vagrant/puppet/hiera/hiera.yaml')
+ end
+
+ if !opt.any? { |o| o.include? "--parser" }
+ opt.push('--parser future')
+ end
+
+ if !opt.any? { |o| o.include? "--modulepath" }
+ opt.push('--modulepath /vagrant/puppet/modules:/etc/puppet/modules:/usr/share/puppet/modules')
+ end
+
+ item.options = opt
+ end
+ end
+
+
+ # SSH Configuration
+ settings[vagrant_vm]['ssh'].each do |item, value|
+ if !value.nil?
+ config.ssh.send("#{item}=", value)
+ end
+ end
+
+ # Vagrant Configuration
+ settings[vagrant_vm]['vagrant'].each do |item, value|
+ if !value.nil?
+ config.vagrant.send("#{item}=", /:(.+)/ =~ value ? $1.to_sym : value)
+ end
+ end
+end
View
2 data/config/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
View
2 data/dot/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
View
2 data/sql/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
View
2 data/ssh/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
View
3 data/vagrant/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!common.yaml-dist
View
282 data/vagrant/common.yaml-dist
@@ -0,0 +1,282 @@
+---
+puppetfile:
+ forge: http://forge.puppetlabs.com
+ modules:
+ stdlib:
+ git: git://github.com/puphpet/puppetlabs-stdlib.git
+ #ref: '0.0.3'
+ #path: modules/apt
+ concat:
+ git: git://github.com/puphpet/puppetlabs-concat.git
+ apt:
+ git: git://github.com/puphpet/puppetlabs-apt.git
+ yum:
+ git: git://github.com/puphpet/puppet-yum.git
+ vcsrepo:
+ git: git://github.com/puphpet/puppetlabs-vcsrepo.git
+ ntp:
+ git: git://github.com/puphpet/puppetlabs-ntp.git
+ iptables:
+ git: git://github.com/puphpet/puppet-iptables.git
+ apache:
+ git: git://github.com/puphpet/puppetlabs-apache.git
+ php:
+ git: git://github.com/puphpet/puppet-php.git
+ composer:
+ git: git://github.com/puphpet/puppet-composer.git
+ puphpet:
+ git: git://github.com/puphpet/puppet-puphpet.git
+ mysql:
+ git: git://github.com/puphpet/puppetlabs-mysql.git
+ postgresql:
+ git: git://github.com/puphpet/puppetlabs-postgresql.git
+ nodejs:
+ git: git://github.com/puppetlabs/puppetlabs-nodejs.git
+ mailcatcher:
+ git: git://github.com/protobox/puppet-mailcatcher.git
+ ngrok:
+ git: git://github.com/protobox/puppet-ngrok.git
+
+vagrantfile-local:
+ vm:
+ box: precise32
+ box_url: 'http://files.vagrantup.com/precise32.box'
+ hostname: protobox
+ network:
+ private_network: 192.168.5.10
+ forwarded_port:
+ web:
+ host: ''
+ guest: ''
+ provider:
+ virtualbox:
+ modifyvm:
+ name: protobox
+ natdnshostresolver1: 'on'
+ memory: '1024'
+ setextradata:
+ VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root: 1
+ provision:
+ puppet:
+ manifests_path: puppet/manifests
+ module_path: null
+ manifest_file: default.pp
+ options:
+ #- --verbose
+ #- --debug
+ synced_folder:
+ root:
+ id: vagrant-root
+ source: ./
+ target: /srv/www
+ nfs: false
+ owner: vagrant
+ group: www-data
+ mount_options:
+ - 'dmode=775'
+ - 'fmode=775'
+ usable_port_range: 2200..2250
+ ssh:
+ host: null
+ port: null
+ private_key_path: null
+ public_key_path: null
+ username: vagrant
+ guest_port: null
+ keep_alive: true
+ forward_agent: false
+ forward_x11: false
+ shell: 'bash -l'
+ vagrant:
+ host: ':detect'
+
+server:
+ packages:
+ - vim
+ - vim-common
+ dot_files:
+ -
+ bash_aliases: null
+ ssh:
+ authorized_keys:
+ #user:
+ # key: ''
+ # type: 'ssh-rsa'
+ #user2:
+ # key_file: '/srv/www/data/ssh/known_hosts'
+ # type: 'ssh-rsa'
+ # user: username
+ config:
+ #all:
+ # config_file: '/srv/www/data/ssh/git_config'
+ #github:
+ # config: 'host *\n\tIdentityFile ~/.ssh/git_id_rsa'
+ keys:
+ #user:
+ # key: ''
+ #user2:
+ # key_file: '/srv/www/data/ssh/github_id_rsa'
+ # filename: 'github_id_rsa'
+ _prevent_empty: ''
+
+apache:
+ install: 1
+ modules:
+ - php
+ - rewrite
+ vhosts:
+ app:
+ servername: app.dev
+ serveraliases:
+ - 'www.app.dev'
+ docroot: /srv/www/web/app
+ #docroot_owner: vagrant
+ #docroot_group: www-data
+ default_vhost: false
+ port: '80'
+ setenv:
+ - 'APP_ENV dev'
+ override:
+ - All
+ user: vagrant
+ group: www-data
+ default_vhost: true
+ mpm_module: prefork
+
+nginx:
+ install: 0
+ vhosts:
+ app:
+ server_name: app.dev
+ server_aliases:
+ - www.app.dev
+ www_root: /srv/www/web/app
+ listen_port: '80'
+ index_files:
+ - index.html
+ - index.htm
+ - index.php
+ envvars:
+ - 'APP_ENV dev'
+
+php:
+ version: '54'
+ composer: 1
+ mailcatcher: 1
+ modules:
+ php:
+ - cli
+ - intl
+ - mcrypt
+ - curl
+ pear: { }
+ pecl:
+ - pecl_http
+ ini:
+ display_errors: 'On'
+ error_reporting: '-1'
+ session.save_path: /var/lib/php/session
+ timezone: America/Chicago
+
+xdebug:
+ install: 0
+ settings:
+ xdebug.default_enable: '1'
+ xdebug.remote_autostart: '0'
+ xdebug.remote_connect_back: '1'
+ xdebug.remote_enable: '1'
+ xdebug.remote_handler: dbgp
+ xdebug.remote_port: '9000'
+
+xhprof:
+ install: 0
+ location: /srv/www/web/xhprof
+
+mysql:
+ install: 1
+ phpmyadmin: 0
+ root_password: 'root'
+ databases:
+ app:
+ grant:
+ - ALL
+ name: app
+ host: localhost
+ user: user
+ password: user
+ #sql_file: '/srv/www/data/sql/app.sql'
+ sql_file: ''
+
+postgresql:
+ install: 0
+ root_password: 'root'
+ user_group: postgres
+ databases:
+ app:
+ grant: ALL
+ name: database
+ user: root
+ password: root
+ sql_file: ''
+
+mongodb:
+ install: 0
+ root_password: 'root'
+
+redis:
+ install: 0
+ conf_port: 6379
+ conf_bind: 127.0.0.1
+
+beanstalkd:
+ install: 0
+ listen_addr: '127.0.0.1'
+ listen_port: '11300'
+
+node:
+ install: 0
+ npm:
+ - grunt
+ - grunt-cli
+ - bower
+ gems:
+ - sass
+ - compass
+
+ngrok:
+ install: 1
+ port: 80
+ #subdomain: protoboxapp
+ #httpauth: 'user:password'
+ #proto: 'tcp 22'
+ #client: 'client1 client2 client3'
+ #hostname: 'your.domain.com'
+ #tunnels:
+ # client:
+ # httpauth: 'user:password'
+ # proto: 'https 8080'
+ # ssh:
+ # proto: 'tcp: 22'
+
+application:
+ install: 0
+ sites:
+ app:
+ install: 1
+ provider: git
+ source: 'git@github.com/laravel/laravel.git'
+ args:
+ revision: 'master'
+ pre_install: { }
+ post_install: { }
+ app2:
+ install: 0
+ provider: composer
+ source: 'laravel/laravel'
+ args:
+ prefer_dist: true
+ stability: 'dev'
+ dev: true
+ pre_install: { }
+ post_install:
+ - 'composer update'
View
7 puppet/hiera/hiera.yaml
@@ -0,0 +1,7 @@
+---
+:backends: yaml
+:yaml:
+ :datadir: '/vagrant/data/vagrant'
+:hierarchy:
+ - common
+:logger: console
View
1,105 puppet/manifests/default.pp
@@ -0,0 +1,1105 @@
+
+# Ensure the time is accurate, reducing the possibilities of apt repositories
+# failing for invalid certificates
+include '::ntp'
+
+Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/", "/usr/local/bin/", "/usr/local/sbin" ] }
+File { owner => 0, group => 0, mode => 0644 }
+
+# Fix qualified domain
+if $virtual == "virtualbox" and $fqdn == '' {
+ $fqdn = 'localhost'
+}
+
+# Build default values from hiera
+if $server_values == undef {
+ $server_values = hiera('server', false)
+}
+
+if $php_values == undef {
+ $php_values = hiera('php', false)
+}
+
+if $apache_values == undef {
+ $apache_values = hiera('apache', false)
+}
+
+if $nginx_values == undef {
+ $nginx_values = hiera('nginx', false)
+}
+
+if $xdebug_values == undef {
+ $xdebug_values = hiera('xdebug', false)
+}
+
+if $xhprof_values == undef {
+ $xhprof_values = hiera('xhprof', false)
+}
+
+if $mysql_values == undef {
+ $mysql_values = hiera('mysql', false)
+}
+
+if $postgresql_values == undef {
+ $postgresql_values = hiera('postgresql', false)
+}
+
+if $node_values == undef {
+ $node_values = hiera('node', false)
+}
+
+if $ngrok_values == undef {
+ $ngrok_values = hiera('ngrok', false)
+}
+
+if $application_values == undef {
+ $application_values = hiera('application', false)
+}
+
+# Make sure apache and nginx are both not running
+if is_hash($apache_values) and $apache_values['install'] == 1 and
+ is_hash($nginx_values) and $nginx_values['install'] == 1 {
+ fail( 'Apache and Nginx can\'t both be installed!' )
+}
+
+# Make sure puppet and www-data groups exist
+group { 'puppet': ensure => present }
+group { 'www-data': ensure => present }
+
+# Make sure ssh user exists, setup in vagrant file
+user { $::ssh_username:
+ shell => '/bin/bash',
+ home => "/home/${::ssh_username}",
+ ensure => present
+}
+
+# Make sure common web server users are in www-data group
+user { ['apache', 'nginx', 'httpd', 'www-data']:
+ shell => '/bin/bash',
+ ensure => present,
+ groups => 'www-data',
+ require => Group['www-data']
+}
+
+# Make sure ssh user has a home directory
+file { "/home/${::ssh_username}":
+ ensure => directory,
+ owner => $::ssh_username,
+}
+
+# Make sure ssh user has ssh folder
+file { "/home/${::ssh_username}/.ssh":
+ ensure => directory,
+ mode => 0700,
+ owner => $::ssh_username,
+ group => $::ssh_username,
+ require => File["/home/${::ssh_username}"],
+}
+
+# copy dot files to ssh user's home directory
+exec { 'dotfiles':
+ cwd => "/home/${::ssh_username}",
+ command => "cp -r /vagrant/files/dot/.[a-zA-Z0-9]* /home/${::ssh_username}/ && chown -R ${::ssh_username} /home/${::ssh_username}/.[a-zA-Z0-9]*",
+ onlyif => "test -d /vagrant/files/dot",
+ require => User[$::ssh_username]
+}
+
+# common setup
+case $::osfamily {
+ # debian, ubuntu
+ 'debian': {
+ class { 'apt': }
+
+ Class['::apt::update'] -> Package <|
+ title != 'python-software-properties'
+ and title != 'software-properties-common'
+ |>
+
+ ensure_packages( ['augeas-tools'] )
+ }
+ # redhat, centos
+ 'redhat': {
+ class { 'yum': extrarepo => ['epel'] }
+
+ Class['::yum'] -> Yum::Managed_yumrepo <| |> -> Package <| |>
+
+ exec { 'bash_git':
+ cwd => "/home/${::ssh_username}",
+ command => "curl https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > /home/${::ssh_username}/.bash_git",
+ creates => "/home/${::ssh_username}/.bash_git"
+ }
+
+ file_line { 'link ~/.bash_git':
+ ensure => present,
+ line => 'if [ -f ~/.bash_git ] ; then source ~/.bash_git; fi',
+ path => "/home/${::ssh_username}/.bash_profile",
+ require => [
+ Exec['dotfiles'],
+ Exec['bash_git'],
+ ]
+ }
+
+ file_line { 'link ~/.bash_aliases':
+ ensure => present,
+ line => 'if [ -f ~/.bash_aliases ] ; then source ~/.bash_aliases; fi',
+ path => "/home/${::ssh_username}/.bash_profile",
+ require => [
+ File_line['link ~/.bash_git'],
+ ]
+ }
+
+ ensure_packages( ['augeas'] )
+ }
+}
+
+## Begin Server manifest
+
+if is_hash($server_values) {
+
+ #ssh configuration
+ if is_hash($server_values['ssh']) {
+
+ #ssh authorized keys
+ if is_hash($server_values['ssh']['authorized_keys']) {
+
+ file { "/home/${::ssh_username}/.ssh/authorized_keys":
+ ensure => present,
+ mode => 0600,
+ owner => $::ssh_username,
+ group => $::ssh_username,
+ require => File["/home/${::ssh_username}/.ssh"],
+ }
+
+ $server_values['ssh']['authorized_keys'].each |$key, $value| {
+ if $value['key_file'] != undef {
+ # copy authorized keys to system
+ $path = $value['key_file']
+ exec { "ssh_authorized_key_file-${key}":
+ command => "/bin/cat ${path} >> /home/${::ssh_username}/.ssh/authorized_keys",
+ onlyif => "test -f ${path}",
+ require => File["/home/${::ssh_username}/.ssh/authorized_keys"],
+ }
+ } else {
+ if $value['options'] != undef {
+ $options = $value['options']
+ } else {
+ $options = undef
+ }
+
+ if $value['target'] != undef {
+ $target = $value['target']
+ } else {
+ $target = "/home/${::ssh_username}/.ssh/authorized_keys"
+ }
+
+ if $value['type'] != undef {
+ $type = $value['type']
+ } else {
+ $type = 'ssh-rsa'
+ }
+
+ if $value['user'] != undef {
+ $user = $value['user']
+ } else {
+ $user = $::ssh_username
+ }
+
+ ssh_authorized_key { 'ssh_authorized_key-${key}':
+ ensure => present,
+ key => $value['key'],
+ options => $options,
+ target => $target,
+ type => $type,
+ user => $user,
+ require => File["/home/${::ssh_username}/.ssh/authorized_keys"],
+ }
+ }
+ }
+ }
+
+ #ssh config
+ if is_hash($server_values['ssh']['config']) {
+
+ # Make sure ssh user has ssh config
+ file { "/home/${::ssh_username}/.ssh/config":
+ ensure => present,
+ mode => 0600,
+ owner => $::ssh_username,
+ group => $::ssh_username,
+ require => File["/home/${::ssh_username}/.ssh"],
+ }
+
+ $server_values['ssh']['config'].each |$key, $value| {
+ if $value['config_file'] != undef {
+ #add entries from file
+ $path = $value['config_file']
+ exec { "ssh_config_file-${key}":
+ command => "/bin/cat ${path} >> /home/${::ssh_username}/.ssh/config",
+ onlyif => "test -f ${path}",
+ require => File["/home/${::ssh_username}/.ssh/config"],
+ }
+ } else {
+ #add single config entries
+ $text = $value['config']
+ exec { "ssh_config-${key}":
+ command => "echo \"${text}\" >> /home/${::ssh_username}/.ssh/config",
+ require => File["/home/${::ssh_username}/.ssh/config"],
+ }
+ }
+ }
+ }
+
+ #ssh keys
+ if is_hash($server_values['ssh']['keys']) {
+
+ $server_values['ssh']['keys'].each |$key, $value| {
+ if $value['key_file'] != undef {
+ # copy keys to system
+ $path = $value['key_file']
+
+ if $value['filename'] != undef {
+ $filename = $value['filename']
+ } else {
+ $filename = 'id_rsa'
+ }
+
+ if ! defined(File["/home/${::ssh_username}/.ssh/${filename}"]) {
+ file { "/home/${::ssh_username}/.ssh/${filename}":
+ ensure => file,
+ mode => 0600,
+ owner => $::ssh_username,
+ group => $::ssh_username,
+ require => File["/home/${::ssh_username}/.ssh"],
+ }
+ }
+
+ exec { "ssh_key_file-${key}":
+ command => "/bin/cp ${path} /home/${::ssh_username}/.ssh/${filename}",
+ onlyif => "test -f ${path}",
+ require => File["/home/${::ssh_username}/.ssh/${filename}"],
+ }
+ } else {
+ #add single ssh key
+
+ if $value['host_aliases'] != undef {
+ $host_aliases = $value['host_aliases']
+ } else {
+ $host_aliases = ''
+ }
+
+ if $value['target'] != undef {
+ $target = $value['target']
+ } else {
+ $target = "/home/${::ssh_username}/.ssh/id_rsa"
+ }
+
+ if $value['type'] != undef {
+ $key_type = $value['type']
+ } else {
+ $key_type = 'ssh-rsa'
+ }
+
+ sshkey { 'ssh_key-${key}':
+ ensure => present,
+ key => $value['key'],
+ host_aliases => $host_aliases,
+ target => $target,
+ type => $key_type,
+ }
+ }
+ }
+ }
+ }
+
+ # server packages
+ if !empty($server_values['packages']) {
+ ensure_packages( $server_values['packages'] )
+ }
+}
+
+## Begin PHP manifest
+
+# update PHP version repo
+case $::operatingsystem {
+ 'debian': {
+ add_dotdeb { 'packages.dotdeb.org': release => $lsbdistcodename }
+
+ if is_hash($php_values) {
+ # Debian Squeeze 6.0 can do PHP 5.3 (default) and 5.4
+ if $lsbdistcodename == 'squeeze' and $php_values['version'] == '54' {
+ add_dotdeb { 'packages.dotdeb.org-php54': release => 'squeeze-php54' }
+ }
+ # Debian Wheezy 7.0 can do PHP 5.4 (default) and 5.5
+ elsif $lsbdistcodename == 'wheezy' and $php_values['version'] == '55' {
+ add_dotdeb { 'packages.dotdeb.org-php55': release => 'wheezy-php55' }
+ }
+ }
+ }
+ 'ubuntu': {
+ apt::key { '4F4EA0AAE5267A6C': }
+
+ if is_hash($php_values) {
+ # Ubuntu Lucid 10.04, Precise 12.04, Quantal 12.10 and Raring 13.04 can do PHP 5.3 (default <= 12.10) and 5.4 (default <= 13.04)
+ if $lsbdistcodename in ['lucid', 'precise', 'quantal', 'raring'] and $php_values['version'] == '54' {
+ if $lsbdistcodename == 'lucid' {
+ apt::ppa { 'ppa:ondrej/php5-oldstable': require => Apt::Key['4F4EA0AAE5267A6C'], options => '' }
+ } else {
+ apt::ppa { 'ppa:ondrej/php5-oldstable': require => Apt::Key['4F4EA0AAE5267A6C'] }
+ }
+ }
+ # Ubuntu Precise 12.04, Quantal 12.10 and Raring 13.04 can do PHP 5.5
+ elsif $lsbdistcodename in ['precise', 'quantal', 'raring'] and $php_values['version'] == '55' {
+ apt::ppa { 'ppa:ondrej/php5': require => Apt::Key['4F4EA0AAE5267A6C'] }
+ }
+ elsif $lsbdistcodename in ['lucid'] and $php_values['version'] == '55' {
+ err('You have chosen to install PHP 5.5 on Ubuntu 10.04 Lucid. This will probably not work!')
+ }
+ }
+ }
+ 'redhat', 'centos': {
+ if is_hash($php_values) {
+ if $php_values['version'] == '54' {
+ class { 'yum::repo::remi': }
+ }
+ # remi_php55 requires the remi repo as well
+ elsif $php_values['version'] == '55' {
+ class { 'yum::repo::remi': }
+ class { 'yum::repo::remi_php55': }
+ }
+ }
+ }
+}
+
+define add_dotdeb ($release){
+ apt::source { $name:
+ location => 'http://packages.dotdeb.org',
+ release => $release,
+ repos => 'all',
+ required_packages => 'debian-keyring debian-archive-keyring',
+ key => '89DF5277',
+ key_server => 'keys.gnupg.net',
+ include_src => true
+ }
+}
+
+## Begin Apache manifest
+
+include puphpet::params
+
+$webroot_location = $puphpet::params::apache_webroot_location
+
+# Create web root if it does not exist
+exec { "exec mkdir -p ${webroot_location}":
+ command => "mkdir -p ${webroot_location}",
+ onlyif => "test -d ${webroot_location}",
+}
+
+# Ensure the directory is created with the right ownership
+if ! defined(File[$webroot_location]) {
+ file { $webroot_location:
+ ensure => directory,
+ group => 'www-data',
+ mode => 0775,
+ require => [
+ Exec["exec mkdir -p ${webroot_location}"],
+ Group['www-data']
+ ]
+ }
+}
+
+# Setup apache class
+class { 'apache':
+ user => $apache_values['user'],
+ group => $apache_values['group'],
+ default_vhost => $apache_values['default_vhost'],
+ mpm_module => $apache_values['mpm_module'],
+ manage_user => false,
+ manage_group => false
+}
+
+# Setup the workers
+if $::osfamily == 'debian' {
+ case $apache_values['mpm_module'] {
+ 'prefork': { ensure_packages( ['apache2-mpm-prefork'] ) }
+ 'worker': { ensure_packages( ['apache2-mpm-worker'] ) }
+ 'event': { ensure_packages( ['apache2-mpm-event'] ) }
+ }
+} elsif $::osfamily == 'redhat' and ! defined(Iptables::Allow['tcp/80']) {
+ iptables::allow { 'tcp/80':
+ port => '80',
+ protocol => 'tcp'
+ }
+}
+
+# setup the virtualhosts
+create_resources(apache::vhost, $apache_values['vhosts'])
+
+# setup apache modules
+define apache_mod {
+ if ! defined(Class["apache::mod::${name}"]) {
+ class { "apache::mod::${name}": }
+ }
+}
+
+if count($apache_values['modules']) > 0 {
+ apache_mod { $apache_values['modules']: }
+}
+
+## Begin PHP manifest
+
+Class['Php'] -> Class['Php::Devel'] -> Php::Module <| |> -> Php::Pear::Module <| |> -> Php::Pecl::Module <| |>
+
+if $php_prefix == undef {
+ $php_prefix = $::operatingsystem ? {
+ /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => 'php5-',
+ default => 'php-',
+ }
+}
+
+if $php_fpm_ini == undef {
+ $php_fpm_ini = $::operatingsystem ? {
+ /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/fpm/php.ini',
+ default => '/etc/php.ini',
+ }
+}
+
+if is_hash($apache_values) and $apache_values['install'] == 1 {
+ include apache::params
+
+ $php_webserver_service = 'httpd'
+ $php_webserver_user = $apache::params::user
+
+ class { 'php':
+ service => $php_webserver_service
+ }
+} elsif is_hash($nginx_values) and $nginx_values['install'] == 1 {
+ include nginx::params
+
+ $php_webserver_service = "${php_prefix}fpm"
+ $php_webserver_user = $nginx::params::nx_daemon_user
+
+ class { 'php':
+ package => $php_webserver_service,
+ service => $php_webserver_service,
+ service_autorestart => false,
+ config_file => $php_fpm_ini,
+ }
+
+ service { $php_webserver_service:
+ ensure => running,
+ enable => true,
+ hasrestart => true,
+ hasstatus => true,
+ require => Package[$php_webserver_service]
+ }
+}
+
+class { 'php::devel': }
+
+if count($php_values['modules']['php']) > 0 {
+ php_mod { $php_values['modules']['php']:; }
+}
+if count($php_values['modules']['pear']) > 0 {
+ php_pear_mod { $php_values['modules']['pear']:; }
+}
+if count($php_values['modules']['pecl']) > 0 {
+ php_pecl_mod { $php_values['modules']['pecl']:; }
+}
+if count($php_values['ini']) > 0 {
+ $php_values['ini'].each |$key, $value| {
+ puphpet::ini { $key:
+ entry => "CUSTOM/${key}",
+ value => $value,
+ php_version => $php_values['version'],
+ webserver => $php_webserver_service
+ }
+ }
+
+ if $php_values['ini']['session.save_path'] != undef {
+ exec {"mkdir -p ${php_values['ini']['session.save_path']}":
+ onlyif => "test ! -d ${php_values['ini']['session.save_path']}",
+ }
+
+ file { $php_values['ini']['session.save_path']:
+ ensure => directory,
+ group => 'www-data',
+ mode => 0775,
+ require => Exec["mkdir -p ${php_values['ini']['session.save_path']}"]
+ }
+ }
+}
+
+puphpet::ini { $key:
+ entry => 'CUSTOM/date.timezone',
+ value => $php_values['timezone'],
+ php_version => $php_values['version'],
+ webserver => $php_webserver_service
+}
+
+define php_mod {
+ php::module { $name: }
+}
+define php_pear_mod {
+ php::pear::module { $name: use_package => false }
+}
+define php_pecl_mod {
+ php::pecl::module { $name: use_package => false }
+}
+
+# install composer if needed
+if $php_values['composer'] == 1 {
+ add_composer { "composer": }
+}
+
+define add_composer (
+ $path = ''
+){
+ class { 'composer':
+ target_dir => '/usr/local/bin',
+ composer_file => 'composer',
+ download_method => 'curl',
+ logoutput => false,
+ tmp_path => '/tmp',
+ php_package => "${php::params::module_prefix}cli",
+ curl_package => 'curl',
+ suhosin_enabled => false,
+ }
+}
+
+## Begin XDebug
+
+if is_hash($xdebug_values) and $xdebug_values['install'] != undef and $xdebug_values['install'] == 1 {
+ class { 'puphpet::xdebug':
+ webserver => $php_webserver_service
+ }
+
+ if is_hash($xdebug_values['settings']) and count($xdebug_values['settings']) > 0 {
+ $xdebug_values['settings'].each |$key, $value| {
+ puphpet::ini { $key:
+ entry => "XDEBUG/${key}",
+ value => $value,
+ php_version => $php_values['version'],
+ webserver => $php_webserver_service
+ }
+ }
+ }
+}
+
+## Begin Xhprof manifest
+
+if is_hash($xhprof_values) and $xhprof_values['install'] == 1 {
+ $xhprofPath = $xhprof_values['location']
+
+ php::pecl::module { 'xhprof':
+ use_package => false,
+ preferred_state => 'beta',
+ }
+
+ exec { 'delete-xhprof-path-if-not-git-repo':
+ command => "rm -rf ${xhprofPath}",
+ onlyif => "test ! -d ${xhprofPath}/.git"
+ }
+
+ vcsrepo { $xhprofPath:
+ ensure => present,
+ provider => git,
+ source => 'https://github.com/facebook/xhprof.git',
+ require => Exec['delete-xhprof-path-if-not-git-repo']
+ }
+
+ file { "${xhprofPath}/xhprof_html":
+ ensure => directory,
+ mode => 0775,
+ require => Vcsrepo[$xhprofPath]
+ }
+
+ composer::exec { 'xhprof-composer-run':
+ cmd => 'install',
+ cwd => $xhprofPath,
+ require => [
+ Class['composer'],
+ File["${xhprofPath}/xhprof_html"]
+ ]
+ }
+}
+
+## Begin MySQL manifest
+
+if is_hash($mysql_values) and $mysql_values['install'] == 1 and $mysql_values['root_password'] {
+ class { 'mysql::server':
+ root_password => $mysql_values['root_password'],
+ }
+
+ if is_hash($mysql_values['databases']) and count($mysql_values['databases']) > 0 {
+ create_resources(mysql_db, $mysql_values['databases'])
+ }
+
+ if is_hash($php_values) {
+ if $::osfamily == 'redhat' and $php_values['version'] == '53' and ! defined(Php::Module['mysql']) {
+ php::module { 'mysql': }
+ } elsif ! defined(Php::Module['mysqlnd']) {
+ php::module { 'mysqlnd': }
+ }
+ }
+}
+
+define mysql_db (
+ $user,
+ $password,
+ $host,
+ $grant = [],
+ $sql_file = false
+) {
+ if $name == '' or $password == '' or $host == '' {
+ fail( 'MySQL DB requires that name, password and host be set. Please check your settings!' )
+ }
+
+ mysql::db { $name:
+ user => $user,
+ password => $password,
+ host => $host,
+ grant => $grant,
+ sql => $sql_file,
+ }
+}
+
+## Begin PostgreSQL manifest
+
+if is_hash($postgresql_values) and $postgresql_values['install'] == 1 {
+ if $postgresql_values['root_password'] {
+ group { $postgresql_values['user_group']:
+ ensure => present
+ }
+
+ class { 'postgresql::server':
+ postgres_password => $postgresql_values['root_password'],
+ require => Group[$postgresql_values['user_group']]
+ }
+
+ if is_hash($postgresql_values['databases']) and count($postgresql_values['databases']) > 0 {
+ create_resources(postgresql_db, $postgresql_values['databases'])
+ }
+
+ if is_hash($php_values) and ! defined(Php::Module['pgsql']) {
+ php::module { 'pgsql': }
+ }
+ }
+}
+
+define postgresql_db (
+ $user,
+ $password,
+ $grant,
+ $sql_file = false
+) {
+ if $name == '' or $user == '' or $password == '' or $grant == '' {
+ fail( 'PostgreSQL DB requires that name, user, password and grant be set. Please check your settings!' )
+ }
+
+ postgresql::server::db { $name:
+ user => $user,
+ password => $password,
+ grant => $grant
+ }
+
+ if $sql_file {
+ $table = "${name}.*"
+
+ exec{ "${name}-import":
+ command => "psql ${name} < ${sql_file}",
+ logoutput => true,
+ refreshonly => $refresh,
+ require => Postgresql::Server::Db[$name],
+ onlyif => "test -f ${sql_file}"
+ }
+ }
+}
+
+# Begin PHPMyAdmin
+
+if is_hash($mysql_values) and is_hash($php_values) and $mysql_values['phpmyadmin'] == 1 {
+ if $::osfamily == 'debian' {
+ if $::operatingsystem == 'ubuntu' {
+ apt::key { '80E7349A06ED541C': }
+ apt::ppa { 'ppa:nijel/phpmyadmin': require => Apt::Key['80E7349A06ED541C'] }
+ }
+
+ $phpMyAdmin_package = 'phpmyadmin'
+ $phpMyAdmin_folder = 'phpmyadmin'
+ } elsif $::osfamily == 'redhat' {
+ $phpMyAdmin_package = 'phpMyAdmin.noarch'
+ $phpMyAdmin_folder = 'phpMyAdmin'
+ }
+
+ if ! defined(Package[$phpMyAdmin_package]) {
+ package { $phpMyAdmin_package:
+ require => Class['mysql::server']
+ }
+ }
+
+ include puphpet::params
+
+ if is_hash($apache_values) and $apache_values['install'] == 1 {
+ $mysql_webroot_location = $puphpet::params::apache_webroot_location
+ } elsif is_hash($nginx_values) and $nginx_values['install'] == 1 {
+ $mysql_webroot_location = $puphpet::params::nginx_webroot_location
+
+ mysql_nginx_default_conf { 'override_default_conf':
+ webroot => $mysql_webroot_location
+ }
+ }
+
+ file { "${mysql_webroot_location}/phpmyadmin":
+ target => "/usr/share/${phpMyAdmin_folder}",
+ ensure => link,
+ replace => 'no',
+ require => [
+ Package[$phpMyAdmin_package],
+ File[$mysql_webroot_location]
+ ]
+ }
+}
+
+define mysql_nginx_default_conf (
+ $webroot
+) {
+ if $php5_fpm_sock == undef {
+ $php5_fpm_sock = '/var/run/php5-fpm.sock'
+ }
+
+ if $fastcgi_pass == undef {
+ $fastcgi_pass = $php_values['version'] ? {
+ undef => null,
+ '53' => '127.0.0.1:9000',
+ default => "unix:${php5_fpm_sock}"
+ }
+ }
+
+ class { 'puphpet::nginx':
+ fastcgi_pass => $fastcgi_pass,
+ notify => Class['nginx::service'],
+ }
+}
+
+# Begin Mailcatcher
+
+if is_hash($php_values) and $php_values['mailcatcher'] == 1 {
+ puphpet::ini { 'sendmail_path':
+ entry => "CUSTOM/sendmail_path",
+ value => '/usr/bin/env catchmail',
+ php_version => $php_values['version'],
+ webserver => $php_webserver_service
+ }
+
+ class { 'mailcatcher':
+ service => $php_webserver_service,
+ start => true,
+ }
+}
+
+# Begin Node
+
+if is_hash($node_values) and $node_values['install'] == 1 {
+ class { 'nodejs':
+ manage_repo => true,
+ #https://github.com/puppetlabs/puppetlabs-nodejs/issues/48
+ #version => '0.10.19-1chl1~precise1'
+ }
+
+ # get rid of old npm and install new one
+ exec { 'install-npm':
+ command => '/usr/bin/curl https://npmjs.org/install.sh | /bin/sh', # | sudo clean=yes /bin/sh
+ environment => 'clean=yes',
+ require => [
+ Class['nodejs'],
+ Package['curl'],
+ ],
+ }
+
+ $node_values['npm'].each |$key| {
+ add_node_package { $key:
+ require => [
+ Class['nodejs'],
+ Exec['install-npm'],
+ ]
+ }
+ }
+
+ $node_values['gems'].each |$key| {
+ if ! defined(Package[$name]) {
+ package { $key:
+ ensure => 'installed',
+ provider => 'gem',
+ require => [
+ Class['nodejs'],
+ Exec['install-npm'],
+ ]
+ }
+ }
+ }
+}
+
+define add_node_package (
+ $ensure = present,
+ $version = '',
+ $source = '',
+ $install_opt = '',
+ $remove_opt = '',
+ $path = '',
+ $local = false,
+){
+ validate_bool($local)
+
+ if $local {
+ nodejs::npm { "$path:$name":
+ ensure => $ensure,
+ version => $version,
+ source => $source,
+ install_opt => $install_opt,
+ remove_opt => $remove_opt,
+ }
+ } else {
+ if ! defined(Package[$name]) {
+ package { $name:
+ ensure => $ensure,
+ provider => 'npm',
+ }
+ }
+ }
+}
+
+## Begin NGrok
+
+if is_hash($ngrok_values) and $ngrok_values['install'] == 1 {
+ class { 'ngrok':
+ start => true,
+ port => $ngrok_values['port'],
+ subdomain => $ngrok_values['subdomain'],
+ httpauth => $ngrok_values['httpauth'],
+ proto => $ngrok_values['proto'],
+ client => $ngrok_values['client'],
+ }
+}
+
+## Begin Application
+
+if is_hash($application_values) and $application_values['install'] != undef and $application_values['install'] == 1 {
+ $application_values['sites'].each |$key, $value| {
+ if $value['install'] != undef and $value['install'] == 1 {
+ if is_hash($apache_values) and $apache_values['install'] == 1 and $apache_values['vhosts'][$key] != undef {
+ $application_directory = $apache_values['vhosts'][$key]['docroot']
+ } elsif is_hash($nginx_values) and $nginx_values['install'] == 1 and $nginx_values['vhosts'][$key] != undef {
+ $application_directory = $nginx_values['vhosts'][$key]['www_root']
+ } else {
+ $application_directory = undef
+ }
+
+ if $application_directory != undef {
+ case $value['provider'] {
+ 'git': {
+ add_application_repo{ $key:
+ source => $value['source'],
+ type => 'git',
+ args => $value['args'],
+ pre_process => $value['pre_process'],
+ post_process => $value['post_process'],
+ directory => $application_directory,
+ }
+ }
+ 'composer': {
+ add_application_composer{ $key:
+ source => $value['source'],
+ args => $value['args'],
+ pre_process => $value['pre_process'],
+ post_process => $value['post_process'],
+ directory => $application_directory,
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+define add_application_composer (
+ $source = '',
+ $args = '',
+ $directory = '',
+ $pre_process = undef,
+ $post_process = undef,
+){
+ # anchor resource provides a consistent dependency for prereq.
+ anchor { 'application_composer::begin': }
+ anchor { 'application_composer::end': }
+
+ if $pre_process != undef and count($pre_process) > 0 {
+ $pre_process.each |$key| {
+ exec { 'app-pre-commands-${key}':
+ command => $key,
+ cwd => $directory,
+ before => Anchor['application_composer::begin']
+ }
+ }
+ }
+
+ exec { 'app-delete-if-doesnt-exist':
+ command => "rm -rf ${directory}",
+ onlyif => "test ! -f ${directory}/composer.json",
+ }
+
+ if $php_values['composer'] == 0 {
+ add_composer { "composer":
+ require => Exec['app-delete-if-doesnt-exist']
+ }
+ }
+
+ # Only one of prefer_source or prefer_dist can be true
+ if ($args['prefer_dist'] != undef and $args['prefer_dist'] == true) {
+ $prefer_source = false
+ $prefer_dist = true
+ } else {
+ $prefer_source = true
+ $prefer_dist = false
+ }
+
+ #$packages = $args['packages'] != undef ? $args['packages'] : ''
+ #$custom_installers = $args['custom_installers'] != undef ? $args['dev'] : false
+ #$scripts = $args['scripts'] != undef ? $args['scripts'] : false
+ #$optimize = $args['optimize'] != undef ? $args['optimize'] : false
+ #$dev = $args['dev'] != undef ? $args['dev'] : false
+
+ #composer::exec { $source:
+ # cmd => 'install',
+ # cwd => $directory,
+ # packages => $packages,
+ # prefer_source => $prefer_source,
+ # prefer_dist => $prefer_dist,
+ # custom_installers => $custom_installers,
+ # scripts => $scripts,
+ # optimize => $optimize,
+ # dev => $dev,
+ # interaction => true,
+ # before => Anchor['application::end'],
+ # require => [
+ # Anchor['application::begin'],
+ # Exec['app-delete-if-doesnt-exist'],
+ # Class['composer'],
+ # ],
+ #}
+
+ if $args['version'] != undef {
+ $version = $args['version']
+ } else {
+ $version = undef
+ }
+
+ if $args['stability'] != undef {
+ $stability = $args['stability']
+ } else {
+ $stability = 'dev'
+ }
+
+ if $args['keep_vcs'] != undef {
+ $keep_vcs = $args['keep_vcs']
+ } else {
+ $keep_vcs = false
+ }
+
+ if $args['dev'] != undef {
+ $dev = $args['dev']
+ } else {
+ $dev = false
+ }
+
+ if $args['repo'] != undef {
+ $repo = $args['repo']
+ } else {
+ $repo = undef
+ }
+
+ composer::project { 'install-application-composer':
+ project_name => $source,
+ target_dir => $directory,
+ version => $version,
+ prefer_source => $prefer_source,
+ prefer_dist => $prefer_dist,
+ stability => $stability,
+ keep_vcs => $keep_vcs,
+ dev => $dev,
+ repository_url => $repo,
+ interaction => true,
+ before => Anchor['application_composer::end'],
+ require => [
+ Anchor['application_composer::begin'],
+ Exec['app-delete-if-doesnt-exist'],
+ Class['composer'],
+ ],
+ }
+
+ if $post_process != undef and count($post_process) > 0 {
+ $post_process.each |$key| {
+ exec { 'app-post-commands-${key}':
+ command => $key,
+ cwd => $directory,
+ require => Anchor['application_composer::end']
+ }
+ }
+ }
+}
+
+define add_application_repo (
+ $source = '',
+ $type = '',
+ $args = '',
+ $directory = '',
+ $pre_process = undef,
+ $post_process = undef,
+){
+
+ # anchor resource provides a consistent dependency for prereq.
+ anchor { 'application_repo::begin': }
+ anchor { 'application_repo::end': }
+
+ if $pre_process != undef and count($pre_process) > 0 {
+ $pre_process.each |$key| {
+ exec { 'app-pre-commands-${key}':
+ command => $key,
+ cwd => $directory,
+ before => Anchor['application_repo::begin']
+ }
+ }
+ }
+
+ exec { 'app-delete-if-doesnt-exist':
+ command => "rm -rf ${directory}",
+ onlyif => "test ! -d ${directory}/.git",
+ }
+
+ if $args['revision'] != undef {
+ $revision = $args['revision']
+ } else {
+ $revision = undef
+ }
+
+ vcsrepo { $directory:
+ ensure => present,
+ provider => $type,
+ source => $source,
+ revision => $revision,
+ before => Anchor['application_repo::end'],
+ require => [
+ Anchor['application_repo::begin'],
+ Exec['app-delete-if-doesnt-exist'],
+ ],
+ }
+
+ if $post_process != undef and count($post_process) > 0 {
+ $post_process.each |$key| {
+ exec { 'app-post-commands-${key}':
+ command => $key,
+ cwd => $directory,
+ require => Anchor['application_repo::end']
+ }
+ }
+ }
+}
View
2 puppet/modules/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
View
43 puppet/shell/build-puppetfile.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+require 'yaml'
+
+options = {}
+OptionParser.new do |opts|
+ opts.banner = "Usage: build-puppetfile.rb [options]"
+
+ opts.on('-s', '--source URL', 'Source URL') { |v| options[:source_url] = v }
+end.parse!
+
+yaml_file = options[:source_url]
+
+if yaml_file.nil? or !File.file?(yaml_file)
+ exit
+end
+
+#puts "\#Location: #{yaml_file}"
+
+data = YAML::load_file(yaml_file);
+
+if !data['puppetfile']['forge'].nil?
+ puts "forge \"" + data['puppetfile']['forge'] + "\"\n"
+end
+
+data['puppetfile']['modules'].each do |item, mod|
+ line = "mod '" + item + "'"
+
+ if !mod['git'].nil?
+ line += ", :git => '" + mod['git'] + "'"
+ end
+
+ if !mod['ref'].nil?
+ line += ", :ref => '" + mod['ref'] + "'"
+ end
+
+ if !mod['path'].nil?
+ line += ", :path => '" + mod['path'] + "'"
+ end
+
+ puts line + "\n"
+end
View
35 puppet/shell/initial-setup.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+OS=$(/bin/bash /vagrant/puppet/shell/os-detect.sh ID)
+CODENAME=$(/bin/bash /vagrant/puppet/shell/os-detect.sh CODENAME)
+
+if [[ ! -d /.protobox ]]; then
+ mkdir /.protobox
+ echo "Created directory /.protobox"
+fi
+
+if [[ ! -f /.protobox/initial-setup-repo-update ]]; then
+ if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
+ echo "Running initial-setup apt-get update"
+ apt-get update >/dev/null 2>&1
+ touch /.protobox/initial-setup-repo-update
+ echo "Finished running initial-setup apt-get update"
+ elif [[ "$OS" == 'centos' ]]; then
+ echo "Running initial-setup yum update"
+ yum update -y >/dev/null 2>&1
+ echo "Finished running initial-setup yum update"
+
+ echo "Installing basic development tools (CentOS)"
+ yum -y groupinstall "Development Tools" >/dev/null 2>&1
+ echo "Finished installing basic development tools (CentOS)"
+ touch /.protobox/initial-setup-repo-update
+ fi
+fi
+
+if [[ "$OS" == 'ubuntu' && ("$CODENAME" == 'lucid' || "$CODENAME" == 'precise') && ! -f /.protobox/ubuntu-required-libraries ]]; then
+ echo 'Installing basic curl packages (Ubuntu only)'
+ apt-get install -y libcurl3 libcurl4-gnutls-dev >/dev/null 2>&1
+ echo 'Finished installing basic curl packages (Ubuntu only)'
+
+ touch /.protobox/ubuntu-required-libraries
+fi
View
108 puppet/shell/librarian-puppet-vagrant.sh
@@ -0,0 +1,108 @@
+#!/bin/bash
+
+OS=$(/bin/bash /vagrant/puppet/shell/os-detect.sh ID)
+CODENAME=$(/bin/bash /vagrant/puppet/shell/os-detect.sh CODENAME)
+
+# Directory in which librarian-puppet should manage its modules directory
+PUPPET_DIR=/etc/puppet/
+PUPPET_LOC=/etc/puppet/Puppetfile
+PUPPET_FILE=/.protobox/puppetfile.build
+PUPPET_DATA=/vagrant/data/vagrant/common.yaml
+
+$(which git > /dev/null 2>&1)
+FOUND_GIT=$?
+
+if [ "$FOUND_GIT" -ne '0' ] && [ ! -f /.protobox/librarian-puppet-installed ]; then
+ $(which apt-get > /dev/null 2>&1)
+ FOUND_APT=$?
+ $(which yum > /dev/null 2>&1)
+ FOUND_YUM=$?
+
+ echo 'Installing git'
+
+ if [ "${FOUND_YUM}" -eq '0' ]; then
+ yum -q -y makecache
+ yum -q -y install git
+ else
+ apt-get -q -y install git-core >/dev/null 2>&1
+ fi
+
+ echo 'Finished installing git'
+fi
+
+if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
+ if [[ ! -f /.protobox/librarian-base-packages ]]; then
+ echo 'Installing base packages for librarian'
+ apt-get install -y build-essential ruby-dev libsqlite3-dev >/dev/null 2>&1
+ echo 'Finished installing base packages for librarian'
+
+ touch /.protobox/librarian-base-packages
+ fi
+fi
+
+if [ "$OS" == 'ubuntu' ]; then
+ if [[ ! -f /.protobox/librarian-libgemplugin-ruby ]]; then
+ echo 'Updating libgemplugin-ruby (Ubuntu only)'
+ apt-get install -y libgemplugin-ruby >/dev/null 2>&1
+ echo 'Finished updating libgemplugin-ruby (Ubuntu only)'
+
+ touch /.protobox/librarian-libgemplugin-ruby
+ fi
+
+ if [ "$CODENAME" == 'lucid' ] && [ ! -f /.protobox/librarian-rubygems-update ]; then
+ echo 'Updating rubygems (Ubuntu Lucid only)'
+ echo 'Ignore all "conflicting chdir" errors!'
+ gem install rubygems-update >/dev/null 2>&1
+ /var/lib/gems/1.8/bin/update_rubygems >/dev/null 2>&1
+ echo 'Finished updating rubygems (Ubuntu Lucid only)'
+
+ touch /.protobox/librarian-rubygems-update
+ fi
+fi
+
+if [[ ! -d "$PUPPET_DIR" ]]; then
+ mkdir -p "$PUPPET_DIR"
+ echo "Created directory $PUPPET_DIR"
+fi
+
+if [[ -f "$PUPPET_FILE" ]]; then
+ rm -f "$PUPPET_FILE"
+ echo "Deleted existing puppetfile build"
+fi
+
+#if [[ ! -f "$PUPPET_DATA" ]]; then
+# echo "File does not exist: $PUPPET_DATA"
+# exit 1
+#fi
+
+if [[ ! -f "$PUPPET_FILE" ]] && [[ -f "$PUPPET_DATA" ]]; then
+ echo "Building puppetfile from yaml"
+ cd /vagrant/puppet/shell/ && ruby build-puppetfile.rb -s "$PUPPET_DATA" > "$PUPPET_FILE"
+ echo "Finished building puppetfile"
+fi
+
+if [[ ! -f "$PUPPET_LOC" ]]; then
+ touch "$PUPPET_LOC"
+ echo "Created Puppetfile at $PUPPET_LOC"
+fi
+
+if [[ -f "$PUPPET_FILE" ]] && [[ -f "$PUPPET_LOC" ]]; then
+ cat "$PUPPET_FILE" >> "$PUPPET_LOC"
+ echo "Copied Puppetfile to $PUPPET_LOC"
+fi
+
+if [[ ! -f /.protobox/librarian-puppet-installed ]]; then
+ echo 'Installing librarian-puppet'
+ gem install librarian-puppet >/dev/null 2>&1
+ echo 'Finished installing librarian-puppet'
+
+ echo 'Running initial librarian-puppet'
+ cd "$PUPPET_DIR" && librarian-puppet install --clean >/dev/null 2>&1
+ echo 'Finished running initial librarian-puppet'
+
+ touch /.protobox/librarian-puppet-installed
+else
+ echo 'Running update librarian-puppet'
+ cd "$PUPPET_DIR" && librarian-puppet update >/dev/null 2>&1
+ echo 'Finished running update librarian-puppet'
+fi
View
49 puppet/shell/os-detect.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+# Try and get debian operating system
+# id, codename, and release
+
+TYPE=$(echo "$1" | tr '[A-Z]' '[a-z]')
+OS=$(uname)
+ID="unknown"
+CODENAME="unknown"
+RELEASE="unknown"
+
+if [ "$OS" == "Linux" ]; then
+ # detect centos
+ grep "centos" /etc/issue -i -q
+ if [ $? = '0' ]; then
+ ID="centos"
+ RELEASE=$(cat /etc/redhat-release | grep -o 'release [0-9]' | cut -d " " -f2)
+ # could be debian or ubuntu
+ elif [ $(which lsb_release) ]; then
+ ID=$(lsb_release -i | cut -f2)
+ CODENAME=$(lsb_release -c | cut -f2)
+ RELEASE=$(lsb_release -r | cut -f2)
+ elif [ -f "/etc/lsb-release" ]; then
+ ID=$(cat /etc/lsb-release | grep DISTRIB_ID | cut -d "=" -f2)
+ CODENAME=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d "=" -f2)
+ RELEASE=$(cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f2)
+ elif [ -f "/etc/issue" ]; then
+ ID=$(head -1 /etc/issue | cut -d " " -f1)
+ if [ -f "/etc/debian_version" ]; then
+ RELEASE=$(</etc/debian_version)
+ else
+ RELEASE=$(head -1 /etc/issue | cut -d " " -f2)
+ fi
+ fi
+fi
+
+declare -A info
+
+info[id]=$(echo "$ID" | tr '[A-Z]' '[a-z]')
+info[codename]=$(echo "$CODENAME" | tr '[A-Z]' '[a-z]')
+info[release]=$(echo "$RELEASE" | tr '[A-Z]' '[a-z]')
+
+if [ "$TYPE" ] ; then
+ echo "${info[$TYPE]}"
+else
+ echo -e "ID\t${info[id]}"
+ echo -e "CODENAME\t${info[codename]}"
+ echo -e "RELEASE\t${info[release]}"
+fi
View
43 puppet/shell/update-puppet.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+OS=$(/bin/bash /vagrant/puppet/shell/os-detect.sh ID)
+RELEASE=$(/bin/bash /vagrant/puppet/shell/os-detect.sh RELEASE)
+CODENAME=$(/bin/bash /vagrant/puppet/shell/os-detect.sh CODENAME)
+
+if [[ ! -f /.protobox/update-puppet ]]; then
+ if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
+ echo "Downloading http://apt.puppetlabs.com/puppetlabs-release-${CODENAME}.deb"
+ wget --quiet --tries=5 --timeout=10 -O "/.protobox/puppetlabs-release-${CODENAME}.deb" "http://apt.puppetlabs.com/puppetlabs-release-${CODENAME}.deb"
+ echo "Finished downloading http://apt.puppetlabs.com/puppetlabs-release-${CODENAME}.deb"
+
+ dpkg -i "/.protobox/puppetlabs-release-${CODENAME}.deb" >/dev/null 2>&1
+
+ echo "Running update-puppet apt-get update"
+ apt-get update >/dev/null 2>&1
+ echo "Finished running update-puppet apt-get update"
+
+ echo "Updating Puppet to latest version"
+ apt-get -y install puppet >/dev/null 2>&1
+ PUPPET_VERSION=$(puppet help | grep 'Puppet v')
+ echo "Finished updating puppet to latest version: $PUPPET_VERSION"
+
+ touch /.protobox/update-puppet
+ echo "Created empty file /.protobox/update-puppet"
+ elif [ "$OS" == 'centos' ]; then
+ echo "Downloading http://yum.puppetlabs.com/el/${RELEASE}/products/x86_64/puppetlabs-release-6-7.noarch.rpm"
+ yum -y --nogpgcheck install "http://yum.puppetlabs.com/el/${RELEASE}/products/x86_64/puppetlabs-release-6-7.noarch.rpm" >/dev/null 2>&1
+ echo "Finished downloading http://yum.puppetlabs.com/el/${RELEASE}/products/x86_64/puppetlabs-release-6-7.noarch.rpm"
+
+ echo "Running update-puppet yum update"
+ yum -y update >/dev/null 2>&1
+ echo "Finished running update-puppet yum update"
+
+ echo "Installing/Updating Puppet to latest version"
+ yum -y install puppet >/dev/null 2>&1
+ PUPPET_VERSION=$(puppet help | grep 'Puppet v')
+ echo "Finished installing/updating puppet to latest version: $PUPPET_VERSION"
+
+ touch /.protobox/update-puppet
+ echo "Created empty file /.protobox/update-puppet"
+ fi
+fi
View
2 web/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore

0 comments on commit 6787118

Please sign in to comment.