machines 0.5.4 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +7 -1
- data/CHANGELOG.md +16 -4
- data/INSTALL.md +3 -0
- data/LICENSE +1 -2
- data/README.md +47 -28
- data/Rakefile +0 -8
- data/TODO.md +66 -59
- data/bin/machines +1 -2
- data/lib/machines.rb +16 -1
- data/lib/machines/app_settings.rb +1 -1
- data/lib/machines/cloud_machine.rb +1 -1
- data/lib/machines/command.rb +0 -2
- data/lib/machines/commandline.rb +23 -29
- data/lib/machines/commands/checks.rb +67 -0
- data/lib/machines/commands/configuration.rb +50 -0
- data/lib/machines/commands/database.rb +18 -0
- data/lib/machines/commands/file_operations.rb +105 -0
- data/lib/machines/commands/installation.rb +184 -0
- data/lib/machines/commands/questions.rb +16 -0
- data/lib/machines/commands/services.rb +26 -0
- data/lib/machines/core.rb +55 -25
- data/lib/machines/logger.rb +0 -2
- data/lib/machines/named_buffer.rb +7 -6
- data/lib/machines/version.rb +1 -1
- data/lib/packages/awstats.rb +2 -2
- data/lib/packages/docky.rb +0 -1
- data/lib/packages/dwm.rb +5 -0
- data/lib/packages/nginx_logrotate.rb +2 -2
- data/lib/packages/timezone.rb +2 -4
- data/lib/template/Machinesfile +2 -1
- data/lib/template/config.yml +3 -0
- data/spec/lib/machines/app_settings_spec.rb +13 -12
- data/spec/lib/machines/cloud_machine_spec.rb +9 -8
- data/spec/lib/machines/commandline_spec.rb +69 -90
- data/spec/lib/machines/{checks_spec.rb → commands/checks_spec.rb} +1 -1
- data/spec/lib/machines/{configuration_spec.rb → commands/configuration_spec.rb} +2 -3
- data/spec/lib/machines/{database_spec.rb → commands/database_spec.rb} +4 -10
- data/spec/lib/machines/{file_operations_spec.rb → commands/file_operations_spec.rb} +3 -7
- data/spec/lib/machines/{installation_spec.rb → commands/installation_spec.rb} +10 -4
- data/spec/lib/machines/{questions_spec.rb → commands/questions_spec.rb} +1 -3
- data/spec/lib/machines/{services_spec.rb → commands/services_spec.rb} +1 -4
- data/spec/lib/machines/core_spec.rb +81 -65
- data/spec/lib/packages/abiword_spec.rb +1 -5
- data/spec/lib/packages/amazon_mp3_spec.rb +0 -4
- data/spec/lib/packages/awstats_spec.rb +3 -4
- data/spec/lib/packages/base_spec.rb +0 -1
- data/spec/lib/packages/chrome_spec.rb +0 -4
- data/spec/lib/packages/cruisecontrol_spec.rb +1 -2
- data/spec/lib/packages/dependencies_spec.rb +1 -2
- data/spec/lib/packages/docky_spec.rb +0 -4
- data/spec/lib/packages/dotfiles_spec.rb +5 -4
- data/spec/lib/packages/dwm_spec.rb +23 -0
- data/spec/lib/packages/file_roller_spec.rb +1 -5
- data/spec/lib/packages/firefox_spec.rb +0 -4
- data/spec/lib/packages/gedit_spec.rb +1 -5
- data/spec/lib/packages/git_spec.rb +0 -4
- data/spec/lib/packages/gmate_spec.rb +1 -5
- data/spec/lib/packages/gnome_spec.rb +0 -4
- data/spec/lib/packages/gnumeric_spec.rb +1 -5
- data/spec/lib/packages/hosts_spec.rb +0 -1
- data/spec/lib/packages/load_machines_spec.rb +16 -15
- data/spec/lib/packages/monit_spec.rb +0 -1
- data/spec/lib/packages/mysql_spec.rb +1 -3
- data/spec/lib/packages/nginx_logrotate_spec.rb +17 -18
- data/spec/lib/packages/nginx_spec.rb +0 -1
- data/spec/lib/packages/openbox_spec.rb +0 -4
- data/spec/lib/packages/passenger_nginx_spec.rb +0 -1
- data/spec/lib/packages/passenger_spec.rb +0 -1
- data/spec/lib/packages/postfix_spec.rb +1 -5
- data/spec/lib/packages/questions_spec.rb +3 -4
- data/spec/lib/packages/rbenv_spec.rb +1 -4
- data/spec/lib/packages/rvm_spec.rb +1 -4
- data/spec/lib/packages/save_machines_spec.rb +0 -1
- data/spec/lib/packages/slim_spec.rb +1 -2
- data/spec/lib/packages/sqlserver_spec.rb +0 -4
- data/spec/lib/packages/timezone_spec.rb +2 -3
- data/spec/lib/packages/unison_spec.rb +1 -2
- data/spec/lib/packages/virtualbox_guest_spec.rb +0 -4
- data/spec/lib/packages/virtualbox_spec.rb +1 -2
- data/spec/lib/packages/webapps_spec.rb +1 -3
- data/spec/spec_helper.rb +59 -61
- data/spec/support/minitest.rb +4 -62
- metadata +27 -28
- data/lib/machines/base.rb +0 -13
- data/lib/machines/checks.rb +0 -63
- data/lib/machines/configuration.rb +0 -49
- data/lib/machines/database.rb +0 -17
- data/lib/machines/file_operations.rb +0 -104
- data/lib/machines/installation.rb +0 -171
- data/lib/machines/machinesfile.rb +0 -25
- data/lib/machines/questions.rb +0 -15
- data/lib/machines/services.rb +0 -24
- data/spec/lib/machines/machinesfile_spec.rb +0 -34
@@ -2,14 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'packages/awstats' do
|
4
4
|
before(:each) do
|
5
|
-
|
6
|
-
$conf.webapps = {'name' => AppBuilder.new({:name => 'appname', :path => 'apppath'})}
|
5
|
+
$conf.webapps = {'name' => AppSettings::AppBuilder.new({:name => 'appname', :path => 'apppath'})}
|
7
6
|
FileUtils.mkdir('misc')
|
8
|
-
|
7
|
+
FileUtils.touch('misc/awstats.conf.erb')
|
8
|
+
eval_package
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'adds the following commands' do
|
12
|
-
eval_package
|
13
12
|
$conf.commands.map(&:info).join("\n").must_equal [
|
14
13
|
"TASK awstats - Install AWStats",
|
15
14
|
"SUDO apt-get -q -y install awstats",
|
@@ -2,10 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'packages/cruisecontrol' do
|
4
4
|
before(:each) do
|
5
|
-
load_package('cruisecontrol')
|
6
5
|
$conf.from_hash(ruby: {gems_path: 'ruby/gems'})
|
7
6
|
$conf.webapps = {'application' =>
|
8
|
-
AppBuilder.new(
|
7
|
+
AppSettings::AppBuilder.new(
|
9
8
|
'scm' => 'github.com/project',
|
10
9
|
'title' => 'Application'
|
11
10
|
)
|
@@ -2,12 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'packages/dependencies' do
|
4
4
|
before(:each) do
|
5
|
-
load_package('dependencies')
|
6
5
|
$conf.hostname = 'hostname'
|
6
|
+
eval_package
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'adds the following commands' do
|
10
|
-
eval_package
|
11
10
|
$conf.commands.map(&:info).must_equal [
|
12
11
|
"TASK dependencies - Dependencies required for various commands to run",
|
13
12
|
"SUDO apt-get -q -y update > /tmp/apt-update.log",
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'packages/dotfiles' do
|
4
4
|
before(:each) do
|
5
|
-
load_package('dotfiles')
|
6
5
|
$conf.machine = AppConf.new
|
7
6
|
$conf.machine.user = 'username'
|
8
7
|
$conf.appsroot = 'appsroot'
|
@@ -18,7 +17,7 @@ describe 'packages/dotfiles' do
|
|
18
17
|
eval_package
|
19
18
|
$conf.commands.map(&:info).join("\n").must_equal [
|
20
19
|
"TASK dotfiles - Upload users/username/dotfiles and set some env vars",
|
21
|
-
"UPLOAD
|
20
|
+
"UPLOAD users/username/dotfiles/bashrc to .bashrc",
|
22
21
|
"RUN mkdir -p $HOME/.ssh",
|
23
22
|
"RUN chmod 700 $HOME/.ssh",
|
24
23
|
"RUN ssh-keyscan -H somehost >> $HOME/.ssh/known_hosts",
|
@@ -32,13 +31,15 @@ describe 'packages/dotfiles' do
|
|
32
31
|
it 'sets RAILS_ENV when specified in set_rails_env_for' do
|
33
32
|
$conf.set_rails_env_for = ['railsenv']
|
34
33
|
eval_package
|
35
|
-
|
34
|
+
expected = /RUN grep \"export RAILS_ENV=railsenv\" .profile || echo \"export RAILS_ENV=railsenv\" >> .profile/
|
35
|
+
$conf.commands.map(&:info).join("\n").must_match expected
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'RAILS_ENV not set when not specified in set_rails_env_for' do
|
39
39
|
$conf.set_rails_env_for = ['some_other_env']
|
40
40
|
eval_package
|
41
|
-
|
41
|
+
expected = /RUN grep \"export RAILS_ENV=railsenv\" .profile \|\| echo \"export RAILS_ENV=railsenv\" >> .profile/
|
42
|
+
$conf.commands.map(&:info).join("\n").wont_match expected
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'packages/dwm' do
|
4
|
+
before do
|
5
|
+
$conf.dwm = AppConf.new
|
6
|
+
$conf.dwm.version = '6.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'adds the following commands' do
|
10
|
+
eval_package
|
11
|
+
$conf.commands.map(&:info).join("\n").must_equal [
|
12
|
+
"TASK dwm - Download, compile and install dwm",
|
13
|
+
"SUDO apt-get -q -y install build-essential",
|
14
|
+
"SUDO apt-get -q -y install libx11-dev",
|
15
|
+
"SUDO apt-get -q -y install libxinerama-dev",
|
16
|
+
"SUDO apt-get -q -y install sharutils",
|
17
|
+
"SUDO cd /tmp && wget http://dl.suckless.org/dwm/dwm-6.0.tar.gz && tar -zxf dwm-6.0.tar.gz && rm dwm-6.0.tar.gz && cd -",
|
18
|
+
"SUDO mv -f /tmp/dwm-6.0 /usr/local/src",
|
19
|
+
"SUDO cd /usr/local/src/dwm-6.0 && make clean install"
|
20
|
+
].join("\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'packages/
|
4
|
-
before(:each) do
|
5
|
-
load_package('file_roller')
|
6
|
-
end
|
7
|
-
|
3
|
+
describe 'packages/file_roller' do
|
8
4
|
def append_command text
|
9
5
|
"RUN grep \"#{text}\" .local/share/applications/mimeapps.list || echo \"#{text}\" >> .local/share/applications/mimeapps.list"
|
10
6
|
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'packages/gmate' do
|
4
|
-
before(:each) do
|
5
|
-
load_package('gmate')
|
6
|
-
$conf.appsroot = 'apps_root'
|
7
|
-
end
|
8
|
-
|
9
4
|
it 'adds the following commands' do
|
5
|
+
$conf.appsroot = 'apps_root'
|
10
6
|
eval_package
|
11
7
|
$conf.commands.map(&:info).must_equal [
|
12
8
|
"TASK gmate - Clone and install gmate for gEdit from Github and set some preferences and plugins",
|
@@ -1,21 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'packages/load_machines' do
|
4
|
-
let(:settings)
|
4
|
+
let(:settings) {
|
5
5
|
{'machines' => {'a_machine' => {'hostname' => 'something', 'user' => 'phil', 'address' => '1.2.3.4'}}}
|
6
|
-
|
6
|
+
}
|
7
7
|
|
8
8
|
def save_settings
|
9
9
|
File.open('machines.yml', 'w') {|f| f.puts settings.to_yaml }
|
10
10
|
end
|
11
11
|
|
12
12
|
before(:each) do
|
13
|
-
load_package('load_machines')
|
14
13
|
$conf.machine_name = 'a_machine'
|
15
14
|
$conf.from_hash('appsroots' => {'phil' => '/home/phil'})
|
16
|
-
stubs(:load_app_settings)
|
17
|
-
stubs(:connect)
|
18
|
-
stubs(:run_instance)
|
15
|
+
core.stubs(:load_app_settings)
|
16
|
+
core.stubs(:connect)
|
17
|
+
core.stubs(:run_instance)
|
19
18
|
end
|
20
19
|
|
21
20
|
describe 'loading machines.yml' do
|
@@ -46,10 +45,13 @@ describe 'packages/load_machines' do
|
|
46
45
|
end
|
47
46
|
|
48
47
|
describe 'setting address' do
|
48
|
+
#TODO: should move from load_machines
|
49
|
+
class Core::ConfigError < StandardError; end
|
50
|
+
|
49
51
|
it 'raises an exception when no address' do
|
50
52
|
settings['machines']['a_machine']['address'] = nil
|
51
53
|
save_settings
|
52
|
-
lambda { eval_package }.must_raise ConfigError
|
54
|
+
lambda { eval_package }.must_raise Core::ConfigError
|
53
55
|
end
|
54
56
|
|
55
57
|
describe 'when EC2' do
|
@@ -59,29 +61,29 @@ describe 'packages/load_machines' do
|
|
59
61
|
|
60
62
|
it 'does not throw or connect when address set' do
|
61
63
|
save_settings
|
62
|
-
expects(:connect).never
|
64
|
+
core.expects(:connect).never
|
63
65
|
eval_package
|
64
66
|
end
|
65
67
|
|
66
68
|
it 'starts a new instance when no address' do
|
67
69
|
settings['machines']['a_machine']['address'] = nil
|
68
70
|
save_settings
|
69
|
-
expects(:connect).returns true
|
70
|
-
expects(:run_instance)
|
71
|
+
core.expects(:connect).returns true
|
72
|
+
core.expects(:run_instance)
|
71
73
|
eval_package
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
78
|
it 'sets root_pass when not set' do
|
77
|
-
stubs(:generate_password).returns '1234'
|
79
|
+
core.stubs(:generate_password).returns '1234'
|
78
80
|
save_settings
|
79
81
|
eval_package
|
80
82
|
$conf.machines.a_machine.root_pass.must_equal '1234'
|
81
83
|
end
|
82
84
|
|
83
85
|
it 'sets $conf.machines_changed when passwords are generated' do
|
84
|
-
stubs(:generate_password).returns '1234'
|
86
|
+
core.stubs(:generate_password).returns '1234'
|
85
87
|
save_settings
|
86
88
|
eval_package
|
87
89
|
$conf.machines_changed.wont_equal nil
|
@@ -95,7 +97,7 @@ describe 'packages/load_machines' do
|
|
95
97
|
end
|
96
98
|
|
97
99
|
it 'does not overwrite root_pass' do
|
98
|
-
expects(:generate_password).never
|
100
|
+
core.expects(:generate_password).never
|
99
101
|
settings['machines']['a_machine']['root_pass'] = 'something'
|
100
102
|
save_settings
|
101
103
|
eval_package
|
@@ -111,8 +113,7 @@ describe 'packages/load_machines' do
|
|
111
113
|
it 'loads app settings' do
|
112
114
|
settings['machines']['a_machine']['apps'] = ['app1', 'app2']
|
113
115
|
save_settings
|
114
|
-
expects(:load_app_settings).with(['app1', 'app2'])
|
116
|
+
core.expects(:load_app_settings).with(['app1', 'app2'])
|
115
117
|
eval_package
|
116
118
|
end
|
117
119
|
end
|
118
|
-
|
@@ -2,8 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'packages/mysql' do
|
4
4
|
before(:each) do
|
5
|
-
load_package('mysql')
|
6
|
-
|
7
5
|
$conf.from_hash(:machine => {
|
8
6
|
:address => 'DB_IP',
|
9
7
|
:root_pass => 'DB_PASS',
|
@@ -38,7 +36,7 @@ describe 'packages/mysql' do
|
|
38
36
|
describe 'dbmaster role' do
|
39
37
|
it 'sets permissions for each app to access database and grants replication rights for slave' do
|
40
38
|
$conf.roles = :dbmaster
|
41
|
-
$conf.webapps = {'name' => AppBuilder.new({:name => 'name', :password => 'PASSWORD'})}
|
39
|
+
$conf.webapps = {'name' => AppSettings::AppBuilder.new({:name => 'name', :password => 'PASSWORD'})}
|
42
40
|
eval_package
|
43
41
|
$conf.commands.map(&:info).must_equal [
|
44
42
|
"TASK dbperms - Grant applications access to the database",
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'packages/nginx_logrotate' do
|
4
4
|
before(:each) do
|
5
|
-
|
6
|
-
$conf.webapps = {'name' => AppBuilder.new({:name => 'appname', :path => 'apppath'})}
|
5
|
+
$conf.webapps = {'name' => AppSettings::AppBuilder.new({:name => 'appname', :path => 'apppath'})}
|
7
6
|
FileUtils.mkdir_p 'logrotate'
|
8
7
|
File.open('logrotate/nginx.erb', 'w') {|f| f.puts 'nginx template' }
|
9
8
|
File.open('logrotate/app.erb', 'w') {|f| f.puts 'app template' }
|
@@ -28,51 +27,51 @@ describe 'packages/nginx_logrotate' do
|
|
28
27
|
|
29
28
|
describe 'nginx logs template' do
|
30
29
|
before(:each) do
|
30
|
+
skip
|
31
31
|
nginx_template = nil
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
FakeFS.deactivate!
|
33
|
+
nginx_template = File.read 'lib/template/logrotate/nginx.erb'
|
34
|
+
FakeFS.activate!
|
35
35
|
File.open('logrotate/nginx.erb', 'w') {|f| f.puts nginx_template }
|
36
36
|
end
|
37
37
|
|
38
38
|
describe 'when awstats set' do
|
39
39
|
it 'generates stats command' do
|
40
|
-
skip
|
41
40
|
settings = stub 'AppBuilder'
|
42
41
|
stats_prerotate = '/usr/lib/cgi-bin/awstats.pl -update -config=appname stats_path/appname > /dev/null'
|
43
42
|
stats_postrotate = '/usr/local/bin/awstats_render riskplatform.insidemedia.net /home/risk/riskplatform_stats/public > /dev/null'
|
44
43
|
options = {:log_path => '/var/log/nginx/appname.access.log', stats_prerotate: stats_prerotate, stats_postrotate: stats_postrotate}
|
45
|
-
AppBuilder.stubs(:new)
|
46
|
-
AppBuilder.expects(:new).with(options).returns settings
|
44
|
+
AppSettings::AppBuilder.stubs(:new)
|
45
|
+
AppSettings::AppBuilder.expects(:new).with(options).returns settings
|
47
46
|
options = {:log_path => '/var/log/nginx/appname.error.log', stats_prerotate: nil, stats_postrotate: nil}
|
48
|
-
AppBuilder.expects(:new).with(options).returns settings
|
47
|
+
AppSettings::AppBuilder.expects(:new).with(options).returns settings
|
49
48
|
options = {:settings => settings, :to => '/etc/logrotate.d/appname_nginx_access'}
|
50
|
-
expects(:create_from).with('logrotate/nginx.erb', options).returns
|
49
|
+
core.expects(:create_from).with('logrotate/nginx.erb', options).returns Command.new 'command', 'check'
|
51
50
|
eval_package
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
54
|
describe 'when awstats not set' do
|
56
55
|
it 'does not generate stats command' do
|
57
|
-
skip
|
58
56
|
settings = stub 'AppBuilder'
|
59
|
-
AppBuilder.stubs(:new)
|
57
|
+
AppSettings::AppBuilder.stubs(:new)
|
60
58
|
options = {:log_path => '/var/log/nginx/appname.access.log', :stats_command => nil}
|
61
|
-
AppBuilder.expects(:new).with(options).returns settings
|
59
|
+
AppSettings::AppBuilder.expects(:new).with(options).returns settings
|
62
60
|
options = {:settings => settings, :to => '/etc/logrotate.d/appname_nginx_access'}
|
63
|
-
expects(:create_from).with('logrotate/nginx.erb', options).returns Command.new 'command', 'check'
|
61
|
+
core.expects(:create_from).with('logrotate/nginx.erb', options).returns Command.new 'command', 'check'
|
64
62
|
eval_package
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
66
|
+
|
68
67
|
describe 'apps logs template' do
|
69
68
|
it 'generates correct template' do
|
70
69
|
mock_settings = mock 'AppBuilder'
|
71
|
-
stubs(:create_from).returns Machines::Command.new 'command', 'check'
|
72
|
-
AppBuilder.stubs(:new)
|
73
|
-
AppBuilder.expects(:new).with(:log_path => 'apppath/shared/log/*.log').returns mock_settings
|
70
|
+
core.stubs(:create_from).returns Machines::Command.new 'command', 'check'
|
71
|
+
AppSettings::AppBuilder.stubs(:new)
|
72
|
+
AppSettings::AppBuilder.expects(:new).with(:log_path => 'apppath/shared/log/*.log').returns mock_settings
|
74
73
|
options = {:settings => mock_settings, :to => '/etc/logrotate.d/appname_app'}
|
75
|
-
expects(:create_from).with('logrotate/app.erb', options).returns
|
74
|
+
core.expects(:create_from).with('logrotate/app.erb', options).returns Command.new 'command', 'check'
|
76
75
|
eval_package
|
77
76
|
end
|
78
77
|
end
|