from-scratch 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +1 -7
  3. data/Berksfile.lock +6 -0
  4. data/README.md +8 -3
  5. data/bin/scratchify +1 -1
  6. data/cookbooks/ruby_build/CHANGELOG.md +72 -0
  7. data/cookbooks/ruby_build/README.md +338 -0
  8. data/cookbooks/ruby_build/attributes/default.rb +67 -0
  9. data/cookbooks/ruby_build/libraries/ruby_build_recipe_helpers.rb +40 -0
  10. data/cookbooks/ruby_build/metadata.json +39 -0
  11. data/cookbooks/ruby_build/providers/ruby.rb +88 -0
  12. data/cookbooks/ruby_build/recipes/default.rb +69 -0
  13. data/cookbooks/ruby_build/resources/ruby.rb +33 -0
  14. data/cookbooks/ruby_rbenv/CHANGELOG.md +221 -0
  15. data/cookbooks/ruby_rbenv/README.md +1059 -0
  16. data/cookbooks/ruby_rbenv/attributes/default.rb +73 -0
  17. data/cookbooks/ruby_rbenv/libraries/chef_provider_package_rbenvrubygems.rb +94 -0
  18. data/cookbooks/ruby_rbenv/libraries/chef_rbenv_mixin.rb +49 -0
  19. data/cookbooks/ruby_rbenv/libraries/chef_rbenv_recipe_helpers.rb +118 -0
  20. data/cookbooks/ruby_rbenv/libraries/chef_rbenv_script_helpers.rb +79 -0
  21. data/cookbooks/ruby_rbenv/libraries/matchers.rb +25 -0
  22. data/cookbooks/ruby_rbenv/metadata.json +1 -0
  23. data/cookbooks/ruby_rbenv/providers/global.rb +53 -0
  24. data/cookbooks/ruby_rbenv/providers/plugin.rb +55 -0
  25. data/cookbooks/ruby_rbenv/providers/rehash.rb +45 -0
  26. data/cookbooks/ruby_rbenv/providers/ruby.rb +123 -0
  27. data/cookbooks/ruby_rbenv/providers/script.rb +81 -0
  28. data/cookbooks/ruby_rbenv/recipes/default.rb +23 -0
  29. data/cookbooks/ruby_rbenv/recipes/system.rb +52 -0
  30. data/cookbooks/ruby_rbenv/recipes/system_install.rb +45 -0
  31. data/cookbooks/ruby_rbenv/recipes/user.rb +76 -0
  32. data/cookbooks/ruby_rbenv/recipes/user_install.rb +48 -0
  33. data/cookbooks/ruby_rbenv/resources/gem.rb +44 -0
  34. data/cookbooks/ruby_rbenv/resources/global.rb +33 -0
  35. data/cookbooks/ruby_rbenv/resources/plugin.rb +15 -0
  36. data/cookbooks/ruby_rbenv/resources/rehash.rb +29 -0
  37. data/cookbooks/ruby_rbenv/resources/ruby.rb +43 -0
  38. data/cookbooks/ruby_rbenv/resources/script.rb +39 -0
  39. data/cookbooks/ruby_rbenv/templates/default/rbenv.sh.erb +15 -0
  40. data/cookbooks/scratchify/Berksfile +1 -7
  41. data/cookbooks/scratchify/Berksfile.lock +6 -0
  42. data/cookbooks/scratchify/README.md +8 -3
  43. data/cookbooks/scratchify/bin/scratchify +1 -1
  44. data/cookbooks/scratchify/from-scratch.gemspec +1 -0
  45. data/cookbooks/scratchify/lib/from-scratch.rb +51 -9
  46. data/cookbooks/scratchify/lib/from-scratch/version.rb +2 -2
  47. data/cookbooks/scratchify/metadata.json +2 -1
  48. data/cookbooks/scratchify/spec/from/scratch_spec.rb +62 -5
  49. data/cookbooks/scratchify/spec/spec_helper.rb +8 -1
  50. data/cookbooks/scratchify/templates/node.json.erb +28 -7
  51. data/cookbooks/scratchify/templates/user.json.erb +1 -1
  52. data/from-scratch.gemspec +1 -0
  53. data/lib/from-scratch.rb +51 -9
  54. data/lib/from-scratch/version.rb +2 -2
  55. data/metadata.rb +1 -0
  56. data/templates/node.json.erb +28 -7
  57. data/templates/user.json.erb +1 -1
  58. metadata +50 -3
@@ -0,0 +1,73 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Attributes:: default
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ # git repository containing rbenv
23
+ default['rbenv']['git_url'] = 'git://github.com/sstephenson/rbenv.git'
24
+ default['rbenv']['git_ref'] = 'v0.4.0'
25
+
26
+ # upgrade action strategy
27
+ default['rbenv']['upgrade'] = 'none'
28
+
29
+ # plugins to install
30
+ default['rbenv']['plugins'] = []
31
+
32
+ # extra system-wide tunables
33
+ default['rbenv']['root_path'] = '/usr/local/rbenv'
34
+ default['rbenv']['vagrant']['system_chef_solo'] = '/opt/ruby/bin/chef-solo'
35
+
36
+ # a list of user hashes, each an isolated per-user rbenv installation
37
+ default['rbenv']['user_installs'] = []
38
+
39
+ # list of additional rubies that will be installed
40
+ default['rbenv']['rubies'] = []
41
+ default['rbenv']['user_rubies'] = []
42
+
43
+ # hash of rubies and their list of additional gems to be installed.
44
+ default['rbenv']['gems'] = {}
45
+ default['rbenv']['user_gems'] = {}
46
+
47
+ # list of rbenv plugins to install
48
+ default['rbenv']['plugins'] = []
49
+ default['rbenv']['user_plugins'] = []
50
+
51
+ # whether to create profile.d shell script
52
+ default['rbenv']['create_profiled'] = true
53
+
54
+ case node['platform_family']
55
+ when 'rhel', 'fedora'
56
+ default['rbenv']['install_pkgs'] = %w(git grep)
57
+ default['rbenv']['user_home_root'] = '/home'
58
+ when 'debian', 'suse'
59
+ default['rbenv']['install_pkgs'] = %w(git-core grep)
60
+ default['rbenv']['user_home_root'] = '/home'
61
+ when 'mac_os_x'
62
+ default['rbenv']['install_pkgs'] = %w(git)
63
+ default['rbenv']['user_home_root'] = '/Users'
64
+ when 'freebsd'
65
+ default['rbenv']['install_pkgs'] = %w(git)
66
+ default['rbenv']['user_home_root'] = '/usr/home'
67
+ when 'gentoo'
68
+ default['rbenv']['install_pkgs'] = %w(git)
69
+ default['rbenv']['user_home_root'] = '/home'
70
+ when 'arch'
71
+ default['rbenv']['install_pkgs'] = %w(git grep)
72
+ default['rbenv']['user_home_root'] = '/home'
73
+ end
@@ -0,0 +1,94 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Provider:: Chef::Provider::Package::RbenvRubygems
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ require 'etc'
22
+
23
+ class Chef
24
+ module Rbenv
25
+ module Mixin
26
+ module ShellOut
27
+ # stub to satisfy RbenvRubygems (library load order not guarenteed)
28
+ end
29
+ end
30
+
31
+ module ScriptHelpers
32
+ # stub to satisfy RbenvRubygems (library load order not guarenteed)
33
+ end
34
+ end
35
+
36
+ class Provider
37
+ class Package
38
+ class RbenvRubygems < Chef::Provider::Package::Rubygems
39
+ class RbenvGemEnvironment < AlternateGemEnvironment
40
+ attr_reader :rbenv_version, :rbenv_user
41
+
42
+ include Chef::Rbenv::Mixin::ShellOut
43
+
44
+ def initialize(gem_binary_location, rbenv_version, rbenv_user = nil)
45
+ super(gem_binary_location)
46
+ @rbenv_version = rbenv_version
47
+ @rbenv_user = rbenv_user
48
+ end
49
+ end
50
+
51
+ attr_reader :rbenv_user
52
+
53
+ include Chef::Rbenv::Mixin::ShellOut
54
+ include Chef::Rbenv::ScriptHelpers
55
+
56
+ def initialize(new_resource, run_context = nil)
57
+ super
58
+ normalize_version
59
+ @new_resource.gem_binary(wrap_shim_cmd('gem'))
60
+ @rbenv_user = new_resource.respond_to?('user') ? new_resource.user : nil
61
+ @gem_env = RbenvGemEnvironment.new(
62
+ gem_binary_path, new_resource.rbenv_version, rbenv_user)
63
+ end
64
+
65
+ def install_package(name, version)
66
+ run_as_user(rbenv_user) { super }
67
+ rehash
68
+ true
69
+ end
70
+
71
+ def remove_package(name, version)
72
+ run_as_user(rbenv_user) { super }
73
+ rehash
74
+ true
75
+ end
76
+
77
+ private
78
+
79
+ # converts "global" to the current global ruby version
80
+ def normalize_version
81
+ @new_resource.rbenv_version(current_global_version) if @new_resource.rbenv_version == 'global'
82
+ end
83
+
84
+ def rehash
85
+ e = ::Chef::Resource::RubyRbenvRehash.new(new_resource.name, @run_context)
86
+ e.root_path rbenv_root
87
+ e.user rbenv_user if rbenv_user
88
+ e.action :nothing
89
+ e.run_action(:run)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Library:: Chef::Rbenv::Mixin
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ class Chef
23
+ module Rbenv
24
+ module Mixin
25
+ module ShellOut
26
+ def shell_out!(*command_args)
27
+ options = command_args.last.is_a?(Hash) ? command_args.pop : {}
28
+ options[:env] = shell_environment.merge(options[:env] || {})
29
+
30
+ super(*command_args.push(options))
31
+ end
32
+
33
+ def shell_environment
34
+ if rbenv_user
35
+ { 'USER' => rbenv_user, 'HOME' => Etc.getpwnam(rbenv_user).dir }
36
+ else
37
+ {}
38
+ end
39
+ end
40
+ end
41
+
42
+ module ResourceString
43
+ def to_s
44
+ "#{@resource_name}[#{@rbenv_version || 'global'}::#{@name}] (#{@user || 'system'})"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,118 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Library:: Chef::RubyBuild::RecipeHelpers
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ class Chef
23
+ module Rbenv
24
+ module RecipeHelpers
25
+ def build_upgrade_strategy(strategy)
26
+ if strategy.nil? || strategy == false
27
+ 'none'
28
+ else
29
+ strategy
30
+ end
31
+ end
32
+
33
+ def mac_with_no_homebrew
34
+ node['platform'] == 'mac_os_x' &&
35
+ Chef::Platform.find_provider_for_node(node, :package) !=
36
+ Chef::Provider::Package::Homebrew
37
+ end
38
+
39
+ def install_rbenv_pkg_prereqs
40
+ return if mac_with_no_homebrew
41
+
42
+ package node['rbenv']['install_pkgs']
43
+ end
44
+
45
+ def install_or_upgrade_rbenv(opts = {})
46
+ git_deploy_rbenv opts
47
+ initialize_rbenv opts
48
+ add_rbenv_to_path
49
+ end
50
+
51
+ private
52
+
53
+ def git_deploy_rbenv(opts)
54
+ if opts[:upgrade_strategy] == 'none'
55
+ git_exec_action = :checkout
56
+ else
57
+ git_exec_action = :sync
58
+ end
59
+
60
+ git opts[:rbenv_prefix] do
61
+ repository opts[:git_url]
62
+ reference opts[:git_ref]
63
+ user opts[:user] if opts[:user]
64
+ group opts[:group] if opts[:group]
65
+ action git_exec_action
66
+ end
67
+
68
+ directory "#{opts[:rbenv_prefix]}/plugins" do
69
+ owner opts[:user].nil? ? 'root' : opts[:user]
70
+ mode '0755'
71
+ end
72
+
73
+ Array(opts[:rbenv_plugins]).each do |plugin|
74
+ revision = plugin['revision'].nil? ? 'master' : plugin['revision']
75
+ plugin_path = "#{opts[:rbenv_prefix]}/plugins/#{plugin['name']}"
76
+
77
+ git "Install rbenv plugin - #{plugin['name']}" do
78
+ repository plugin['git_url']
79
+ destination plugin_path
80
+ reference revision
81
+ user opts[:user] if opts[:user]
82
+ group opts[:group] if opts[:group]
83
+ action :sync
84
+ end
85
+ log "Installed rbenv plugin - #{plugin['name']}"
86
+ end
87
+ end
88
+
89
+ def initialize_rbenv(opts)
90
+ prefix = opts[:rbenv_prefix]
91
+
92
+ if opts[:user]
93
+ init_env = { 'USER' => opts[:user], 'HOME' => opts[:home_dir] }
94
+ else
95
+ init_env = {}
96
+ end
97
+
98
+ bash "Initialize rbenv (#{opts[:user] || 'system'})" do
99
+ code %(PATH="#{prefix}/bin:$PATH" rbenv init -)
100
+ environment({ 'RBENV_ROOT' => prefix }.merge(init_env))
101
+ user opts[:user] if opts[:user]
102
+ group opts[:group] if opts[:group]
103
+ end
104
+
105
+ log "rbenv-post-init-#{opts[:user] || 'system'}"
106
+ end
107
+
108
+ def add_rbenv_to_path
109
+ ruby_block 'Add rbenv to PATH' do
110
+ block do
111
+ rbenv_root = node['rbenv']['root_path']
112
+ ENV['PATH'] = "#{rbenv_root}/shims:#{rbenv_root}/bin:#{ENV['PATH']}"
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,79 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Library:: Chef::Rbenv::ShellHelpers
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ class Chef
23
+ module Rbenv
24
+ module ScriptHelpers
25
+ def rbenv_root
26
+ if new_resource.root_path
27
+ new_resource.root_path
28
+ elsif new_resource.user
29
+ ::File.join(user_home, '.rbenv')
30
+ else
31
+ node['rbenv']['root_path']
32
+ end
33
+ end
34
+
35
+ def user_home
36
+ return nil unless new_resource.user
37
+
38
+ Etc.getpwnam(new_resource.user).dir
39
+ end
40
+
41
+ def which_rbenv
42
+ "(#{new_resource.user || 'system'})"
43
+ end
44
+
45
+ def current_global_version
46
+ version_file = ::File.join(rbenv_root, 'version')
47
+
48
+ ::File.exist?(version_file) && ::IO.read(version_file).chomp
49
+ end
50
+
51
+ def wrap_shim_cmd(cmd)
52
+ [%(export RBENV_ROOT="#{rbenv_root}"),
53
+ %(export PATH="$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH"),
54
+ %(export RBENV_VERSION="#{new_resource.rbenv_version}"),
55
+ %($RBENV_ROOT/shims/#{cmd})
56
+ ].join(' && ')
57
+ end
58
+
59
+ def set_updated
60
+ r = yield
61
+ new_resource.updated_by_last_action(r.updated_by_last_action?)
62
+ end
63
+
64
+ # Execute the supplied block of code as the given user.
65
+ def run_as_user(username, &block)
66
+ if username
67
+ user = Etc.getpwnam(username)
68
+ Process.fork do
69
+ Process.uid = user.uid
70
+ block.call
71
+ end
72
+ Process.wait
73
+ else
74
+ block.call
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,25 @@
1
+ if defined?(ChefSpec)
2
+ def install_rbenv_plugin(name)
3
+ ChefSpec::Matchers::ResourceMatcher.new(:rbenv_plugin, :install, name)
4
+ end
5
+
6
+ def run_rbenv_script(name)
7
+ ChefSpec::Matchers::ResourceMatcher.new(:rbenv_script, :run, name)
8
+ end
9
+
10
+ def install_rbenv_gem(name)
11
+ ChefSpec::Matchers::ResourceMatcher.new(:rbenv_gem, :install, name)
12
+ end
13
+
14
+ def upgrade_rbenv_gem(name)
15
+ ChefSpec::Matchers::ResourceMatcher.new(:rbenv_gem, :upgrade, name)
16
+ end
17
+
18
+ def remove_rbenv_gem(name)
19
+ ChefSpec::Matchers::ResourceMatcher.new(:rbenv_gem, :remove, name)
20
+ end
21
+
22
+ def purge_rbenv_gem(name)
23
+ ChefSpec::Matchers::ResourceMatcher.new(:rbenv_gem, :purge, name)
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ {"name":"ruby_rbenv","version":"1.0.1","description":"Manages rbenv and its installed rubies. Several LWRPs are also defined.","long_description":"Please refer to README.md (it's long).","maintainer":"Fletcher Nichol","maintainer_email":"fnichol@nichol.ca","license":"Apache 2.0","platforms":{"ubuntu":">= 0.0.0","linuxmint":">= 0.0.0","debian":">= 0.0.0","freebsd":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","fedora":">= 0.0.0","amazon":">= 0.0.0","scientific":">= 0.0.0","suse":">= 0.0.0","mac_os_x":">= 0.0.0","gentoo":">= 0.0.0","arch":">= 0.0.0"},"dependencies":{"ruby_build":">= 0.0.0"},"recommendations":{"java":"> 1.4.0"},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}}