megalodon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/Gemfile +4 -0
  2. data/README.md +80 -0
  3. data/bin/megalodon +68 -0
  4. data/config/rake.rb +60 -0
  5. data/config/run_list.json +5 -0
  6. data/config/run_vhosts.json +5 -0
  7. data/config/solo.rb +20 -0
  8. data/cookbooks/dnsmasq/recipies/default.rb +28 -0
  9. data/cookbooks/elasticsearch/recipies/default.rb +23 -0
  10. data/cookbooks/erlang/README.rdoc +8 -0
  11. data/cookbooks/erlang/metadata.rb +6 -0
  12. data/cookbooks/erlang/recipes/default.rb +8 -0
  13. data/cookbooks/git/README.rdoc +8 -0
  14. data/cookbooks/git/metadata.rb +6 -0
  15. data/cookbooks/git/recipes/default.rb +24 -0
  16. data/cookbooks/git/templates/default/dot.gitconfig.erb +47 -0
  17. data/cookbooks/homebrew/README.rdoc +73 -0
  18. data/cookbooks/homebrew/libraries/homebrew_package.rb +85 -0
  19. data/cookbooks/homebrew/metadata.json +33 -0
  20. data/cookbooks/homebrew/metadata.rb +9 -0
  21. data/cookbooks/homebrew/recipes/default.rb +11 -0
  22. data/cookbooks/jenkins/metadata.rb +9 -0
  23. data/cookbooks/jenkins/recipes/default.rb +21 -0
  24. data/cookbooks/maatkit/recipes/default.rb +10 -0
  25. data/cookbooks/megalodon/attributes/default.rb +3 -0
  26. data/cookbooks/megalodon/definitions/megalodon_app.rb +21 -0
  27. data/cookbooks/megalodon/recipes/apache_vhosts.rb +46 -0
  28. data/cookbooks/megalodon/recipes/default.rb +55 -0
  29. data/cookbooks/megalodon/recipes/misc.rb +14 -0
  30. data/cookbooks/megalodon/templates/default/default.conf.erb +26 -0
  31. data/cookbooks/megalodon/templates/default/default.json.erb +5 -0
  32. data/cookbooks/megalodon/templates/default/dot.profile.erb +22 -0
  33. data/cookbooks/megalodon/templates/default/php5.conf.erb +12 -0
  34. data/cookbooks/megalodon/templates/default/vhost.conf.erb +28 -0
  35. data/cookbooks/memcached/README.rdoc +8 -0
  36. data/cookbooks/memcached/metadata.rb +2 -0
  37. data/cookbooks/memcached/recipes/default.rb +9 -0
  38. data/cookbooks/mongodb/recipes/default.rb +23 -0
  39. data/cookbooks/mvim/README.rdoc +8 -0
  40. data/cookbooks/mvim/metadata.rb +6 -0
  41. data/cookbooks/mvim/recipes/default.rb +47 -0
  42. data/cookbooks/mvim/templates/default/dot.vimrc.erb +23 -0
  43. data/cookbooks/mysql/README.rdoc +143 -0
  44. data/cookbooks/mysql/attributes/server.rb +58 -0
  45. data/cookbooks/mysql/metadata.rb +78 -0
  46. data/cookbooks/mysql/recipes/default.rb +24 -0
  47. data/cookbooks/mysql/recipes/mariadb.rb +41 -0
  48. data/cookbooks/mysql/templates/default/my.cnf.erb +161 -0
  49. data/cookbooks/nginx/recipes/default.rb +66 -0
  50. data/cookbooks/nginx/templates/default/app_nginx.conf.erb +42 -0
  51. data/cookbooks/nginx/templates/default/default.conf.erb +40 -0
  52. data/cookbooks/nginx/templates/default/fastcgi_params.erb +23 -0
  53. data/cookbooks/nginx/templates/default/nginx.conf.erb +33 -0
  54. data/cookbooks/node/README.rdoc +8 -0
  55. data/cookbooks/node/metadata.rb +6 -0
  56. data/cookbooks/node/recipes/default.rb +12 -0
  57. data/cookbooks/php/attributes/default.rb +3 -0
  58. data/cookbooks/php/metadata.rb +2 -0
  59. data/cookbooks/php/providers/pear.rb +229 -0
  60. data/cookbooks/php/providers/pear_channel.rb +91 -0
  61. data/cookbooks/php/recipes/default.rb +25 -0
  62. data/cookbooks/php/recipes/fpm.rb +45 -0
  63. data/cookbooks/php/recipes/module_apc.rb +12 -0
  64. data/cookbooks/php/recipes/module_memcached.rb +12 -0
  65. data/cookbooks/php/recipes/module_mongo.rb +11 -0
  66. data/cookbooks/php/recipes/module_xdebug.rb +11 -0
  67. data/cookbooks/php/resources/pear.rb +28 -0
  68. data/cookbooks/php/resources/pear_channel.rb +28 -0
  69. data/cookbooks/php/templates/default/mods/apc.ini.erb +4 -0
  70. data/cookbooks/php/templates/default/mods/memcached.ini.erb +1 -0
  71. data/cookbooks/php/templates/default/mods/mongo.ini.erb +1 -0
  72. data/cookbooks/php/templates/default/mods/xdebug.ini.erb +39 -0
  73. data/cookbooks/php/templates/default/net.php.php-fpm.plist.erb +23 -0
  74. data/cookbooks/php/templates/default/php-fpm.conf.erb +323 -0
  75. data/cookbooks/php/templates/default/php.ini.erb +1854 -0
  76. data/cookbooks/php.tgz +0 -0
  77. data/cookbooks/phpunit/metadata.rb +8 -0
  78. data/cookbooks/phpunit/recipes/default.rb +38 -0
  79. data/cookbooks/python/README.rdoc +8 -0
  80. data/cookbooks/python/metadata.rb +6 -0
  81. data/cookbooks/python/recipes/default.rb +6 -0
  82. data/cookbooks/redis/recipes/default.rb +23 -0
  83. data/cookbooks/siege/recipes/default.rb +4 -0
  84. data/cookbooks/solr/metadata.json +36 -0
  85. data/cookbooks/solr/metadata.rb +9 -0
  86. data/cookbooks/solr/recipes/default.rb +18 -0
  87. data/cookbooks/varnish/attributes/default.rb +2 -0
  88. data/cookbooks/varnish/recipes/default.rb +24 -0
  89. data/cookbooks/varnish/templates/default/default.vcl.erb +268 -0
  90. data/cookbooks/varnish/templates/default/ubuntu-default.erb +103 -0
  91. data/cookbooks/xhprof/metadata.json +36 -0
  92. data/cookbooks/xhprof/metadata.rb +12 -0
  93. data/cookbooks/xhprof/recipes/default.rb +43 -0
  94. data/cookbooks/xhprof/templates/default/xhprof.ini.erb +2 -0
  95. data/formulas/apc.rb +63 -0
  96. data/formulas/cclient.rb +57 -0
  97. data/formulas/megalodon.rb +27 -0
  98. data/formulas/memcached-php.rb +24 -0
  99. data/formulas/mongo-php.rb +25 -0
  100. data/formulas/mongodb-php.rb +31 -0
  101. data/formulas/php-memcached.rb +31 -0
  102. data/formulas/php.rb +261 -0
  103. data/formulas/xdebug.rb +36 -0
  104. data/formulas/xhprof.rb +33 -0
  105. data/lib/megalodon/version.rb +3 -0
  106. data/megalodon.gemspec +14 -0
  107. data/roles/nginx_web_server.json +23 -0
  108. data/roles/web_server.json +19 -0
  109. metadata +170 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Use megalodon.gemspec instead.
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Megalodon
2
+
3
+ The goal of megalodon to provide a simple, repeatable, and extendable way to setup a modern php development environment on Mac OS X. It consists of a collection of [homebrew](http://mxcl.github.com/homebrew) formulas and [chef](http://www.opscode.com/chef/) recipies. It's pretty awesome.
4
+
5
+ This project is heavily influenced by [cider/cinderella](https://github.com/atmos/cinderella), which is aimed at providing an environment for ruby/python/node. Megalodon started as a fork of [smeagol](https://github.com/atmos/smeagol) (the chef bits of cinderella), but has since taken a different approach.
6
+
7
+ ## Installation
8
+
9
+ Install [homebrew](http://mxcl.github.com/homebrew/).
10
+
11
+ You can use sudo for installing gems, but don't use sudo for anything else. If you already installed Ruby with homebrew then don't use sudo for any of the installation.
12
+
13
+ Install megalodon:
14
+
15
+ gem install megalodon
16
+
17
+ Run megalodon:
18
+
19
+ megalodon install
20
+
21
+ If `megalodon install` fails along the way try running it again.
22
+
23
+ If it fails again, read what command failed and run just that command and look at the output.
24
+
25
+ ## Usage
26
+
27
+ ### General
28
+
29
+ Megalodon uses OSX's built in apache, so you can restart apache like so:
30
+
31
+ sudo /usr/sbin/apachectl restart
32
+
33
+ Everything else that's installed with homebrew should have a plist in ~/Library/LaunchAgents (OSX's equivalent to /etc/init.d), which can be managed with lunchy. It will soon be included in megalodon, but for now just do `gem install lunchy`.
34
+
35
+ For example, you'd restart mysql like so:
36
+
37
+ lunchy restart mysql
38
+
39
+ ### Managing virtual hosts
40
+
41
+ You will need to edit /etc/hosts as per usual; To add a new virtual host, add a new .json file in:
42
+
43
+ ~/.megalodon/data_bags/vhosts
44
+
45
+ For example, you could add example.com to your /etc/hosts for 127.0.0.1 and then use an entry called example.json in ~/.megalodon/data_bags/vhosts with these contents:
46
+
47
+ {
48
+ "id": "example_com",
49
+ "docroot": "/home/yourname/workspace/example/",
50
+ "servername": "example.com",
51
+ "server_aliases": [ "www.example.com", "foo.example.com"]
52
+ }
53
+
54
+ You can specify additional key/value pairs as desired:
55
+
56
+ {
57
+ "id": "example_com",
58
+ "docroot": "/home/yourname/workspace/example/",
59
+ "servername": "example.com",
60
+ "php_admin_value": "xdebug.remote_enable 1",
61
+ "php_admin_value": "xdebug.remote_autostart 1"
62
+ }
63
+
64
+ To re-generate the apache confs after modifying/adding vhosts:
65
+
66
+ megalodon update_vhosts
67
+
68
+ Then restart apache as above.
69
+
70
+ ## Other notes
71
+
72
+ mysql default username is root, no password
73
+
74
+ ## Troubleshooting the install
75
+ Test if a new virtual host is working using curl:
76
+
77
+ curl http://localhost/ -H "Host www.example.com"
78
+
79
+ Replace www.example.com with the hostname you expect to work. If that returns the content you expect.
80
+
data/bin/megalodon ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require 'optparse'
4
+ require 'fileutils'
5
+
6
+ # Cross-platform way of finding an executable in the $PATH. (stolen from hub)
7
+ #
8
+ # which('ruby') #=> /usr/bin/ruby
9
+ def which(cmd)
10
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
11
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
12
+ exts.each { |ext|
13
+ exe = "#{path}/#{cmd}#{ext}"
14
+ return exe if File.executable? exe
15
+ }
16
+ end
17
+ return nil
18
+ end
19
+
20
+ def install_chef
21
+ puts "You don't seem to have chef, installing it for you"
22
+ script_name = "install.sh"
23
+ command = [
24
+ "curl -L -o /tmp/#{script_name} https://www.opscode.com/chef/#{script_name}",
25
+ "sudo bash /tmp/#{script_name} -v 10.24.0"
26
+ ]
27
+ system command.join(" && ")
28
+ which('chef-solo')
29
+ end
30
+
31
+ opt_parser = OptionParser.new do |opt|
32
+ opt.banner = "Usage: megalodon {-h} [install|update_vhosts]"
33
+ opt.on("-h","--help","help") do
34
+ puts opt_parser
35
+ exit
36
+ end
37
+ end
38
+
39
+ # Parse the command line.
40
+ opt_parser.parse!
41
+
42
+ case ARGV[0]
43
+ when 'update_vhosts'
44
+ runlist = 'run_vhosts.json'
45
+ when 'install', nil
46
+ runlist = 'run_list.json'
47
+ else
48
+ puts opt_parser
49
+ exit
50
+ end
51
+
52
+ # Create the databag directory here since it appears that the chef-solo run
53
+ # will fail if it doesn't already exist. Wish there was a better way to do this…
54
+ directory_name = "#{ENV['HOME']}/.megalodon/data_bags/vhosts"
55
+ FileUtils.mkdir_p(directory_name) unless FileTest::directory?(directory_name)
56
+
57
+ megalodon_path = File.expand_path("../../", __FILE__)
58
+
59
+ chef_solo = which('chef-solo') || install_chef
60
+
61
+ unless chef_solo
62
+ raise "Cannot find chef-solo!}"
63
+ end
64
+
65
+ puts "Copying custom forumulas"
66
+ system("cp #{megalodon_path}/formulas/* /usr/local/Library/Formula/")
67
+ puts "Starting chef-solo run"
68
+ system("#{chef_solo} -j #{megalodon_path}/config/#{runlist} -c #{megalodon_path}/config/solo.rb")
data/config/rake.rb ADDED
@@ -0,0 +1,60 @@
1
+ ###
2
+ # Company and SSL Details
3
+ ###
4
+
5
+ # The company name - used for SSL certificates, and in srvious other places
6
+ COMPANY_NAME = "atmos.org"
7
+
8
+ # The Country Name to use for SSL Certificates
9
+ SSL_COUNTRY_NAME = "US"
10
+
11
+ # The State Name to use for SSL Certificates
12
+ SSL_STATE_NAME = "Several"
13
+
14
+ # The Locality Name for SSL - typically, the city
15
+ SSL_LOCALITY_NAME = "Locality"
16
+
17
+ # What department?
18
+ SSL_ORGANIZATIONAL_UNIT_NAME = "Operations"
19
+
20
+ # The SSL contact email address
21
+ SSL_EMAIL_ADDRESS = "atmos@atmos.org"
22
+
23
+ # License for new Cookbooks
24
+ # Can be :apachev2 or :none
25
+ NEW_COOKBOOK_LICENSE = :none
26
+
27
+ ##########################
28
+ # Chef Repository Layout #
29
+ ##########################
30
+
31
+ # Where to install upstream cookbooks for serving
32
+ COOKBOOK_PATH = "/srv/chef/cookbooks"
33
+
34
+ # Where to install site-local modifications to upstream cookbooks
35
+ SITE_COOKBOOK_PATH = "/srv/chef/site-cookbooks"
36
+
37
+ # Where to install roles
38
+ ROLE_PATH = "/srv/chef/roles"
39
+
40
+ # Chef Config Path
41
+ CHEF_CONFIG_PATH = "/etc/chef"
42
+
43
+ # The location of the Chef Server Config file (on the server)
44
+ CHEF_SERVER_CONFIG = File.join(CHEF_CONFIG_PATH, "server.rb")
45
+
46
+ # The location of the Chef Client Config file (on the client)
47
+ CHEF_CLIENT_CONFIG = File.join(CHEF_CONFIG_PATH, "client.rb")
48
+
49
+ ###
50
+ # Useful Extras (which you probably don't need to change)
51
+ ###
52
+
53
+ # The top of the repository checkout
54
+ TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
55
+
56
+ # Where to store certificates generated with ssl_cert
57
+ CADIR = File.expand_path(File.join(TOPDIR, "certificates"))
58
+
59
+ # Where to store the mtime cache for the recipe/template syntax check
60
+ TEST_CACHE = File.expand_path(File.join(TOPDIR, ".rake_test_cache"))
@@ -0,0 +1,5 @@
1
+ {
2
+ "run_list": [
3
+ "megalodon","megalodon::misc", "role[web_server]", "solr", "varnish", "redis", "phpunit"
4
+ ]
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "run_list": [
3
+ "megalodon::apache_vhosts"
4
+ ]
5
+ }
data/config/solo.rb ADDED
@@ -0,0 +1,20 @@
1
+ #
2
+ # Chef Solo Config File
3
+ #
4
+ megalodon_root = "#{Dir.tmpdir}/megalodon"
5
+
6
+ log_level :info
7
+ log_location STDOUT
8
+ sandbox_path "#{megalodon_root}/sandboxes"
9
+ file_cache_path "#{megalodon_root}/cookbooks"
10
+ file_backup_path "#{megalodon_root}/backup"
11
+ cache_options ({ :path => "#{megalodon_root}/cache/checksums", :skip_expires => true })
12
+
13
+ # Optionally store your JSON data file and a tarball of cookbooks remotely.
14
+ #json_attribs "http://chef.example.com/dna.json"
15
+ #recipe_url "http://chef.example.com/cookbooks.tar.gz"
16
+ cookbook_path File.expand_path(File.join(File.dirname(__FILE__), "..", "cookbooks"))
17
+ role_path File.expand_path(File.join(File.dirname(__FILE__), "..", "roles"))
18
+ data_bag_path "#{ENV['HOME']}/.megalodon/data_bags"
19
+
20
+ Mixlib::Log::Formatter.show_time = false
@@ -0,0 +1,28 @@
1
+ # Cookbook Name:: dnsmasq
2
+ # Recipe:: default
3
+ #
4
+ package "dnsmasq"
5
+
6
+ bash "copy-conf" do
7
+ code <<-EOS
8
+ cp /usr/local/Cellar/dnsmasq/2.57/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
9
+ EOS
10
+ end
11
+
12
+ bash "copy plist firsttime" do
13
+ code <<-EOS
14
+ sudo ln -nfs /usr/local/Cellar/dnsmasq/2.57/uk.org.thekelleys.dnsmasq.plist /Library/LaunchDaemons/
15
+ sudo launchctl load -wF /Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist
16
+ EOS
17
+ not_if File.exists?("~/Library/LaunchAgents/org.elasticsearch.plist")
18
+ end
19
+
20
+ bash "copy new plist" do
21
+ code <<-EOS
22
+ sudo launchctl unload -w /Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist
23
+ sudo ln -nfs /usr/local/Cellar/dnsmasq/2.57/uk.org.thekelleys.dnsmasq.plist /Library/LaunchDaemons/
24
+ sudo launchctl load -wF /Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist
25
+ EOS
26
+ only_if File.exists?("/Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist")
27
+ end
28
+
@@ -0,0 +1,23 @@
1
+ # Cookbook Name:: elasticsearch
2
+ # Recipe:: default
3
+ #
4
+ package "eslasticsearch"
5
+
6
+ bash "copy plist firsttime" do
7
+ code <<-EOS
8
+ mkdir -p ~/Library/LaunchAgents
9
+ ln -nfs /usr/local/Cellar/elasticsearch/0.16.2/org.elasticsearch.plist ~/Library/LaunchAgents/
10
+ launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist
11
+ EOS
12
+ not_if File.exists?("~/Library/LaunchAgents/org.elasticsearch.plist")
13
+ end
14
+
15
+ bash "copy new plist" do
16
+ code <<-EOS
17
+ launchctl unload -w ~/Library/LaunchAgents/org.elasticsearch.plist
18
+ ln -nfs /usr/local/Cellar/elasticsearch/0.16.2/org.elasticsearch.plist ~/Library/LaunchAgents/
19
+ launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist
20
+ EOS
21
+ only_if File.exists?("~/Library/LaunchAgents/org.elasticsearch.plist")
22
+ end
23
+
@@ -0,0 +1,8 @@
1
+ = DESCRIPTION:
2
+
3
+ = REQUIREMENTS:
4
+
5
+ = ATTRIBUTES:
6
+
7
+ = USAGE:
8
+
@@ -0,0 +1,6 @@
1
+ maintainer "atmos.org"
2
+ maintainer_email "atmos@atmos.org"
3
+ license "MIT"
4
+ description "Installs/Configures erlang and riak"
5
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
6
+ version "0.1"
@@ -0,0 +1,8 @@
1
+ #
2
+ # Cookbook Name:: erlang
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2010, atmos.org
6
+ #
7
+
8
+ package "erlang"
@@ -0,0 +1,8 @@
1
+ = DESCRIPTION:
2
+
3
+ = REQUIREMENTS:
4
+
5
+ = ATTRIBUTES:
6
+
7
+ = USAGE:
8
+
@@ -0,0 +1,6 @@
1
+ maintainer "atmos"
2
+ maintainer_email "atmos@atmos.org"
3
+ license "MIT"
4
+ description "Installs/Configures git configs and shit you need"
5
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
6
+ version "0.1.0"
@@ -0,0 +1,24 @@
1
+ #
2
+ # Cookbook Name:: git
3
+ # Recipe:: default
4
+ #
5
+ root = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "homebrew"))
6
+ require root + '/resources/homebrew'
7
+ require root + '/providers/homebrew'
8
+ require 'etc'
9
+
10
+ template "#{ENV['HOME']}/.gitconfig" do
11
+ mode 0700
12
+ owner ENV['USER']
13
+ group Etc.getgrgid(Process.gid).name
14
+ source "dot.gitconfig.erb"
15
+ variables({
16
+ :home => ENV['HOME'],
17
+ :user => ENV['USER'],
18
+ :email => ENV['EMAIL'],
19
+ :github_user => ENV['GITHUB_USER'],
20
+ :github_token => ENV['GITHUB_TOKEN'],
21
+ :editor => ENV['EDITOR'] || fail("No editor set for your ~/.gitconfig"),
22
+ :fullname => ENV['FULLNAME'] || fail("No Full Name set for your ~/.gitconfig")
23
+ })
24
+ end
@@ -0,0 +1,47 @@
1
+ [core]
2
+ excludesfile = <%= @home %>/.gitfiles/excludes
3
+ editor = <%= @editor %>
4
+ whitespace = trailing-space,space-before-tab
5
+
6
+ [apply]
7
+ whitespace = fix
8
+
9
+ [color]
10
+ ui = true ;doesnt work for some reason ...
11
+
12
+ interactive = true
13
+ status = true
14
+ branch = true
15
+ diff = true
16
+ [alias]
17
+ st = status
18
+ ci = commit
19
+ co = checkout
20
+ br = branch
21
+ ls = branch
22
+ s = status
23
+ a = add
24
+ b = branch
25
+ d = diff
26
+ dc = diff --cached
27
+ v = show
28
+ l = log --pretty=oneline
29
+ ll = log
30
+ cp = cherry-pick
31
+ c = checkout
32
+ cc = commit
33
+ ri = rebase -i HEAD~10
34
+ sh = !git-sh
35
+ ro = !git fetch origin && git reset --hard origin/master
36
+
37
+ <% if @email && @fullname %>
38
+ [user]
39
+ email = <%= @email %>
40
+ name = <%= @fullname %>
41
+ <% end %>
42
+
43
+ <% if @github_user && @github_token %>
44
+ [github]
45
+ user = <%= @github_user %>
46
+ token = <%= @github_token %>
47
+ <% end %>
@@ -0,0 +1,73 @@
1
+ = Description
2
+
3
+ Installs Homebrew and acts as the native package provider for Mac OS X using
4
+ Homebrew to install packages. See:
5
+
6
+ http://woss.name/2011/01/23/converging-your-home-directory-with-chef/
7
+
8
+ for additional background.
9
+
10
+ = Requirements
11
+
12
+ == Prerequisites
13
+
14
+ In order for this recipe to work, you will have to already own
15
+ <tt>/usr/local</tt>. This is outside the scope of the cookbook because it's
16
+ anticipated that you'll run the cookbook as your own user, not root and you'd
17
+ have to be root to take ownership of the directory. Easiest way to get started:
18
+
19
+ sudo chown -R `whoami`:staff /usr/local
20
+
21
+ Bear in mind that this will take ownership of the entire folder and its
22
+ contents, so if you've already got stuff in there (eg MySQL owned by a +mysql+
23
+ user) you'll need to be a touch more careful.
24
+
25
+ == Platform
26
+
27
+ This is only going to work on platforms that Homebrew supports which is, I
28
+ think, just Mac OS X. This cookbook has been tested on Mac OS X 10.6.6 with the
29
+ latest version of Homebrew (as of Mon 24 Jan 2011 at any rate!).
30
+
31
+ == Cookbooks
32
+
33
+ Shouldn't require any other cookbooks, though its operation may be greatly
34
+ enhanced by another cookbook I'm brewing that manages launchd. ;-)
35
+
36
+ = Resources and Providers
37
+
38
+ This cookbook provides a package provider called +homebrew_package+ which will
39
+ install/remove packages using Homebrew. This becomes the default provider for
40
+ +package+ if your platform is Mac OS X.
41
+
42
+ = Attributes
43
+
44
+ None.
45
+
46
+ = Usage
47
+
48
+ Just make sure that this cookbook is selected before you start installing
49
+ packages. You can add:
50
+
51
+ include_recipe 'homebrew'
52
+
53
+ to all your recipes that install packages, or you can just make sure it's on
54
+ the run list somewhere early on. The bookbook itself ensures that Homebrew is
55
+ installed and up to date.
56
+
57
+ = License and Author
58
+
59
+ Author:: Graeme Mathieson (<mathie@woss.name>)
60
+
61
+ Copyright:: 2011, Graeme Mathieson
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
@@ -0,0 +1,85 @@
1
+ # Chef package provider for Homebrew
2
+
3
+ require 'chef/provider/package'
4
+ require 'chef/resource/package'
5
+ require 'chef/platform'
6
+
7
+ class Chef
8
+ class Provider
9
+ class Package
10
+ class Homebrew < Package
11
+ def load_current_resource
12
+ @current_resource = Chef::Resource::Package.new(@new_resource.name)
13
+ @current_resource.package_name(@new_resource.package_name)
14
+ @current_resource.version(current_installed_version)
15
+
16
+ @current_resource
17
+ end
18
+
19
+ def install_package(name, version)
20
+ brew('install', name, @new_resource.options)
21
+ end
22
+
23
+ # Homebrew doesn't really have a notion of upgrading packages, just
24
+ # install the latest version?
25
+ def upgrade_package(name, version)
26
+ install_package(name, version)
27
+ end
28
+
29
+ def remove_package(name, version)
30
+ brew('uninstall', name)
31
+ end
32
+
33
+ # Homebrew doesn't really have a notion of purging, so just remove.
34
+ def purge_package(name, version)
35
+ remove_package(name, version)
36
+ end
37
+
38
+ protected
39
+ def brew(*args)
40
+ run_command_with_systems_locale(
41
+ :command => "brew #{args.join(' ')}"
42
+ )
43
+ end
44
+
45
+ def current_installed_version
46
+ get_version_from_command("brew list --versions | awk '/^#{@new_resource.package_name} / { print $2 }'")
47
+ end
48
+
49
+ def candidate_version
50
+ brew_version = %x[brew --version].strip
51
+ if Gem::Version.new(brew_version) >= Gem::Version.new('0.9.2')
52
+ command = "brew info #{@new_resource.package_name} | awk '/^#{@new_resource.package_name}:/ { print $3 }'"
53
+ else
54
+ command = "brew info #{@new_resource.package_name} | awk '/^#{@new_resource.package_name} / { print $2 }'"
55
+ end
56
+ get_version_from_command(command)
57
+ end
58
+
59
+ def get_version_from_command(command)
60
+ version = get_response_from_command(command).chomp
61
+ version.empty? ? nil : version
62
+ end
63
+
64
+ # Nicked from lib/chef/package/provider/macports.rb and tweaked
65
+ # slightly.
66
+ def get_response_from_command(command)
67
+ output = nil
68
+ status = popen4(command) do |pid, stdin, stdout, stderr|
69
+ begin
70
+ output = stdout.read
71
+ rescue Exception => e
72
+ raise Chef::Exceptions::Package, "Could not read from STDOUT on command: #{command}\nException: #{e.inspect}"
73
+ end
74
+ end
75
+ unless (0..1).include? status.exitstatus
76
+ raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}"
77
+ end
78
+ output
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew
@@ -0,0 +1,33 @@
1
+ {
2
+ "suggestions": {
3
+ },
4
+ "conflicting": {
5
+ },
6
+ "long_description": "= Description\n\nInstalls Homebrew and acts as the native package provider for Mac OS X using\nHomebrew to install packages. See:\n\nhttp://woss.name/2011/01/23/converging-your-home-directory-with-chef/\n\nfor additional background.\n\n= Requirements\n\n== Platform\n\nThis is only going to work on platforms that Homebrew supports which is, I\nthink, just Mac OS X. This cookbook has been tested on Mac OS X 10.6.6 with the\nlatest version of Homebrew (as of Mon 24 Jan 2011 at any rate!).\n\n== Cookbooks\n\nShouldn't require any other cookbooks, though its operation may be greatly\nenhanced by another cookbook I'm brewing that manages launchd. ;-)\n\n= Resources and Providers\n\nThis cookbook provides a package provider called +homebrew_package+ which will\ninstall/remove packages using Homebrew. This becomes the default provider for\n+package+ if your platform is Mac OS X.\n\n= Attributes\n\nNone.\n\n= Usage\n\nJust make sure that this cookbook is selected before you start installing\npackages. You can add:\n\n include_recipe 'homebrew'\n\nto all your recipes that install packages, or you can just make sure it's on\nthe run list somewhere early on. The bookbook itself ensures that Homebrew is\ninstalled and up to date.\n\n= License and Author\n\nAuthor:: Graeme Mathieson (<mathie@woss.name>)\n\nCopyright:: 2011, Graeme Mathieson\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
7
+ "providing": {
8
+ },
9
+ "platforms": {
10
+ "mac_os_x": [
11
+
12
+ ]
13
+ },
14
+ "license": "Apache 2.0",
15
+ "maintainer": "Graeme Mathieson",
16
+ "replacing": {
17
+ },
18
+ "maintainer_email": "mathie@woss.name",
19
+ "name": "homebrew",
20
+ "version": "1.0.0",
21
+ "groupings": {
22
+ },
23
+ "dependencies": {
24
+ },
25
+ "description": "Install Homebrew and use it as your package provider in Mac OS X",
26
+ "recipes": {
27
+ "homebrew": "Install Homebrew"
28
+ },
29
+ "attributes": {
30
+ },
31
+ "recommendations": {
32
+ }
33
+ }
@@ -0,0 +1,9 @@
1
+ name "homebrew"
2
+ maintainer "Graeme Mathieson"
3
+ maintainer_email "mathie@woss.name"
4
+ license "Apache 2.0"
5
+ description "Install Homebrew and use it as your package provider in Mac OS X"
6
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
7
+ version "1.0.0"
8
+ recipe "homebrew", "Install Homebrew"
9
+ supports "mac_os_x"
@@ -0,0 +1,11 @@
1
+ execute "install homebrew" do
2
+ command "curl -sfL https://github.com/mxcl/homebrew/tarball/master | tar zx -m --strip 1"
3
+ cwd "/usr/local"
4
+ not_if { File.exist? '/usr/local/bin/brew' }
5
+ end
6
+
7
+ package 'git'
8
+
9
+ execute "update homebrew from github" do
10
+ command "/usr/local/bin/brew update || true"
11
+ end
@@ -0,0 +1,9 @@
1
+ maintainer "Mark Sonnabaum"
2
+ maintainer_email "mark.sonnabaum@acquia.com"
3
+ license "Apache 2.0"
4
+ description "Installs Jenkins CI"
5
+ version "0.9"
6
+
7
+ %w{ mac_os_x }.each do |os|
8
+ supports os
9
+ end
@@ -0,0 +1,21 @@
1
+ # Cookbook Name:: jenkins
2
+ # Recipe:: default
3
+ #
4
+ package "jenkins"
5
+
6
+ bash "copy plist firsttime" do
7
+ code <<-EOS
8
+ cp /usr/local/Cellar/jenkins/*/org.jenkins-ci.plist ~/Library/LaunchAgents/
9
+ launchctl load -w ~/Library/LaunchAgents/org.jenkins-ci.plist
10
+ EOS
11
+ not_if File.exists?("~/Library/LaunchAgents/org.jenkins-ci.plist")
12
+ end
13
+
14
+ bash "copy new plist" do
15
+ code <<-EOS
16
+ launchctl unload -w ~/Library/LaunchAgents/org.jenkins-ci.plist
17
+ cp /usr/local/Cellar/jenkins/*/org.jenkins-ci.plist ~/Library/LaunchAgents/
18
+ launchctl load -w ~/Library/LaunchAgents/org.jenkins-ci.plist
19
+ EOS
20
+ only_if File.exists?("~/Library/LaunchAgents/org.jenkins-ci.plist")
21
+ end