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.
- checksums.yaml +4 -4
- data/Berksfile +1 -7
- data/Berksfile.lock +6 -0
- data/README.md +8 -3
- data/bin/scratchify +1 -1
- data/cookbooks/ruby_build/CHANGELOG.md +72 -0
- data/cookbooks/ruby_build/README.md +338 -0
- data/cookbooks/ruby_build/attributes/default.rb +67 -0
- data/cookbooks/ruby_build/libraries/ruby_build_recipe_helpers.rb +40 -0
- data/cookbooks/ruby_build/metadata.json +39 -0
- data/cookbooks/ruby_build/providers/ruby.rb +88 -0
- data/cookbooks/ruby_build/recipes/default.rb +69 -0
- data/cookbooks/ruby_build/resources/ruby.rb +33 -0
- data/cookbooks/ruby_rbenv/CHANGELOG.md +221 -0
- data/cookbooks/ruby_rbenv/README.md +1059 -0
- data/cookbooks/ruby_rbenv/attributes/default.rb +73 -0
- data/cookbooks/ruby_rbenv/libraries/chef_provider_package_rbenvrubygems.rb +94 -0
- data/cookbooks/ruby_rbenv/libraries/chef_rbenv_mixin.rb +49 -0
- data/cookbooks/ruby_rbenv/libraries/chef_rbenv_recipe_helpers.rb +118 -0
- data/cookbooks/ruby_rbenv/libraries/chef_rbenv_script_helpers.rb +79 -0
- data/cookbooks/ruby_rbenv/libraries/matchers.rb +25 -0
- data/cookbooks/ruby_rbenv/metadata.json +1 -0
- data/cookbooks/ruby_rbenv/providers/global.rb +53 -0
- data/cookbooks/ruby_rbenv/providers/plugin.rb +55 -0
- data/cookbooks/ruby_rbenv/providers/rehash.rb +45 -0
- data/cookbooks/ruby_rbenv/providers/ruby.rb +123 -0
- data/cookbooks/ruby_rbenv/providers/script.rb +81 -0
- data/cookbooks/ruby_rbenv/recipes/default.rb +23 -0
- data/cookbooks/ruby_rbenv/recipes/system.rb +52 -0
- data/cookbooks/ruby_rbenv/recipes/system_install.rb +45 -0
- data/cookbooks/ruby_rbenv/recipes/user.rb +76 -0
- data/cookbooks/ruby_rbenv/recipes/user_install.rb +48 -0
- data/cookbooks/ruby_rbenv/resources/gem.rb +44 -0
- data/cookbooks/ruby_rbenv/resources/global.rb +33 -0
- data/cookbooks/ruby_rbenv/resources/plugin.rb +15 -0
- data/cookbooks/ruby_rbenv/resources/rehash.rb +29 -0
- data/cookbooks/ruby_rbenv/resources/ruby.rb +43 -0
- data/cookbooks/ruby_rbenv/resources/script.rb +39 -0
- data/cookbooks/ruby_rbenv/templates/default/rbenv.sh.erb +15 -0
- data/cookbooks/scratchify/Berksfile +1 -7
- data/cookbooks/scratchify/Berksfile.lock +6 -0
- data/cookbooks/scratchify/README.md +8 -3
- data/cookbooks/scratchify/bin/scratchify +1 -1
- data/cookbooks/scratchify/from-scratch.gemspec +1 -0
- data/cookbooks/scratchify/lib/from-scratch.rb +51 -9
- data/cookbooks/scratchify/lib/from-scratch/version.rb +2 -2
- data/cookbooks/scratchify/metadata.json +2 -1
- data/cookbooks/scratchify/spec/from/scratch_spec.rb +62 -5
- data/cookbooks/scratchify/spec/spec_helper.rb +8 -1
- data/cookbooks/scratchify/templates/node.json.erb +28 -7
- data/cookbooks/scratchify/templates/user.json.erb +1 -1
- data/from-scratch.gemspec +1 -0
- data/lib/from-scratch.rb +51 -9
- data/lib/from-scratch/version.rb +2 -2
- data/metadata.rb +1 -0
- data/templates/node.json.erb +28 -7
- data/templates/user.json.erb +1 -1
- metadata +50 -3
@@ -1,15 +1,26 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'erb'
|
3
3
|
require 'fileutils'
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
app_name, host = ARGV
|
8
|
-
ssh_pub_key = `cat ~/.ssh/id_rsa.pub`.strip
|
9
|
-
postgresql_admin_password = `echo -n '#{SecureRandom.base64(16)}''postgres' | openssl md5 | sed -e 's/.* /md5/'`.strip
|
10
|
-
postgresql_user_password = SecureRandom.base64(16)
|
7
|
+
class FromScratch
|
8
|
+
DEFAULTS = { ruby_installer: 'rvm' }
|
11
9
|
|
12
|
-
|
10
|
+
attr_accessor :options
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@options = OpenStruct.new DEFAULTS
|
14
|
+
end
|
15
|
+
|
16
|
+
def run!
|
17
|
+
parse_options
|
18
|
+
get_host_and_app_name
|
19
|
+
generate_values
|
20
|
+
|
21
|
+
{ node: ['nodes', @options.host],
|
22
|
+
user: ['data_bags/users', 'deploy']
|
23
|
+
}.each do |from, to|
|
13
24
|
FileUtils.mkdir_p File.expand_path("../../tmp/#{to[0]}", __FILE__)
|
14
25
|
File.open(File.expand_path("../../tmp/#{to.join('/')}.json", __FILE__), 'w') do |f|
|
15
26
|
f.write ERB.new(File.open(File.expand_path("../../templates/#{from}.json.erb", __FILE__)).read).result(binding)
|
@@ -17,10 +28,41 @@ module FromScratch
|
|
17
28
|
end
|
18
29
|
|
19
30
|
Dir.chdir(File.expand_path('../..', __FILE__)) do
|
20
|
-
system "knife solo bootstrap root@#{host} -c ./.chef/knife.rb"
|
21
|
-
system "knife solo clean root@#{host} -c ./.chef/knife.rb"
|
31
|
+
system "knife solo bootstrap root@#{@options.host} -c ./.chef/knife.rb"
|
32
|
+
system "knife solo clean root@#{@options.host} -c ./.chef/knife.rb"
|
22
33
|
end
|
23
34
|
|
24
35
|
FileUtils.rm_rf [File.expand_path('../../tmp', __FILE__)]
|
25
36
|
end
|
37
|
+
|
38
|
+
def get_host_and_app_name
|
39
|
+
@options.app_name, @options.host = ARGV.select { |x| !(x =~ /^\-/) }
|
40
|
+
|
41
|
+
unless @options.app_name && @options.host
|
42
|
+
raise ArgumentError, 'You should specify APP_NAME and HOST. Use --help for information.'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_options
|
47
|
+
opt_parser = OptionParser.new do |args|
|
48
|
+
args.banner = "Usage: scratchify your_app_name your.host.com [options]"
|
49
|
+
|
50
|
+
args.on '--rbenv', 'Use RBENV instead of RVM' do
|
51
|
+
@options.ruby_installer = 'rbenv'
|
52
|
+
end
|
53
|
+
|
54
|
+
args.on '-h', '--help', 'Prints this help' do
|
55
|
+
puts args
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
opt_parser.parse!
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate_values
|
64
|
+
@options.ssh_pub_key = `cat ~/.ssh/id_rsa.pub`.strip
|
65
|
+
@options.postgresql_admin_password = `echo -n '#{SecureRandom.base64(16)}''postgres' | openssl md5 | sed -e 's/.* /md5/'`.strip
|
66
|
+
@options.postgresql_user_password = SecureRandom.base64(16)
|
67
|
+
end
|
26
68
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class FromScratch
|
2
|
+
VERSION = "0.6.0"
|
3
3
|
end
|
@@ -1,11 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
3
|
+
describe FromScratch do
|
4
|
+
let(:instance) { described_class.new }
|
5
|
+
let(:app_name) { 'my_app' }
|
6
|
+
let(:host) { 'host.example.com' }
|
7
|
+
|
8
|
+
describe '::new' do
|
9
|
+
subject { instance }
|
10
|
+
|
11
|
+
its('options.to_h') { are_expected.to eq(described_class::DEFAULTS) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#get_host_and_app_name' do
|
15
|
+
before do
|
16
|
+
stub_const 'ARGV', argv
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { instance.options }
|
20
|
+
|
21
|
+
context 'with app_name and host' do
|
22
|
+
before { instance.get_host_and_app_name }
|
23
|
+
let(:argv) { [app_name, host] }
|
24
|
+
|
25
|
+
its(:app_name) { is_expected.to eq(app_name) }
|
26
|
+
its(:host) { is_expected.to eq(host) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'without one of app_name or host' do
|
30
|
+
let(:argv) { [app_name] }
|
31
|
+
|
32
|
+
it 'should raise' do
|
33
|
+
expect do
|
34
|
+
instance.get_host_and_app_name
|
35
|
+
end.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'and with --option' do
|
39
|
+
let(:argv) { [app_name, '--option'] }
|
40
|
+
|
41
|
+
it 'should raise' do
|
42
|
+
expect do
|
43
|
+
instance.get_host_and_app_name
|
44
|
+
end.to raise_error(ArgumentError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
6
48
|
end
|
7
49
|
|
8
|
-
|
9
|
-
|
50
|
+
describe '#parse_options' do
|
51
|
+
before do
|
52
|
+
stub_const 'ARGV', argv
|
53
|
+
instance.parse_options
|
54
|
+
end
|
55
|
+
|
56
|
+
subject { instance.options }
|
57
|
+
|
58
|
+
context 'with --rbenv' do
|
59
|
+
let(:argv) { [app_name, host, '--rbenv'] }
|
60
|
+
|
61
|
+
its(:ruby_installer) { is_expected.to eq('rbenv') }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'has a version number' do
|
66
|
+
expect(FromScratch::VERSION).not_to be nil
|
10
67
|
end
|
11
68
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"run_list": [
|
3
3
|
"recipe[user::data_bag]",
|
4
|
+
<% if @options.ruby_installer == 'rvm' %>
|
4
5
|
"recipe[scratchify::pre_rvm]",
|
5
6
|
"recipe[rvm::user]",
|
7
|
+
<% elsif @options.ruby_installer == 'rbenv' %>
|
8
|
+
"recipe[ruby_build]",
|
9
|
+
"recipe[ruby_rbenv::user]",
|
10
|
+
<% end %>
|
6
11
|
"recipe[postgresql::server]",
|
7
12
|
"recipe[postgresql::config_pgtune]",
|
8
13
|
"recipe[postgresql::setup_users]",
|
@@ -14,6 +19,7 @@
|
|
14
19
|
|
15
20
|
"users": ["deploy"],
|
16
21
|
|
22
|
+
<% if @options.ruby_installer == 'rvm' %>
|
17
23
|
"rvm": {
|
18
24
|
"user_default_ruby": "2.2.3",
|
19
25
|
"user_install_rubies": true,
|
@@ -27,27 +33,42 @@
|
|
27
33
|
],
|
28
34
|
"gpg": {}
|
29
35
|
},
|
36
|
+
<% elsif @options.ruby_installer == 'rbenv' %>
|
37
|
+
"rbenv": {
|
38
|
+
"user_installs": [
|
39
|
+
{ "user": "deploy",
|
40
|
+
"rubies": [{
|
41
|
+
"name": "2.2.3",
|
42
|
+
"environment": {
|
43
|
+
"RUBY_CONFIGURE_OPTS": "--disable-install-doc"
|
44
|
+
}
|
45
|
+
}],
|
46
|
+
"global": "2.2.3"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
},
|
50
|
+
<% end %>
|
30
51
|
|
31
52
|
"postgresql": {
|
32
53
|
"version": "9.4",
|
33
54
|
"enable_pgdg_yum": true,
|
34
55
|
"enable_pgdg_apt": true,
|
35
56
|
"password": {
|
36
|
-
"postgres": "<%= postgresql_admin_password %>"
|
57
|
+
"postgres": "<%= @options.postgresql_admin_password %>"
|
37
58
|
},
|
38
59
|
"users": [
|
39
60
|
{
|
40
|
-
"username": "<%= app_name %>",
|
61
|
+
"username": "<%= @options.app_name %>",
|
41
62
|
"superuser": false,
|
42
63
|
"createdb": false,
|
43
64
|
"login": true,
|
44
|
-
"password": "<%= postgresql_user_password %>"
|
65
|
+
"password": "<%= @options.postgresql_user_password %>"
|
45
66
|
}
|
46
67
|
],
|
47
68
|
"databases": [
|
48
69
|
{
|
49
|
-
"name": "<%= app_name %>",
|
50
|
-
"owner": "<%= app_name %>"
|
70
|
+
"name": "<%= @options.app_name %>",
|
71
|
+
"owner": "<%= @options.app_name %>"
|
51
72
|
}
|
52
73
|
],
|
53
74
|
"pg_hba": [
|
@@ -72,7 +93,7 @@
|
|
72
93
|
},
|
73
94
|
|
74
95
|
"scratchify": {
|
75
|
-
"app_name": "<%= app_name %>"
|
96
|
+
"app_name": "<%= @options.app_name %>"
|
76
97
|
},
|
77
98
|
|
78
99
|
"nginx": {
|
@@ -81,6 +102,6 @@
|
|
81
102
|
},
|
82
103
|
|
83
104
|
"automatic": {
|
84
|
-
"ipaddress": "<%= host %>"
|
105
|
+
"ipaddress": "<%= @options.host %>"
|
85
106
|
}
|
86
107
|
}
|
data/from-scratch.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.10"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency 'rspec', "~> 3.3"
|
24
|
+
spec.add_development_dependency 'rspec-its'
|
24
25
|
spec.add_development_dependency 'pry', "~> 0.10"
|
25
26
|
|
26
27
|
spec.add_dependency 'knife-solo'
|
data/lib/from-scratch.rb
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'erb'
|
3
3
|
require 'fileutils'
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
app_name, host = ARGV
|
8
|
-
ssh_pub_key = `cat ~/.ssh/id_rsa.pub`.strip
|
9
|
-
postgresql_admin_password = `echo -n '#{SecureRandom.base64(16)}''postgres' | openssl md5 | sed -e 's/.* /md5/'`.strip
|
10
|
-
postgresql_user_password = SecureRandom.base64(16)
|
7
|
+
class FromScratch
|
8
|
+
DEFAULTS = { ruby_installer: 'rvm' }
|
11
9
|
|
12
|
-
|
10
|
+
attr_accessor :options
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@options = OpenStruct.new DEFAULTS
|
14
|
+
end
|
15
|
+
|
16
|
+
def run!
|
17
|
+
parse_options
|
18
|
+
get_host_and_app_name
|
19
|
+
generate_values
|
20
|
+
|
21
|
+
{ node: ['nodes', @options.host],
|
22
|
+
user: ['data_bags/users', 'deploy']
|
23
|
+
}.each do |from, to|
|
13
24
|
FileUtils.mkdir_p File.expand_path("../../tmp/#{to[0]}", __FILE__)
|
14
25
|
File.open(File.expand_path("../../tmp/#{to.join('/')}.json", __FILE__), 'w') do |f|
|
15
26
|
f.write ERB.new(File.open(File.expand_path("../../templates/#{from}.json.erb", __FILE__)).read).result(binding)
|
@@ -17,10 +28,41 @@ module FromScratch
|
|
17
28
|
end
|
18
29
|
|
19
30
|
Dir.chdir(File.expand_path('../..', __FILE__)) do
|
20
|
-
system "knife solo bootstrap root@#{host} -c ./.chef/knife.rb"
|
21
|
-
system "knife solo clean root@#{host} -c ./.chef/knife.rb"
|
31
|
+
system "knife solo bootstrap root@#{@options.host} -c ./.chef/knife.rb"
|
32
|
+
system "knife solo clean root@#{@options.host} -c ./.chef/knife.rb"
|
22
33
|
end
|
23
34
|
|
24
35
|
FileUtils.rm_rf [File.expand_path('../../tmp', __FILE__)]
|
25
36
|
end
|
37
|
+
|
38
|
+
def get_host_and_app_name
|
39
|
+
@options.app_name, @options.host = ARGV.select { |x| !(x =~ /^\-/) }
|
40
|
+
|
41
|
+
unless @options.app_name && @options.host
|
42
|
+
raise ArgumentError, 'You should specify APP_NAME and HOST. Use --help for information.'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_options
|
47
|
+
opt_parser = OptionParser.new do |args|
|
48
|
+
args.banner = "Usage: scratchify your_app_name your.host.com [options]"
|
49
|
+
|
50
|
+
args.on '--rbenv', 'Use RBENV instead of RVM' do
|
51
|
+
@options.ruby_installer = 'rbenv'
|
52
|
+
end
|
53
|
+
|
54
|
+
args.on '-h', '--help', 'Prints this help' do
|
55
|
+
puts args
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
opt_parser.parse!
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate_values
|
64
|
+
@options.ssh_pub_key = `cat ~/.ssh/id_rsa.pub`.strip
|
65
|
+
@options.postgresql_admin_password = `echo -n '#{SecureRandom.base64(16)}''postgres' | openssl md5 | sed -e 's/.* /md5/'`.strip
|
66
|
+
@options.postgresql_user_password = SecureRandom.base64(16)
|
67
|
+
end
|
26
68
|
end
|
data/lib/from-scratch/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class FromScratch
|
2
|
+
VERSION = "0.6.0"
|
3
3
|
end
|
data/metadata.rb
CHANGED
data/templates/node.json.erb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"run_list": [
|
3
3
|
"recipe[user::data_bag]",
|
4
|
+
<% if @options.ruby_installer == 'rvm' %>
|
4
5
|
"recipe[scratchify::pre_rvm]",
|
5
6
|
"recipe[rvm::user]",
|
7
|
+
<% elsif @options.ruby_installer == 'rbenv' %>
|
8
|
+
"recipe[ruby_build]",
|
9
|
+
"recipe[ruby_rbenv::user]",
|
10
|
+
<% end %>
|
6
11
|
"recipe[postgresql::server]",
|
7
12
|
"recipe[postgresql::config_pgtune]",
|
8
13
|
"recipe[postgresql::setup_users]",
|
@@ -14,6 +19,7 @@
|
|
14
19
|
|
15
20
|
"users": ["deploy"],
|
16
21
|
|
22
|
+
<% if @options.ruby_installer == 'rvm' %>
|
17
23
|
"rvm": {
|
18
24
|
"user_default_ruby": "2.2.3",
|
19
25
|
"user_install_rubies": true,
|
@@ -27,27 +33,42 @@
|
|
27
33
|
],
|
28
34
|
"gpg": {}
|
29
35
|
},
|
36
|
+
<% elsif @options.ruby_installer == 'rbenv' %>
|
37
|
+
"rbenv": {
|
38
|
+
"user_installs": [
|
39
|
+
{ "user": "deploy",
|
40
|
+
"rubies": [{
|
41
|
+
"name": "2.2.3",
|
42
|
+
"environment": {
|
43
|
+
"RUBY_CONFIGURE_OPTS": "--disable-install-doc"
|
44
|
+
}
|
45
|
+
}],
|
46
|
+
"global": "2.2.3"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
},
|
50
|
+
<% end %>
|
30
51
|
|
31
52
|
"postgresql": {
|
32
53
|
"version": "9.4",
|
33
54
|
"enable_pgdg_yum": true,
|
34
55
|
"enable_pgdg_apt": true,
|
35
56
|
"password": {
|
36
|
-
"postgres": "<%= postgresql_admin_password %>"
|
57
|
+
"postgres": "<%= @options.postgresql_admin_password %>"
|
37
58
|
},
|
38
59
|
"users": [
|
39
60
|
{
|
40
|
-
"username": "<%= app_name %>",
|
61
|
+
"username": "<%= @options.app_name %>",
|
41
62
|
"superuser": false,
|
42
63
|
"createdb": false,
|
43
64
|
"login": true,
|
44
|
-
"password": "<%= postgresql_user_password %>"
|
65
|
+
"password": "<%= @options.postgresql_user_password %>"
|
45
66
|
}
|
46
67
|
],
|
47
68
|
"databases": [
|
48
69
|
{
|
49
|
-
"name": "<%= app_name %>",
|
50
|
-
"owner": "<%= app_name %>"
|
70
|
+
"name": "<%= @options.app_name %>",
|
71
|
+
"owner": "<%= @options.app_name %>"
|
51
72
|
}
|
52
73
|
],
|
53
74
|
"pg_hba": [
|
@@ -72,7 +93,7 @@
|
|
72
93
|
},
|
73
94
|
|
74
95
|
"scratchify": {
|
75
|
-
"app_name": "<%= app_name %>"
|
96
|
+
"app_name": "<%= @options.app_name %>"
|
76
97
|
},
|
77
98
|
|
78
99
|
"nginx": {
|
@@ -81,6 +102,6 @@
|
|
81
102
|
},
|
82
103
|
|
83
104
|
"automatic": {
|
84
|
-
"ipaddress": "<%= host %>"
|
105
|
+
"ipaddress": "<%= @options.host %>"
|
85
106
|
}
|
86
107
|
}
|