from-scratch 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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,53 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Provider:: global
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, 2014 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
+ def whyrun_supported?
23
+ true
24
+ end
25
+
26
+ use_inline_resources
27
+
28
+ provides :rbenv_global
29
+
30
+ include Chef::Rbenv::ScriptHelpers
31
+
32
+ action :create do
33
+ if current_global_version_correct?
34
+ set_updated { run_script }
35
+ else
36
+ Chef::Log.debug("#{new_resource} is already set - nothing to do")
37
+ end
38
+ end
39
+
40
+ def run_script
41
+ command = %(rbenv global #{new_resource.rbenv_version})
42
+
43
+ rbenv_script "#{command} #{which_rbenv}" do
44
+ code command
45
+ user new_resource.user if new_resource.user
46
+ root_path new_resource.root_path if new_resource.root_path
47
+ action :run
48
+ end
49
+ end
50
+
51
+ def current_global_version_correct?
52
+ current_global_version != new_resource.rbenv_version
53
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Provider:: plugin
4
+ #
5
+ # Author:: Joshua Yotty <jyotty@bluebox.net>
6
+ #
7
+ # Copyright 2014, Joshua Yotty
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
+ def whyrun_supported?
23
+ true
24
+ end
25
+
26
+ use_inline_resources
27
+
28
+ provides :rbenv_plugin
29
+
30
+ include Chef::Rbenv::ScriptHelpers
31
+
32
+ action :install do
33
+ set_updated { create_plugins_directory }
34
+ set_updated { clone_plugin_repo }
35
+ end
36
+
37
+ def create_plugins_directory
38
+ directory ::File.join(rbenv_root, 'plugins') do
39
+ owner new_resource.user || 'root'
40
+ mode '0755'
41
+ action :create
42
+ end
43
+ end
44
+
45
+ def clone_plugin_repo
46
+ plugin_path = ::File.join(rbenv_root, 'plugins', new_resource.name)
47
+
48
+ git "Install #{new_resource.name} plugin" do
49
+ destination plugin_path
50
+ repository new_resource.git_url
51
+ reference new_resource.git_ref || 'master'
52
+ user new_resource.user if new_resource.user
53
+ action :sync
54
+ end
55
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Provider:: rehash
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, 2014, 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
+ def whyrun_supported?
23
+ true
24
+ end
25
+
26
+ use_inline_resources
27
+
28
+ provides :rbenv_rehash
29
+
30
+ include Chef::Rbenv::ScriptHelpers
31
+
32
+ action :run do
33
+ set_updated { run_script }
34
+ end
35
+
36
+ def run_script
37
+ command = %(rbenv rehash)
38
+
39
+ rbenv_script "#{command} #{which_rbenv}" do
40
+ code command
41
+ user new_resource.user if new_resource.user
42
+ root_path new_resource.root_path if new_resource.root_path
43
+ action :run
44
+ end
45
+ end
@@ -0,0 +1,123 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Provider:: ruby
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
+ provides :rbenv_ruby
23
+
24
+ include Chef::Rbenv::ScriptHelpers
25
+
26
+ def load_current_resource
27
+ @rubie = new_resource.definition
28
+ @definition_file = new_resource.definition_file
29
+ @root_path = new_resource.root_path
30
+ @user = new_resource.user
31
+ @environment = new_resource.environment
32
+ @patch_url = new_resource.patch_url
33
+ @patch_file = new_resource.patch_file
34
+ @rbenv_action = new_resource.rbenv_action
35
+ end
36
+
37
+ action :install do # ~FC017
38
+ perform_install
39
+ end
40
+
41
+ action :reinstall do # ~FC017
42
+ perform_install
43
+ end
44
+
45
+ private
46
+
47
+ def perform_install
48
+ if ruby_build_missing?
49
+ Chef::Log.warn(
50
+ 'ruby_build cookbook is missing. Please add to the run_list (Action will be skipped).')
51
+ elsif ruby_installed?
52
+ Chef::Log.debug("#{new_resource} is already installed - nothing to do")
53
+ else
54
+ install_start = Time.now
55
+
56
+ install_ruby_dependencies
57
+
58
+ Chef::Log.info("Building #{new_resource}, this could take a while...")
59
+
60
+ # bypass block scoping issues
61
+ rbenv_user = @user
62
+ rubie = @rubie
63
+ definition = @definition_file || rubie
64
+ rbenv_prefix = @root_path
65
+ rbenv_env = @environment
66
+
67
+ patch_command = nil
68
+ patch_command = "--patch < <(curl -sSL #{@patch_url})" if @patch_url
69
+ patch_command = "--patch < #{@patch_file}" if @patch_file
70
+ command = %(rbenv #{@rbenv_action} #{definition} #{patch_command})
71
+
72
+ rbenv_script "#{command} #{which_rbenv}" do
73
+ code command
74
+ user rbenv_user if rbenv_user
75
+ root_path rbenv_prefix if rbenv_prefix
76
+ environment rbenv_env if rbenv_env
77
+ action :nothing
78
+ end.run_action(:run)
79
+
80
+ Chef::Log.debug("#{new_resource} build time was " \
81
+ "#{(Time.now - install_start) / 60.0} minutes")
82
+
83
+ new_resource.updated_by_last_action(true)
84
+ end
85
+ end
86
+
87
+ def ruby_installed?
88
+ if Array(new_resource.action).include?(:reinstall)
89
+ false
90
+ else
91
+ ::File.directory?(::File.join(rbenv_root, 'versions', @rubie))
92
+ end
93
+ end
94
+
95
+ def ruby_build_missing?
96
+ !run_context.loaded_recipe?('ruby_build')
97
+ end
98
+
99
+ def install_ruby_dependencies
100
+ definition = ::File.basename(new_resource.definition)
101
+
102
+ case definition
103
+ when /^\d\.\d\.\d/, /^rbx-/, /^ree-/
104
+ pkgs = node['ruby_build']['install_pkgs_cruby']
105
+ when /^jruby-/
106
+ pkgs = node['ruby_build']['install_pkgs_jruby']
107
+ end
108
+
109
+ package Array(pkgs) do
110
+ action :nothing
111
+ end.run_action(:install)
112
+
113
+ ensure_java_environment if definition =~ /^jruby-/
114
+ end
115
+
116
+ def ensure_java_environment
117
+ resource_collection.find(
118
+ 'ruby_block[update-java-alternatives]'
119
+ ).run_action(:create)
120
+ rescue Chef::Exceptions::ResourceNotFound
121
+ # have pity on my soul
122
+ Chef::Log.info 'The java cookbook does not appear to in the run_list.'
123
+ end
@@ -0,0 +1,81 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Provider:: script
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, 2014, 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
+ def whyrun_supported?
23
+ true
24
+ end
25
+
26
+ use_inline_resources
27
+
28
+ provides :rbenv_script
29
+
30
+ include Chef::Rbenv::ScriptHelpers
31
+
32
+ action :run do
33
+ set_updated { run_script }
34
+ end
35
+
36
+ def run_script
37
+ script_code = build_script_code
38
+ script_environment = build_script_environment
39
+
40
+ script new_resource.name do
41
+ interpreter 'bash'
42
+ code script_code
43
+ user new_resource.user if new_resource.user
44
+ creates new_resource.creates if new_resource.creates
45
+ cwd new_resource.cwd if new_resource.cwd
46
+ group new_resource.group if new_resource.group
47
+ returns new_resource.returns if new_resource.returns
48
+ timeout new_resource.timeout if new_resource.timeout
49
+ umask new_resource.umask if new_resource.umask
50
+
51
+ environment(script_environment)
52
+ end
53
+ end
54
+
55
+ def build_script_code
56
+ script = []
57
+ script << %(export RBENV_ROOT="#{rbenv_root}")
58
+ script << %(export PATH="${RBENV_ROOT}/bin:$PATH")
59
+ script << %{eval "$(rbenv init -)"}
60
+ if new_resource.rbenv_version
61
+ script << %(export RBENV_VERSION="#{new_resource.rbenv_version}")
62
+ end
63
+ script << new_resource.code
64
+ script.join("\n").concat("\n")
65
+ end
66
+
67
+ def build_script_environment
68
+ script_env = { 'RBENV_ROOT' => rbenv_root }
69
+
70
+ script_env.merge!(new_resource.environment) if new_resource.environment
71
+
72
+ if new_resource.path
73
+ script_env.merge!('PATH' => "#{new_resource.path.join(':')}:#{ENV['PATH']}")
74
+ end
75
+
76
+ if new_resource.user
77
+ script_env.merge!('USER' => new_resource.user, 'HOME' => user_home)
78
+ end
79
+
80
+ script_env
81
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2011, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ class Chef::Recipe
21
+ # mix in recipe helpers
22
+ include Chef::Rbenv::RecipeHelpers
23
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Recipe:: system
4
+ #
5
+ # Copyright 2010, 2011 Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ include_recipe 'ruby_rbenv::system_install'
21
+
22
+ Array(node['rbenv']['plugins']).each do |plugin|
23
+ rbenv_plugin plugin['name'] do
24
+ git_url plugin['git_url']
25
+ git_ref plugin['git_ref'] if plugin['git_ref']
26
+ end
27
+ end
28
+
29
+ Array(node['rbenv']['rubies']).each do |rubie|
30
+ if rubie.is_a?(Hash)
31
+ rbenv_ruby rubie['name'] do
32
+ environment rubie['environment'] if rubie['environment']
33
+ definition_file rubie['definition_file'] if rubie['definition_file']
34
+ end
35
+ else
36
+ rbenv_ruby rubie
37
+ end
38
+ end
39
+
40
+ rbenv_global node['rbenv']['global'] if node['rbenv']['global']
41
+
42
+ node['rbenv']['gems'].each_pair do |rubie, gems|
43
+ Array(gems).each do |gem|
44
+ rbenv_gem gem['name'] do
45
+ rbenv_version rubie
46
+
47
+ %w(version action options source).each do |attr|
48
+ send(attr, gem[attr]) if gem[attr]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Cookbook Name:: ruby_rbenv
3
+ # Recipe:: system_install
4
+ #
5
+ # Copyright 2011, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ include_recipe 'ruby_rbenv'
21
+
22
+ upgrade_strategy = build_upgrade_strategy(node['rbenv']['upgrade'])
23
+ git_url = node['rbenv']['git_url']
24
+ git_ref = node['rbenv']['git_ref']
25
+ rbenv_prefix = node['rbenv']['root_path']
26
+ rbenv_plugins = node['rbenv']['plugins']
27
+
28
+ install_rbenv_pkg_prereqs
29
+
30
+ directory '/etc/profile.d' do
31
+ owner 'root'
32
+ mode '0755'
33
+ end
34
+
35
+ template '/etc/profile.d/rbenv.sh' do
36
+ source 'rbenv.sh.erb'
37
+ owner 'root'
38
+ mode '0755'
39
+ end
40
+
41
+ install_or_upgrade_rbenv rbenv_prefix: rbenv_prefix,
42
+ git_url: git_url,
43
+ git_ref: git_ref,
44
+ upgrade_strategy: upgrade_strategy,
45
+ rbenv_plugins: rbenv_plugins