ec2launcher 1.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/ec2launcher +34 -0
- data/ec2launcher.gemspec +18 -0
- data/lib/ec2launcher/application.rb +262 -0
- data/lib/ec2launcher/block_device.rb +91 -0
- data/lib/ec2launcher/block_device_builder.rb +270 -0
- data/lib/ec2launcher/config.rb +76 -0
- data/lib/ec2launcher/defaults.rb +9 -0
- data/lib/ec2launcher/email_notification.rb +62 -0
- data/lib/ec2launcher/environment.rb +179 -0
- data/lib/ec2launcher/init_options.rb +166 -0
- data/lib/ec2launcher/version.rb +6 -0
- data/lib/ec2launcher.rb +734 -0
- data/startup-scripts/setup.rb +154 -0
- data/startup-scripts/setup_instance.rb +340 -0
- metadata +81 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sean Laurent
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Ec2launcher
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ec2launcher'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ec2launcher
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/ec2launcher
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2012 Sean Laurent
|
4
|
+
#
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
require 'ec2launcher'
|
8
|
+
require "ec2launcher/init_options"
|
9
|
+
|
10
|
+
opt_parser = InitOptions.new
|
11
|
+
opt_parser.parse(ARGV)
|
12
|
+
|
13
|
+
if opt_parser.command == "init"
|
14
|
+
if File.exists?(opt_parser.location)
|
15
|
+
puts "ERROR! Location '#{opt_parser.location} already exists!"
|
16
|
+
exit 2
|
17
|
+
end
|
18
|
+
Dir.mkdir(opt_parser.location)
|
19
|
+
Dir.chdir(opt_parser.location)
|
20
|
+
|
21
|
+
Dir.mkdir("applications")
|
22
|
+
Dir.mkdir("environments")
|
23
|
+
|
24
|
+
new_config_template = ERB.new(EC2Launcher::Config::DEFAULT_CONFIG_ERB)
|
25
|
+
File.open("config.rb", 'w') {|f| f.write(new_config_template.result)}
|
26
|
+
|
27
|
+
puts "Successfully created #{opt_parser.location}"
|
28
|
+
elsif opt_parser.command == "launch"
|
29
|
+
launcher = EC2Launcher::Launcher.new
|
30
|
+
launcher.launch(opt_parser.options)
|
31
|
+
else
|
32
|
+
opt_parser.help
|
33
|
+
exit 1
|
34
|
+
end
|
data/ec2launcher.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ec2launcher/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Sean Laurent"]
|
6
|
+
gem.description = %q{Tool to manage application configurations and launch new EC2 instances based on the configurations.}
|
7
|
+
gem.summary = %q{Tool to launch EC2 instances.}
|
8
|
+
gem.homepage = "https://github.com/StudyBlue/ec2launcher"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "ec2launcher"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Ec2launcher::VERSION
|
16
|
+
|
17
|
+
gem.add_runtime_dependency "aws-sdk", [">= 1.5.0"]
|
18
|
+
end
|
@@ -0,0 +1,262 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Sean Laurent
|
3
|
+
#
|
4
|
+
require 'ec2launcher/block_device'
|
5
|
+
require 'ec2launcher/email_notification'
|
6
|
+
|
7
|
+
class ApplicationDSL
|
8
|
+
attr_accessor :applications
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.applications = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def application(name, &block)
|
15
|
+
application = Application.new(name)
|
16
|
+
applications << application
|
17
|
+
application.instance_eval &block
|
18
|
+
application
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.execute(dsl)
|
22
|
+
new.tap do |context|
|
23
|
+
context.instance_eval(dsl)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Application
|
29
|
+
include EmailNotifications
|
30
|
+
|
31
|
+
attr_reader :name
|
32
|
+
|
33
|
+
def initialize(name)
|
34
|
+
@name = name
|
35
|
+
@email_notifications = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def application(name)
|
39
|
+
@name = name
|
40
|
+
yield self
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def ami_name(*ami_name)
|
45
|
+
if ami_name.empty?
|
46
|
+
@ami_name
|
47
|
+
else
|
48
|
+
if ami_name[0].kind_of? String
|
49
|
+
@ami_name = /#{ami_name[0]}/
|
50
|
+
else
|
51
|
+
@ami_name = ami_name[0]
|
52
|
+
end
|
53
|
+
self
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def availability_zone(*zone)
|
58
|
+
if zone.empty?
|
59
|
+
@availability_zone
|
60
|
+
else
|
61
|
+
@availability_zone = zone[0].to_s
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def basename(*name)
|
67
|
+
if name.empty?
|
68
|
+
@basename
|
69
|
+
else
|
70
|
+
@basename = name[0]
|
71
|
+
self
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def block_devices(*block_device_data)
|
76
|
+
if block_device_data.empty?
|
77
|
+
@block_devices
|
78
|
+
else
|
79
|
+
self
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def block_device(&block)
|
84
|
+
@block_devices = [] if @block_devices.nil?
|
85
|
+
device = BlockDevice.new
|
86
|
+
device.instance_exec(&block)
|
87
|
+
@block_devices << device
|
88
|
+
end
|
89
|
+
|
90
|
+
def elb(*elb)
|
91
|
+
if elb.empty?
|
92
|
+
@elb
|
93
|
+
else
|
94
|
+
@elb = Hash.new if @elb.nil?
|
95
|
+
if elb[0].kind_of? Hash
|
96
|
+
elb[0].keys.each {|key| @elb[key] = elb[0][key]}
|
97
|
+
else
|
98
|
+
@elb["default"] = elb[0].to_s
|
99
|
+
end
|
100
|
+
self
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def elb_for_environment(environment)
|
105
|
+
elb_name = @elb[environment]
|
106
|
+
elb_name ||= @elb["default"]
|
107
|
+
elb_name
|
108
|
+
end
|
109
|
+
|
110
|
+
def environment_roles(*data)
|
111
|
+
if data.empty?
|
112
|
+
@environment_roles
|
113
|
+
else
|
114
|
+
@environment_roles = Hash.new if @environment_roles.nil?
|
115
|
+
env_name = data[0]
|
116
|
+
env_roles = data[1]
|
117
|
+
|
118
|
+
environment_data = @environment_roles[env_name]
|
119
|
+
environment_data ||= []
|
120
|
+
|
121
|
+
if env_roles.kind_of? Array
|
122
|
+
environment_data += env_roles
|
123
|
+
else
|
124
|
+
environment_data << env_roles
|
125
|
+
end
|
126
|
+
@environment_roles[env_name] = environment_data
|
127
|
+
|
128
|
+
self
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def gems(*gems)
|
133
|
+
if gems.empty?
|
134
|
+
@gems
|
135
|
+
else
|
136
|
+
@gems = gems[0]
|
137
|
+
self
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def inherit(*inherit_type)
|
142
|
+
if inherit_type.empty?
|
143
|
+
@inherit_type
|
144
|
+
else
|
145
|
+
@inherit_type = inherit_type[0]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def instance_type(*type_name)
|
150
|
+
if type_name.empty?
|
151
|
+
@instance_type
|
152
|
+
else
|
153
|
+
@instance_type = type_name[0]
|
154
|
+
self
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Takes values from the other server type and merges them into this one
|
159
|
+
def merge(other_server)
|
160
|
+
@name = other_server.name
|
161
|
+
@ami_name = other_server.ami_name unless other_server.ami_name.nil?
|
162
|
+
@availability_zone = other_server.availability_zone unless other_server.availability_zone.nil?
|
163
|
+
@basename = other_server.basename unless other_server.basename.nil?
|
164
|
+
other_server.block_devices.each {|bd| @block_devices << bd } unless other_server.block_devices.nil?
|
165
|
+
other_server.elb.keys.each {|env_name| @elb[env_name] = other_server.elb[env_name] } unless other_server.elb.nil?
|
166
|
+
@instance_type = other_server.instance_type unless other_server.instance_type.nil?
|
167
|
+
@name_suffix = other_server.name_suffix unless other_server.name_suffix.nil?
|
168
|
+
other_server.roles.each {|role| @roles << role } unless other_server.roles.nil?
|
169
|
+
unless other_server.security_groups.nil?
|
170
|
+
other_server.security_groups.keys.each do |env_name|
|
171
|
+
unless @security_groups.has_key? env_name
|
172
|
+
@security_groups[env_name] = []
|
173
|
+
end
|
174
|
+
other_server.security_groups[env_name].each {|sg| @security_groups[env_name] << sg }
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def name_suffix(*suffix)
|
180
|
+
if suffix.empty?
|
181
|
+
@name_suffix
|
182
|
+
else
|
183
|
+
@name_suffix = suffix[0]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def packages(*packages)
|
188
|
+
if packages.empty?
|
189
|
+
@packages
|
190
|
+
else
|
191
|
+
@packages = packages[0]
|
192
|
+
self
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def roles(*roles)
|
197
|
+
if roles.empty?
|
198
|
+
@roles
|
199
|
+
else
|
200
|
+
@roles = [] if @roles.nil?
|
201
|
+
if roles[0].kind_of? Array
|
202
|
+
@roles += roles[0]
|
203
|
+
else
|
204
|
+
@roles = []
|
205
|
+
@roles << roles[0]
|
206
|
+
end
|
207
|
+
self
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def roles_for_environment(environment)
|
212
|
+
roles = []
|
213
|
+
roles += @roles unless @roles.nil?
|
214
|
+
|
215
|
+
unless @environment_roles.nil? || @environment_roles[environment].nil?
|
216
|
+
roles += @environment_roles[environment]
|
217
|
+
end
|
218
|
+
roles
|
219
|
+
end
|
220
|
+
|
221
|
+
def security_groups(*groups)
|
222
|
+
if groups.empty?
|
223
|
+
@security_groups
|
224
|
+
else
|
225
|
+
@security_groups = Hash.new if @security_groups.nil?
|
226
|
+
if groups[0].kind_of? Array
|
227
|
+
@security_groups["default"] = groups[0]
|
228
|
+
elsif groups[0].kind_of? Hash
|
229
|
+
groups[0].keys.each {|key| @security_groups[key] = [ groups[0][key] ] }
|
230
|
+
else
|
231
|
+
@security_groups["default"] = [ groups[0].to_s ]
|
232
|
+
end
|
233
|
+
self
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def security_groups_for_environment(environment)
|
238
|
+
groups = @security_groups[environment]
|
239
|
+
groups ||= @security_groups["default"]
|
240
|
+
groups ||= []
|
241
|
+
groups
|
242
|
+
end
|
243
|
+
|
244
|
+
def subnet(*subnet)
|
245
|
+
if subnet.empty?
|
246
|
+
@subnet
|
247
|
+
else
|
248
|
+
@subnet = subnet[0]
|
249
|
+
self
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def load(dsl)
|
254
|
+
self.instance_eval(dsl)
|
255
|
+
self
|
256
|
+
end
|
257
|
+
|
258
|
+
def self.load(dsl)
|
259
|
+
env = Application.new.instance_eval(dsl)
|
260
|
+
env
|
261
|
+
end
|
262
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Sean Laurent
|
3
|
+
#
|
4
|
+
class BlockDevice
|
5
|
+
attr_reader :mount_point
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
@count = 1
|
10
|
+
@group = "root"
|
11
|
+
@user = "root"
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_raid?()
|
15
|
+
@raid_level.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def count(*block_count)
|
19
|
+
if block_count.empty?
|
20
|
+
@count
|
21
|
+
else
|
22
|
+
@count = block_count[0]
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def group(*group)
|
28
|
+
if group.empty?
|
29
|
+
@group
|
30
|
+
else
|
31
|
+
@group = group[0]
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def mount(*mount)
|
37
|
+
if mount.empty?
|
38
|
+
@mount
|
39
|
+
else
|
40
|
+
@mount_point = mount[0]
|
41
|
+
self
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def name(*name)
|
46
|
+
if name.empty?
|
47
|
+
@name
|
48
|
+
else
|
49
|
+
@name = name[0]
|
50
|
+
self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def owner(*owner)
|
55
|
+
if owner.empty?
|
56
|
+
@owner
|
57
|
+
else
|
58
|
+
@owner = owner[0]
|
59
|
+
self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def raid_level(*raid_level)
|
64
|
+
if raid_level.empty?
|
65
|
+
@raid_level
|
66
|
+
else
|
67
|
+
@raid_level = raid_level[0]
|
68
|
+
self
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def size(*volume_size)
|
73
|
+
if volume_size.empty?
|
74
|
+
@size
|
75
|
+
else
|
76
|
+
@size = volume_size[0].to_i
|
77
|
+
self
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_json(*a)
|
82
|
+
{
|
83
|
+
"name" => @name,
|
84
|
+
"count" => @count,
|
85
|
+
"raid_level" => @raid_level,
|
86
|
+
"mount_point" => @mount_point,
|
87
|
+
"owner" => @owner,
|
88
|
+
"group" => @group
|
89
|
+
}.to_json(*a)
|
90
|
+
end
|
91
|
+
end
|