-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
161 lines (148 loc) · 5 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env rake
require 'rake'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |task|
task.rspec_opts = '--color'
end
rescue LoadError
warn 'It looks like the Chef DK is not configured. Download the Chef DK'\
" via\nhttps://downloads.getchef.com/chef-dk. On Linux and Mac OS X"\
" add to $PATH with:\n"\
' eval "$(chef shell-init bash)"'
end
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new do |task|
task.fail_on_error = true
task.options = %w(--display-cop-names)
end
rescue LoadError
warn '>>>>> Rubocop gem not loaded, omitting tasks'
end
begin
require 'foodcritic/rake_task'
require 'foodcritic'
task default: [:foodcritic]
FoodCritic::Rake::LintTask.new do |task|
task.options = {
fail_tags: ['any'],
tags: ['~FC015']
}
end
rescue LoadError
warn '>>>>> foodcritic gem not loaded, omitting tasks'
end
task default: 'test:quick'
namespace :test do
desc 'Run all the quick tests.'
task :quick do
Rake::Task['rubocop'].invoke
Rake::Task['foodcritic'].invoke
Rake::Task['spec'].invoke
end
end
desc 'Bootstrap with chef-solo'
task :bootstrap do
sh 'rm -rf cookbooks && berks vendor cookbooks'
sh 'sudo chef-solo --json-attributes bootstrap/standalone.json'\
' --config bootstrap/solo.rb'
end
unless ENV['CI']
begin
require 'kitchen/rake_tasks'
Kitchen::RakeTasks.new
desc 'Run _all_ the tests. Go get a coffee.'
task :complete do
Rake::Task['test:quick'].invoke
Rake::Task['test:kitchen:all'].invoke
end
rescue LoadError
puts '>>>>> Kitchen gem not loaded, omitting tasks'
end
end
unless ENV['CI']
namespace :standalone do
require 'kitchen'
@centos_instances = []
@centos_enterprise_instances = []
@ubuntu_instances = []
@ubuntu_enterprise_instances = []
@config = Kitchen::Config.new
@centos_names = %w(node1-centos65 node2-centos65 standalone-centos65)
@centos_enterprise_names = %w(node1-enterprise-centos65
node2-enterprise-centos65
standalone-enterprise-centos65)
@ubuntu_names = %w(node1-ubuntu1404 node2-ubuntu1404 standalone-ubuntu1404)
@ubuntu_enterprise_names = %w(node1-enterprise-ubuntu1404
node2-enterprise-ubuntu1404
standalone-enterprise-ubuntu1404)
@centos_names.each do |name|
@centos_instances << @config.instances.get(name)
end
@centos_enterprise_names.each do |name|
@centos_enterprise_instances << @config.instances.get(name)
end
@ubuntu_names.each do |name|
@ubuntu_instances << @config.instances.get(name)
end
@ubuntu_enterprise_names.each do |name|
@ubuntu_enterprise_instances << @config.instances.get(name)
end
@centos_backend_name = 'standalone-centos65'
@centos_enterprise_backend_name = 'standalone-enterprise-centos65'
@ubuntu_backend_name = 'standalone-ubuntu1404'
@ubuntu_enterprise_backend_name = 'standalone-enterprise-ubuntu1404'
desc 'login to standalone server'
task :login, :platform do |_t, args|
platform = args[:platform] || 'centos'
case platform
when 'centos' then config.instances.get(@centos_backend_name).login
when 'centos-enterprise'
@config.instances.get(@centos_enterprise_backend_name).login
when 'ubuntu' then config.instances.get(@ubuntu_backend_name).login
when 'ubuntu-enterprise'
@config.instances.get(@ubuntu_enterprise_backend_name).login
end
end
desc 'create standalone cluster'
task :create, :platform do |_t, args|
platform = args[:platform] || 'centos'
case platform
when 'centos' then @centos_instances.each(&:create)
when 'centos-enterprise'
@centos_enterprise_instances.each(&:create)
when 'ubuntu' then @ubuntu_instances.each(&:create)
when 'ubuntu-enterprise'
@ubuntu_enterprise_instances.each(&:create)
else @centos_instances.each(&:create)
end
end
desc 'destroy standalone cluster'
task :destroy, :platform do |_t, args|
platform = args[:platform] || 'centos'
case platform
when 'centos' then @centos_instances.each(&:destroy)
when 'centos-enterprise'
@centos_enterprise_instances.each(&:destroy)
when 'ubuntu' then @ubuntu_instances.each(&:destroy)
when 'ubuntu-enterprise'
@ubuntu_enterprise_instances.each(&:destroy)
else @centos_instances.each(&:destroy)
end
end
desc 'converge standalone cluster'
task :converge, :platform do |_t, args|
platform = args[:platform] || 'centos'
case platform
when 'centos' then @centos_instances.each(&:converge)
when 'centos-enterprise'
@centos_enterprise_instances.each(&:converge)
when 'ubuntu' then @ubuntu_instances.each(&:converge)
when 'ubuntu-enterprise'
@ubuntu_enterprise_instances.each(&:converge)
else @centos_instances.each(&:converge)
end
end
end
end