├── .gitignore
├── .gitmodules
├── README.md
├── chef
├── cookbooks
│ ├── apache-sites
│ │ ├── README.md
│ │ ├── metadata.rb
│ │ ├── recipes
│ │ │ └── default.rb
│ │ └── templates
│ │ │ └── default
│ │ │ └── sites.conf.erb
│ ├── mysql-databases
│ │ ├── README.md
│ │ ├── metadata.rb
│ │ └── recipes
│ │ │ └── default.rb
│ └── r
│ │ ├── README.md
│ │ ├── attributes
│ │ └── default.rb
│ │ ├── metadata.json
│ │ ├── metadata.rb
│ │ ├── providers
│ │ ├── file.rb
│ │ └── package.rb
│ │ ├── recipes
│ │ ├── GEOquery.rb
│ │ └── default.rb
│ │ └── resources
│ │ └── package.rb
├── data_bags
│ ├── elasticsearch
│ │ └── users.json
│ └── sites
│ │ ├── default.json
│ │ └── legacy.json
└── scripts
│ └── chef-osx.sh
├── scripts
├── files
│ ├── .bash_profile
│ └── etc_profile
└── shell.sh
└── vagrant
├── Makefile
└── vagrantfiles
└── Vagrantfile
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "chef/cookbooks/apache2"]
2 | path = chef/cookbooks/apache2
3 | url = git@github.com:opscode-cookbooks/apache2.git
4 | [submodule "chef/cookbooks/apt"]
5 | path = chef/cookbooks/apt
6 | url = git@github.com:opscode-cookbooks/apt.git
7 | [submodule "chef/cookbooks/aws"]
8 | path = chef/cookbooks/aws
9 | url = git@github.com:opscode-cookbooks/aws.git
10 | [submodule "chef/cookbooks/database"]
11 | path = chef/cookbooks/database
12 | url = git@github.com:opscode-cookbooks/database.git
13 | [submodule "chef/cookbooks/dmg"]
14 | path = chef/cookbooks/dmg
15 | url = git@github.com:opscode-cookbooks/dmg.git
16 | [submodule "chef/cookbooks/git"]
17 | path = chef/cookbooks/git
18 | url = git@github.com:opscode-cookbooks/git.git
19 | [submodule "chef/cookbooks/java"]
20 | path = chef/cookbooks/java
21 | url = git@github.com:opscode-cookbooks/java.git
22 | [submodule "chef/cookbooks/mysql"]
23 | path = chef/cookbooks/mysql
24 | url = git@github.com:opscode-cookbooks/mysql.git
25 | [submodule "chef/cookbooks/openssl"]
26 | path = chef/cookbooks/openssl
27 | url = git@github.com:opscode-cookbooks/openssl.git
28 | [submodule "chef/cookbooks/php"]
29 | path = chef/cookbooks/php
30 | url = git@github.com:opscode-cookbooks/php.git
31 | [submodule "chef/cookbooks/users"]
32 | path = chef/cookbooks/users
33 | url = git@github.com:opscode-cookbooks/users.git
34 | [submodule "chef/cookbooks/yum"]
35 | path = chef/cookbooks/yum
36 | url = git@github.com:opscode-cookbooks/yum.git
37 | [submodule "chef/cookbooks/build-essential"]
38 | path = chef/cookbooks/build-essential
39 | url = git@github.com:opscode-cookbooks/build-essential.git
40 | [submodule "chef/cookbooks/chef-php-extra"]
41 | path = chef/cookbooks/chef-php-extra
42 | url = git@github.com:inviqa/chef-php-extra.git
43 | [submodule "chef/cookbooks/composer"]
44 | path = chef/cookbooks/composer
45 | url = git@github.com:zircote/chef-composer.git
46 | [submodule "chef/cookbooks/phpunit"]
47 | path = chef/cookbooks/phpunit
48 | url = git@github.com:escapestudios/chef-phpunit.git
49 | [submodule "chef/cookbooks/elasticsearch"]
50 | path = chef/cookbooks/elasticsearch
51 | url = git@github.com:elasticsearch/cookbook-elasticsearch.git
52 | [submodule "chef/cookbooks/ark"]
53 | path = chef/cookbooks/ark
54 | url = git@github.com:opscode-cookbooks/ark.git
55 | [submodule "chef/cookbooks/curl"]
56 | path = chef/cookbooks/curl
57 | url = git@github.com:phlipper/chef-curl.git
58 | [submodule "chef/cookbooks/supervisor"]
59 | path = chef/cookbooks/supervisor
60 | url = git@github.com:opscode-cookbooks/supervisor.git
61 | [submodule "chef/cookbooks/python"]
62 | path = chef/cookbooks/python
63 | url = git@github.com:opscode-cookbooks/python.git
64 | [submodule "chef/cookbooks/nodejs"]
65 | path = chef/cookbooks/nodejs
66 | url = git@github.com:mdxp/nodejs-cookbook.git
67 | [submodule "chef/cookbooks/memcached"]
68 | path = chef/cookbooks/memcached
69 | url = git@github.com:opscode-cookbooks/memcached.git
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vagrant / Chef Configurations v1.1
2 |
3 | Everything that one needs to create development environments with Vagrant and Chef.
4 |
5 | This repo is very much a work in progress. There are many things that can be improved. Annotations were made in comment form within the example Vagrantfile, regarding room for improvement. Issues and pull-requests are encouraged.
6 |
7 | ### Features Include
8 |
9 | - LAMP (PHP 5.4)
10 | - Git
11 | - Composer
12 | - PHPUnit
13 | - automatic MySQL database creation
14 | - automatic apache vhost creation
15 | - other cookbooks and ready for love (ElasticSearch)
16 |
17 | # Installation
18 |
19 | These instructions are merely one way to use these tools. I'm presenting them because I feel that they're both reasonable and simple.
20 |
21 | These are instructions for creating a development environment utilizing Vagrant for virtual-machine management and Chef for installing and configuring software.
22 |
23 | You would install this individually into each site repo. When working on a site, you'd bring up the server. When you're done, you suspend it. I repeat. Each individual site repo has its own virtual-machine that is brought up when you're working on that specific site, and then suspended when you're done.
24 |
25 | This should work on any Windows, OSX, or Linux box.
26 |
27 | ### First, install the applications.
28 |
29 | **(DO NOT INSTALL FROM PACKAGE MANAGER)** If you do install virtualbox, vagrant or chef from package managers then expect pain.
30 |
31 | - [Install VirtualBox](https://www.virtualbox.org/wiki/Downloads)
32 |
33 | - [install Vagrant](http://www.vagrantup.com/downloads.html)
34 |
35 | - [Install Chef Client](http://www.opscode.com/chef/install/)
36 |
37 | ### Now, set up your project.
38 |
39 | 1. Add this repository to yours.
40 |
41 | ```
42 | cd mysite
43 |
44 | git submodule add git@github.com:ShawnMcCool/vagrant-chef.git
45 | ```
46 |
47 |
48 | 2. Update the submodules within the submodule. (inception)
49 |
50 | ```
51 | git submodule update --init --recursive
52 | ```
53 |
54 | 3. Copy an example Vagrantfile to your project's root.
55 |
56 | ```
57 | cp vagrant-chef/vagrant/vagrantfiles/Vagrantfile .
58 | ```
59 |
60 | 4. Read the Vagrant file and modify where appropriate for your project.
61 |
62 | 5. Add this entry to hosts file
63 |
64 | ```
65 | 10.10.10.10 app.local
66 | ```
67 |
68 | # Workflow
69 |
70 | ### Start the Application
71 |
72 | $ vagrant up
73 |
74 | Wait until Vagrant / Chef are done. Then, in your browser hit http://app.local.
75 |
76 | ### Stop the Application
77 |
78 | You have the choice of either... supending the application (takes a small bit more disk space). **Recommended**
79 |
80 | $ vagrant suspend
81 |
82 | or.. you can halt the box. (saves like 200meg?) But, because next time you start it up again it'll take a long time.
83 |
84 | $ vagrant halt
85 |
86 | ### When making changes to the environment...
87 |
88 | If configurations change you can simply run:
89 |
90 | $ vagrant reload
91 |
92 | It will then apply your changes to the Vagrantfile or cookbooks.
93 |
94 | ### Easing the pain
95 |
96 | Ok, it's not really that painful in exchange for what you get from it. I add these aliases to my shell script's initialization file for ease. You might like them, too.
97 |
98 | alias vl="VBoxManage list runningvms"
99 | alias vu="vagrant up"
100 | alias vd="vagrant suspend"
101 | alias vr="vagrant reload"
102 | alias vs="vagrant ssh"
103 | alias ga="git add ."
104 | alias gc="git commit -a"
105 | alias gp="git push"
106 |
107 | ### Troubleshooting
108 |
109 | There is a known Mac issue with VirtualBox crashing your VMs. [Here are more details and the solution.](https://www.virtualbox.org/ticket/11649)
110 |
111 | ### How you can help!
112 |
113 | I've made many annotations of issues in the Vagrantfile example, each could use a solution.
114 |
115 | Trying to install this on your system and reporting back any issues that you've had with instructions listed would be a huge help.
116 |
117 | Know a bit about Vagrant / Chef and want to complain that something could be done better? Please open an issue!
118 |
--------------------------------------------------------------------------------
/chef/cookbooks/apache-sites/README.md:
--------------------------------------------------------------------------------
1 | Description
2 | ===========
3 | Manages apache site configurations
4 |
5 | Requirements
6 | ============
7 |
8 | Attributes
9 | ==========
10 |
11 | Usage
12 | =====
13 |
14 |
--------------------------------------------------------------------------------
/chef/cookbooks/apache-sites/metadata.rb:
--------------------------------------------------------------------------------
1 | maintainer "Shawn McCool"
2 | maintainer_email "shawn@heybigname.com"
3 | license "All rights reserved"
4 | description "Installs/Configures apache site configurations"
5 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6 | version "0.0.1"
--------------------------------------------------------------------------------
/chef/cookbooks/apache-sites/recipes/default.rb:
--------------------------------------------------------------------------------
1 | # Install packages
2 | # %w{ debconf vim screen mc subversion curl tmux make g++ libsqlite3-dev }.each do |a_package|
3 | # package a_package
4 | # end
5 |
6 | # Generate selfsigned ssl
7 | execute "make-ssl-cert" do
8 | command "make-ssl-cert generate-default-snakeoil --force-overwrite"
9 | ignore_failure true
10 | action :nothing
11 | end
12 |
13 | # Configure sites
14 | sites = node["sites"] ||= []
15 |
16 | sites.each do |name|
17 | site = data_bag_item("sites", name)
18 |
19 | puts "Installing site #{site["id"]}"
20 |
21 | # Add site to apache config
22 | web_app site["host"] do
23 | template "sites.conf.erb"
24 | server_name site["host"]
25 | server_aliases site["aliases"]
26 | docroot site["docroot"]
27 | end
28 |
29 | # Add site info in /etc/hosts
30 | bash "hosts" do
31 | aliases = site["aliases"].join(' ') if site["aliases"].kind_of?(Array)
32 | code "echo 127.0.0.1 #{site["host"]} #{aliases} >> /etc/hosts"
33 | end
34 | end
35 |
36 | # Disable default site
37 | apache_site "default" do
38 | enable false
39 | end
--------------------------------------------------------------------------------
/chef/cookbooks/apache-sites/templates/default/sites.conf.erb:
--------------------------------------------------------------------------------
1 |
2 | ServerName <%= @params[:server_name] %>
3 | DocumentRoot <%= @params[:docroot] %>
4 | RewriteEngine On
5 |
6 | <% if @params[:server_aliases].kind_of?(Array) %>
7 | ServerAlias <% @params[:server_aliases].each do |a| %><%= "#{a}" %> <% end %>
8 | <% end %>
9 |
10 | >
11 | Options FollowSymLinks
12 | AllowOverride All
13 | Order allow,deny
14 | Allow from all
15 |
16 |
17 |
18 | Options FollowSymLinks
19 | AllowOverride None
20 |
21 |
22 |
23 | SetHandler server-status
24 |
25 | Order Allow,Deny
26 | Allow from all
27 |
28 |
29 | LogLevel info
30 | ErrorLog <%= node[:apache][:log_dir] %>/<%= @params[:name] %>-error.log
31 | CustomLog <%= node[:apache][:log_dir] %>/<%= @params[:name] %>-access.log combined
32 |
33 | RewriteEngine On
34 | RewriteLog <%= node[:apache][:log_dir] %>/<%= @application_name %>-rewrite.log
35 | # level 0 => Do not log rewrite
36 | RewriteLogLevel 0
37 |
38 |
39 |
40 | ServerName <%= @params[:server_name] %>
41 | DocumentRoot <%= @params[:docroot] %>
42 | RewriteEngine On
43 |
44 | <% if @params[:server_aliases].kind_of?(Array) %>
45 | ServerAlias <% @params[:server_aliases].each do |a| %><%= "#{a}" %> <% end %>
46 | <% end %>
47 |
48 | >
49 | Options FollowSymLinks
50 | AllowOverride All
51 | Order allow,deny
52 | Allow from all
53 |
54 |
55 |
56 | Options FollowSymLinks
57 | AllowOverride None
58 |
59 |
60 |
61 | SetHandler server-status
62 |
63 | Order Allow,Deny
64 | Allow from all
65 |
66 |
67 | LogLevel info
68 | ErrorLog <%= node[:apache][:log_dir] %>/<%= @params[:name] %>-error.log
69 | CustomLog <%= node[:apache][:log_dir] %>/<%= @params[:name] %>-access.log combined
70 |
71 | RewriteEngine On
72 | RewriteLog <%= node[:apache][:log_dir] %>/<%= @application_name %>-rewrite.log
73 | # level 0 => Do not log rewrite
74 | RewriteLogLevel 0
75 |
76 | SSLEngine on
77 | SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
78 | SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
79 |
80 |
--------------------------------------------------------------------------------
/chef/cookbooks/mysql-databases/README.md:
--------------------------------------------------------------------------------
1 | Description
2 | ===========
3 | Manages basic MySQL database creation.
4 |
5 | Requirements
6 | ============
7 |
8 | Attributes
9 | ==========
10 |
11 | Usage
12 | =====
13 |
14 |
--------------------------------------------------------------------------------
/chef/cookbooks/mysql-databases/metadata.rb:
--------------------------------------------------------------------------------
1 | maintainer "Shawn McCool"
2 | maintainer_email "shawn@heybigname.com"
3 | license "All rights reserved"
4 | description "Manages basic MySQL database creation"
5 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6 | version "0.0.1"
--------------------------------------------------------------------------------
/chef/cookbooks/mysql-databases/recipes/default.rb:
--------------------------------------------------------------------------------
1 | mysql_connection_info = {:host => "localhost",
2 | :username => 'root',
3 | :password => node['mysql']['server_root_password']}
4 |
5 | # Set up client site databases and users
6 | if defined? node['databases'] then
7 |
8 | if defined? node['databases']['create'] then
9 | if node['databases']['create'].kind_of?(Array) then
10 |
11 | node['databases']['create'].each do |db_name|
12 |
13 | mysql_database db_name do
14 | connection mysql_connection_info
15 | action :create
16 | end
17 |
18 | # setup users
19 | if defined? node['databases']['grant'] then
20 | if node['databases']['grant'].kind_of?(Array) then
21 | node['databases']['grant'].each do |user|
22 | mysql_database_user user["user"] do
23 | connection mysql_connection_info
24 | password user["password"]
25 | host user["host"]
26 | action :grant
27 | end
28 | end
29 | end
30 | end
31 | end
32 |
33 | end
34 | end
35 | end
36 |
37 | # add root - password
38 | mysql_database_user 'root' do
39 | connection mysql_connection_info
40 | password 'password'
41 | host '%'
42 | action :grant
43 | end
--------------------------------------------------------------------------------
/chef/cookbooks/r/README.md:
--------------------------------------------------------------------------------
1 | Description
2 | ===========
3 |
4 | Requirements
5 | ============
6 |
7 | Attributes
8 | ==========
9 |
10 | Usage
11 | =====
12 |
13 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/attributes/default.rb:
--------------------------------------------------------------------------------
1 | default[:R][:CRAN][:default] = "cran.r-project.org"
2 | default[:R][:packages] = Array.new
3 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "r",
3 | "description": "Installs/Configures R",
4 | "long_description": "Description\n===========\n\nRequirements\n============\n\nAttributes\n==========\n\nUsage\n=====\n\n",
5 | "maintainer": "Michael Linderman",
6 | "maintainer_email": "michael.linderman@mssm.edu",
7 | "license": "Apache 2.0",
8 | "platforms": {
9 | "ubuntu": ">= 0.0.0",
10 | "centos": ">= 0.0.0",
11 | "redhat": ">= 0.0.0",
12 | "fedora": ">= 0.0.0"
13 | },
14 | "dependencies": {
15 | "apt": ">= 0.0.0",
16 | "build-essential": ">= 0.0.0"
17 | },
18 | "recommendations": {
19 | },
20 | "suggestions": {
21 | },
22 | "conflicting": {
23 | },
24 | "providing": {
25 | },
26 | "replacing": {
27 | },
28 | "attributes": {
29 | },
30 | "groupings": {
31 | },
32 | "recipes": {
33 | "r": "Install R base packages"
34 | },
35 | "version": "0.0.1"
36 | }
--------------------------------------------------------------------------------
/chef/cookbooks/r/metadata.rb:
--------------------------------------------------------------------------------
1 | maintainer "Michael Linderman"
2 | maintainer_email "michael.linderman@mssm.edu"
3 | license "Apache 2.0"
4 | description "Installs/Configures R"
5 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6 | version "0.0.1"
7 |
8 | recipe "r", "Install R base packages"
9 |
10 | depends "apt"
11 | depends "build-essential"
12 |
13 | %w{ ubuntu centos redhat fedora }.each do |os|
14 | supports os
15 | end
16 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/providers/file.rb:
--------------------------------------------------------------------------------
1 | action :install do
2 |
3 | package_name = ::File.basename(new_resource.package_name).gsub(/(.+)_[0-9.]*\.tar\.gz\z/,'\1')
4 | Chef::Log.info "Installing filesystem package #{package_name} from #{new_resource.package_name}"
5 | bash "R_file_package_install" do
6 | user "root"
7 | code <<-EOH
8 | R_CMD=`which R 2> /dev/null`
9 | if [ $? -ne 0 ]; then
10 | R_CMD=/usr/local/bin/R
11 | fi
12 | set -e
13 | cat <<-EOF | $R_CMD --no-save --no-restore --file=-
14 | if (!("#{package_name}" %in% installed.packages())) {
15 | install.packages("#{new_resource.package_name}", repos=NULL)
16 | stopifnot("#{package_name}" %in% installed.packages())
17 | }
18 | EOF
19 | EOH
20 | end
21 |
22 | end
23 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/providers/package.rb:
--------------------------------------------------------------------------------
1 | action :install do
2 |
3 | Chef::Log.info "Installing CRAN/BioC package #{new_resource.package_name}"
4 | bash "R_CRAN_BioC_package_install" do
5 | user "root"
6 | code <<-EOH
7 | R_CMD=`which R 2> /dev/null`
8 | if [ $? -ne 0 ]; then
9 | R_CMD=/usr/local/bin/R
10 | fi
11 | set -e
12 | cat <<-EOF | $R_CMD --no-save --no-restore --file=-
13 | if (!("#{new_resource.package_name}" %in% installed.packages())) {
14 | source("http://bioconductor.org/biocLite.R")
15 | biocLite("#{new_resource.package_name}")
16 | stopifnot("#{new_resource.package_name}" %in% installed.packages())
17 | }
18 | EOF
19 | EOH
20 | end
21 |
22 | end
23 |
24 | action :remove do
25 |
26 | Chef::Log.info "Remove R package #{new_resource.package_name}"
27 | bash "R_package_remove" do
28 | user "root"
29 | code <<-EOH
30 | R_CMD=`which R 2> /dev/null`
31 | if [ $? -ne 0 ]; then
32 | R_CMD=/usr/local/bin/R
33 | fi
34 | set -e
35 | cat <<-EOF | $R_CMD --no-save --no-restore --file=-
36 | package <- installed.packages()["#{new_resource.package_name}",]
37 | if (!is.na(package)) {
38 | remove.packages("#{new_resource.package_name}", package['LibPath'])
39 | stopifnot(!("#{new_resource.package_name}" %in% installed.packages()))
40 | }
41 | EOF
42 | EOH
43 | end
44 |
45 | end
46 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/recipes/GEOquery.rb:
--------------------------------------------------------------------------------
1 | case node['platform']
2 | when "ubuntu", "debian"
3 |
4 | package "libcurl4-openssl-dev" do
5 | action :install
6 | end
7 |
8 | end
9 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: r
3 | # Recipe:: default
4 | #
5 | # Copyright 2012, Michael Linderman
6 | #
7 |
8 | include_recipe "build-essential"
9 |
10 | case node['platform']
11 | when "ubuntu"
12 | include_recipe "apt"
13 |
14 | # Key obtained from CRAN Ubuntu README
15 | execute "gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 && gpg -a --export E084DAB9 | sudo apt-key add -" do
16 | not_if "apt-key list | grep 'E084DAB9'"
17 | notifies :run, resources(:execute => "apt-get update"), :immediately
18 | end
19 |
20 | # apt_repository "CRAN" do
21 | # uri "http://#{node[:R][:CRAN][:default]}/bin/linux/ubuntu"
22 | # distribution "#{node[:lsb][:codename]}/"
23 | # action :add
24 | # end
25 |
26 | %w{ r-base r-base-dev }.each do |p|
27 | package p do
28 | action :install
29 | end
30 | end
31 |
32 | when "debian"
33 | include_recipe "apt"
34 |
35 | # Key obtained from CRAN Ubuntu README
36 | execute "gpg --keyserver keyserver.ubuntu.com --recv-key 381BA480 && gpg -a --export 381BA480 | sudo apt-key add -" do
37 | not_if "apt-key list | grep '381BA480'"
38 | notifies :run, resources(:execute => "apt-get update"), :immediately
39 | end
40 |
41 | apt_repository "CRAN" do
42 | uri "http://#{node[:R][:CRAN][:default]}/bin/linux/debian"
43 | distribution "#{node[:lsb][:codename]}-cran/"
44 | action :add
45 | end
46 |
47 | # Need to use specific repository to get backported R...
48 | execute "install R" do
49 | command "apt-get -t #{node[:lsb][:codename]}-cran install --yes --force-yes r-base r-base-dev"
50 | end
51 |
52 | execute "install GMT package" do
53 | command "sudo /usr/bin/R -e \"install.packages('gmt')\""
54 | end
55 |
56 | when "centos","redhat","fedora"
57 | remote_file "/tmp/R-latest.tar.gz" do
58 | source "http://#{node[:R][:CRAN][:default]}/src/base/R-latest.tar.gz"
59 | backup false
60 | end
61 |
62 | # Also installs X, X-devel and fortran compiler (mandatory packages from
63 | # 'X Window System' and 'X Software Development')
64 |
65 | %w{ gcc-gfortran tcl tk tcl-devel tk-devel }.each do |p|
66 | package p do
67 | action :install
68 | end
69 | end
70 |
71 | bash "install_R_from_source" do
72 | user "root"
73 | code <<-EOH
74 | set -e
75 | yum -y groupinstall 'X Window System'
76 | yum -y groupinstall 'X Software Development'
77 | cd /tmp
78 | tar -xzf R-latest.tar.gz
79 | BASE=`tar tzf R-latest.tar.gz | sed -e 's@/.*@@' | uniq`
80 | cd $BASE
81 | ./configure
82 | make && make install
83 | rm -rf /tmp/$BASE /tmp/R-latest.tar.gz
84 | EOH
85 | not_if do
86 | File.exists? "/usr/local/bin/R"
87 | end
88 | end
89 | end
90 |
91 | # Setup a default CRAN repository
92 | # It would be better to make this a template, but we don't know the
93 | # target directory until convergence time and so have to use this approach
94 | bash "Set_R_site_profile" do
95 | user "root"
96 | code <<-EOH
97 | cat <<-EOF > $(R RHOME)/etc/Rprofile.site
98 | ## Rprofile.site generated by Chef for #{node[:fqdn]}
99 | local({
100 | r <- getOption("repos")
101 | r["CRAN"] <- "http://#{node[:R][:CRAN][:default]}";
102 | options(repos = r)
103 | })
104 | EOF
105 | EOH
106 | end
107 |
108 | node[:R][:packages].each do |p|
109 |
110 | include_recipe "r::#{p}" rescue ArgumentError
111 |
112 | r_package p do
113 | action :install
114 | end
115 | end
116 |
--------------------------------------------------------------------------------
/chef/cookbooks/r/resources/package.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: r
3 | # Resource:: package
4 | #
5 | # Copyright 2012, Michael Linderman
6 | #
7 |
8 | actions :install, :remove
9 |
10 | attribute :package_name, :kind_of => String, :name_attribute => true
11 |
--------------------------------------------------------------------------------
/chef/data_bags/elasticsearch/users.json:
--------------------------------------------------------------------------------
1 | {
2 | "id" : "users",
3 | "_default" : {
4 | "users" : [
5 | { "username" : "username", "password" : "password" }
6 | ]
7 | }
8 | }
--------------------------------------------------------------------------------
/chef/data_bags/sites/default.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "default",
3 | "host": "app.local",
4 | "aliases": [
5 | "app.dev",
6 | "local.dev"
7 | ],
8 | "docroot": "/vagrant/public"
9 | }
--------------------------------------------------------------------------------
/chef/data_bags/sites/legacy.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "legacy",
3 | "host": "app.local",
4 | "aliases": [
5 | "app.dev",
6 | "local.dev"
7 | ],
8 | "docroot": "/vagrant"
9 | }
--------------------------------------------------------------------------------
/chef/scripts/chef-osx.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # This is the current stable release to default to, with Omnibus patch level (e.g. 10.12.0-1)
4 | # Note that the chef template downloads 'x.y.z' not 'x.y.z-r' which should be a duplicate of the latest -r
5 | use_shell=0
6 |
7 | prerelease="false"
8 |
9 | # Check whether a command exists - returns 0 if it does, 1 if it does not
10 | exists() {
11 | if command -v $1 >/dev/null 2>&1
12 | then
13 | return 0
14 | else
15 | return 1
16 | fi
17 | }
18 |
19 | # Set the filename for a deb, based on version and machine
20 | deb_filename() {
21 | filetype="deb"
22 | if [ "$machine" = "x86_64" ];
23 | then
24 | filename="chef_${version}_amd64.deb"
25 | else
26 | filename="chef_${version}_i386.deb"
27 | fi
28 | }
29 |
30 | # Set the filename for an rpm, based on version and machine
31 | rpm_filename() {
32 | filetype="rpm"
33 | filename="chef-${version}.${machine}.rpm"
34 | }
35 |
36 | # Set the filename for a Solaris SVR4 package, based on version and machine
37 | svr4_filename() {
38 | PATH=/usr/sfw/bin:$PATH
39 | filetype="solaris"
40 | filename="chef-${version}.${machine}.solaris"
41 | }
42 |
43 | # Set the filename for the sh archive
44 | shell_filename() {
45 | filetype="sh"
46 | filename="chef-${version}-${platform}-${platform_version}-${machine}.sh"
47 | }
48 |
49 | report_bug() {
50 | echo "Please file a bug report at http://tickets.opscode.com"
51 | echo "Project: Chef"
52 | echo "Component: Packages"
53 | echo "Label: Omnibus"
54 | echo "Version: $version"
55 | echo " "
56 | echo "Please detail your operating system type, version and any other relevant details"
57 | }
58 |
59 | # Get command line arguments
60 | while getopts spv: opt
61 | do
62 | case "$opt" in
63 | v) version="$OPTARG";;
64 | s) use_shell=1;;
65 | p) prerelease="true";;
66 | \?) # unknown flag
67 | echo >&2 \
68 | "usage: $0 [-s] [-v version]"
69 | exit 1;;
70 | esac
71 | done
72 | shift `expr $OPTIND - 1`
73 |
74 | machine=$(printf `uname -m`)
75 |
76 | # Retrieve Platform and Platform Version
77 | if [ -f "/etc/lsb-release" ] && grep -q DISTRIB_ID /etc/lsb-release;
78 | then
79 | platform=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]')
80 | platform_version=$(grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2)
81 | elif [ -f "/etc/debian_version" ];
82 | then
83 | platform="debian"
84 | platform_version=$(printf `cat /etc/debian_version`)
85 | elif [ -f "/etc/redhat-release" ];
86 | then
87 | platform=$(sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]')
88 | platform_version=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release)
89 |
90 | # If /etc/redhat-release exists, we act like RHEL by default
91 | if [ "$platform" = "fedora" ];
92 | then
93 | # Change platform version for use below.
94 | platform_version="6.0"
95 | fi
96 | platform="el"
97 | elif [ -f "/etc/system-release" ];
98 | then
99 | platform=$(sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]')
100 | platform_version=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]')
101 | # amazon is built off of fedora, so act like RHEL
102 | if [ "$platform" = "amazon linux ami" ];
103 | then
104 | platform="el"
105 | platform_version="6.0"
106 | fi
107 | # Apple OS X
108 | elif [ -f "/usr/bin/sw_vers" ];
109 | then
110 | platform="mac_os_x"
111 | # Matching the tab-space with sed is error-prone
112 | platform_version=$(sw_vers | awk '/^ProductVersion:/ { print $2 }')
113 |
114 | major_version=$(echo $platform_version | cut -d. -f1,2)
115 | case $major_version in
116 | "10.6") platform_version="10.6" ;;
117 | "10.7") platform_version="10.7" ;;
118 | "10.9") platform_version="10.7" ;;
119 | *) echo "No builds for platform: $major_version"
120 | report_bug
121 | exit 1
122 | ;;
123 | esac
124 |
125 | # x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
126 | x86_64=$(sysctl -n hw.optional.x86_64)
127 | if [ $x86_64 -eq 1 ]; then
128 | machine="x86_64"
129 | fi
130 | elif [ -f "/etc/release" ];
131 | then
132 | platform="solaris2"
133 | machine=$(/usr/bin/uname -p)
134 | platform_version=$(/usr/bin/uname -r)
135 | elif [ -f "/etc/SuSE-release" ];
136 | then
137 | if grep -q 'Enterprise' /etc/SuSE-release;
138 | then
139 | platform="sles"
140 | platform_version=$(awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release)
141 | else
142 | platform="suse"
143 | platform_version=$(awk '/^VERSION =/ { print $3 }' /etc/SuSE-release)
144 | fi
145 | elif [ "$(uname -s)" == "FreeBSD" ]; then
146 | platform="freebsd"
147 | platform_version=$(uname -r | sed 's/-.*//')
148 | fi
149 |
150 | if [ "x$platform" = "x" ];
151 | then
152 | echo "Unable to determine platform version!"
153 | report_bug
154 | exit 1
155 | fi
156 |
157 | # Mangle $platform_version to pull the correct build
158 | # for various platforms
159 | major_version=$(echo $platform_version | cut -d. -f1)
160 | case $platform in
161 | "el")
162 | case $major_version in
163 | "5") platform_version="5" ;;
164 | "6") platform_version="6" ;;
165 | esac
166 | ;;
167 | "debian")
168 | case $major_version in
169 | "5") platform_version="6";;
170 | "6") platform_version="6";;
171 | "7") platform_version="6";;
172 | esac
173 | ;;
174 | "freebsd")
175 | case $major_version in
176 | "8") platform_version="8" ;;
177 | "9") platform_version="9" ;;
178 | esac
179 | ;;
180 | esac
181 |
182 | if [ "x$platform_version" = "x" ];
183 | then
184 | echo "Unable to determine platform version!"
185 | report_bug
186 | exit 1
187 | fi
188 |
189 | if [ $use_shell = 1 ];
190 | then
191 | shell_filename
192 | else
193 | case $platform in
194 | "ubuntu") deb_filename ;;
195 | "debian") deb_filename ;;
196 | "el") rpm_filename ;;
197 | "suse") rpm_filename ;;
198 | "sles") rpm_filename ;;
199 | "fedora") rpm_filename ;;
200 | "solaris2") svr4_filename ;;
201 | *) shell_filename ;;
202 | esac
203 | fi
204 |
205 | echo "Downloading Chef $version for ${platform}..."
206 |
207 | url="http://www.opscode.com/chef/download?v=${version}&prerelease=${prerelease}&p=${platform}&pv=${platform_version}&m=${machine}"
208 | tmp_dir=$(mktemp -d -t tmp.XXXXXXXX || echo "/tmp")
209 |
210 | if exists wget;
211 | then
212 | downloader="wget"
213 | wget -O "$tmp_dir/$filename" "$url" 2>/tmp/stderr
214 | elif exists curl;
215 | then
216 | downloader="curl"
217 | curl -L "$url" > "$tmp_dir/$filename"
218 | else
219 | echo "Cannot find wget or curl - cannot install Chef!"
220 | exit 5
221 | fi
222 |
223 | # Check to see if we got a 404 or an empty file
224 |
225 | unable_to_retrieve_package() {
226 | echo "Unable to retrieve a valid package!"
227 | report_bug
228 | echo "URL: $url"
229 | exit 1
230 | }
231 |
232 | if [ "$downloader" = "curl" ]
233 | then
234 | #do curl stuff
235 | grep "The specified key does not exist." "$tmp_dir/$filename" 2>&1 >/dev/null
236 | if [ $? -eq 0 ] || [ ! -s "$tmp_dir/$filename" ]
237 | then
238 | unable_to_retrieve_package
239 | fi
240 | elif [ "$downloader" = "wget" ]
241 | then
242 | #do wget stuff
243 | grep "ERROR 404" /tmp/stderr 2>&1 >/dev/null
244 | if [ $? -eq 0 ] || [ ! -s "$tmp_dir/$filename" ]
245 | then
246 | unable_to_retrieve_package
247 | fi
248 | fi
249 |
250 | echo "Installing Chef $version"
251 | case "$filetype" in
252 | "rpm") rpm -Uvh "$tmp_dir/$filename" ;;
253 | "deb") dpkg -i "$tmp_dir/$filename" ;;
254 | "solaris") echo "conflict=nocheck" > /tmp/nocheck
255 | echo "action=nocheck" >> /tmp/nocheck
256 | pkgadd -n -d "$tmp_dir/$filename" -a /tmp/nocheck chef
257 | ;;
258 | "sh" ) bash "$tmp_dir/$filename" ;;
259 | esac
260 |
261 | if [ "$tmp_dir" != "/tmp" ];
262 | then
263 | rm -r "$tmp_dir"
264 | fi
265 |
266 | if [ $? -ne 0 ];
267 | then
268 | echo "Installation failed"
269 | report_bug
270 | exit 1
271 | fi
272 |
--------------------------------------------------------------------------------
/scripts/files/.bash_profile:
--------------------------------------------------------------------------------
1 | cd /vagrant
2 |
--------------------------------------------------------------------------------
/scripts/files/etc_profile:
--------------------------------------------------------------------------------
1 | umask 027
2 | alias t="vendor/bin/codecept run"
3 | alias ltr="ls -ltr"
4 |
--------------------------------------------------------------------------------
/scripts/shell.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ -n /home/vagrant/.bash_profile ]; then
4 | cp /vagrant/vagrant-chef/scripts/files/.bash_profile /home/vagrant
5 | cat /vagrant/vagrant-chef/scripts/files/etc_profile >> /etc/profile
6 | fi
7 |
--------------------------------------------------------------------------------
/vagrant/Makefile:
--------------------------------------------------------------------------------
1 | # Set any variables here - override them by using VARIABLE="value" in the command line
2 | VAGRANTENV = --env=vagrant
3 | VAGRANTSSH = vagrant ssh -c
4 | ARTISAN = php artisan
5 | DBNAME = default_database
6 |
7 | # Useage information
8 | # Use: make all
9 | all:
10 | @echo "A helpful Makefile for common vagrant tasks."
11 |
12 | @echo "\nVagrant"
13 | @echo " make up - Start the vagrant virtual machine"
14 | @echo " make clean - Removes Laravel files in the cache, session and view storage folders."
15 | @echo " make vagrant - Sets up a vagrant box for development. This will launch the vagrant box and apply any migrations to it. Also updates composer modules, submodules and bundle assets."
16 | @echo " make vagrant-clean - Halt the VM, destroy the box, re-download and set up the box again."
17 |
18 | @echo "\nComposer"
19 | @echo " make composer-download - Download and install composer."
20 | @echo " make composer-install - Perform a `php composer.phar install`"
21 | @echo " make composer-install-dev - Perform a `php composer.phar install --dev`"
22 |
23 | @echo "\nMigrations and Database"
24 | @echo " make createdb - Create a database based on the DBNAME variable"
25 | @echo " make migrate-install - Install the laravel migration table."
26 | @echo " make migrate - Launches a migration command on your vagrantbox. Called automatically with 'make vagrant'"
27 | @echo " make rollback - Launches a rollback command on your vagrantbox."
28 |
29 | @echo "\nMaintenance"
30 | @echo " make submodules - Update any submodules in the project"
31 | @echo " make publish - Publish any bundle assets into /public/bundles"
32 | @echo " make task - Run a task on the vagrant box"
33 | @echo " make test - Run all unit tests on the vagrant box"
34 |
35 | # Give help
36 | # Use: make help
37 | help: all
38 |
39 | # Run almost everything from the ground up
40 | # Update submodules, bring vagrant up, install composer, create a database, install the laravel migration table, migrate and publish assets
41 | # Use: make vagrant
42 | vagrant: submodules up composer-install-dev createdb migrate-install migrate publish
43 |
44 | # Alias to migrate-install and migrate
45 | # Use: make vagrant-install-and-migrate
46 | vagrant-install-and-migrate: vagrant-migrate-install vagrant-migrate
47 |
48 | # Clean out laravel's cache, session and storage directories
49 | # make clean
50 | clean:
51 | rm storage/cache/*
52 | rm storage/sessions/*
53 | rm storage/views/*
54 |
55 | # Update/sync submodules
56 | # Use: make submodules
57 | submodules:
58 | git submodule update --init
59 |
60 | # Publish assets from bundles
61 | # Use: make publish
62 | publish:
63 | $(ARTISAN) bundle:publish
64 |
65 | # Install a migration table
66 | # Use: make migrateinstall
67 | migrate-install:
68 | $(ARTISAN) migrate:install
69 |
70 | # Bring vagrant up
71 | # Use: make up
72 | up:
73 | vagrant up
74 |
75 | # Clean vagrant up and re-download/re-up it
76 | # Use: make vagrant-clean
77 | vagrant-clean:
78 | vagrant destroy && vagrant box remove && make vagrant
79 |
80 | # Download an install composer in this project
81 | # Use: make composer-download
82 | composer-download:
83 | $(VAGRANTSSH) "cd /vagrant && curl -sS https://getcomposer.org/installer | php"
84 |
85 | # Perform a composer install
86 | # Use: make composer-install
87 | composer-install:
88 | $(VAGRANTSSH) "cd /vagrant && php composer.phar install"
89 |
90 | # Perform a composer install with --dev
91 | # Use: make composer-install-dev
92 | composer-install-dev:
93 | $(VAGRANTSSH) "cd /vagrant && php composer.phar install --dev"
94 |
95 |
96 | # Create a database
97 | # Use: make createdb DBNAME="mydbname"
98 | createdb:
99 | $(VAGRANTSSH) "mysql --user=root --password=password -e 'create database $(DBNAME)'"
100 |
101 | # Run migrations
102 | # Use: make migrate
103 | migrate:
104 | $(VAGRANTSSH) "php /vagrant/artisan migrate $(VAGRANTENV)"
105 |
106 | # Rollback a migration
107 | # Use: make rollback
108 | rollback:
109 | $(VAGRANTSSH) "php /vagrant/artisan migrate:rollback $(VAGRANTENV)"
110 |
111 | # Run a specific task
112 | # Use: make task task="mytask"
113 | task:
114 | $(VAGRANTSSH) "php /vagrant/artisan $(task) $(VAGRANTENV)"
115 |
116 | # Run unit tests through phpunit install via composer
117 | # Use: make test
118 | test:
119 | $(VAGRANTSSH) "PATH=/vagrant/vendor/phpunit/phpunit/composer/bin:$$PATH && php /vagrant/artisan test"
120 |
121 |
--------------------------------------------------------------------------------
/vagrant/vagrantfiles/Vagrantfile:
--------------------------------------------------------------------------------
1 | Vagrant::configure('2') do |config|
2 | config.vm.box = 'bn-quantal64-lamp-2.4'
3 | config.vm.box_url = 'http://big-name.s3.amazonaws.com/bn-quantal64-lamp-2.4.box'
4 |
5 | config.vm.provider "virtualbox" do |v|
6 | v.customize ["modifyvm", :id, "--memory", "768"]
7 | end
8 |
9 | config.vm.network "private_network", ip: "10.10.10.10"
10 |
11 | config.vm.synced_folder ".", "/vagrant", :mount_options => [ "dmode=777", "fmode=777" ]
12 |
13 | config.vm.provision :chef_solo do |chef|
14 | chef.cookbooks_path = "vagrant-chef/chef/cookbooks"
15 | chef.data_bags_path = "vagrant-chef/chef/data_bags"
16 |
17 | chef.add_recipe "apt"
18 | chef.add_recipe "git"
19 | chef.add_recipe "apache2"
20 | chef.add_recipe "apache2::mod_rewrite"
21 | chef.add_recipe "apache2::mod_ssl"
22 | chef.add_recipe "apache2::mod_php5"
23 | chef.add_recipe "mysql::server"
24 | chef.add_recipe "php"
25 | chef.add_recipe "php::module_mysql"
26 | chef.add_recipe "php::module_apc"
27 | chef.add_recipe "php::module_sqlite3"
28 | chef.add_recipe "php::module_gd"
29 | chef.add_recipe "php::module_curl"
30 | chef.add_recipe "chef-php-extra"
31 | chef.add_recipe "database::mysql"
32 | chef.add_recipe "apache-sites"
33 | chef.add_recipe "mysql-databases"
34 | chef.add_recipe "memcached"
35 |
36 | chef.json.merge!({
37 | "mysql" => {
38 | "server_root_password" => "password",
39 | "server_debian_password" => "password",
40 | "server_repl_password" => "password",
41 | "bind_address" => "0.0.0.0"
42 | },
43 | "databases" => {
44 | "create" => [
45 | "dbnamehere", "optionaladditionalnameshere"
46 | ]
47 | },
48 | "sites" => ["default"]
49 | })
50 |
51 | end
52 | end
53 |
--------------------------------------------------------------------------------