judo 0.2.1 → 0.2.3
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/README.markdown +35 -41
- data/Rakefile +1 -1
- data/TODO +13 -10
- data/VERSION +1 -1
- data/bin/judo +2 -1
- data/lib/judo/base.rb +87 -2
- data/lib/judo/commandline_helpers.rb +2 -2
- data/lib/judo/group.rb +23 -22
- data/lib/judo/server.rb +10 -28
- data/lib/judo.rb +4 -6
- metadata +5 -7
- data/lib/judo/config.rb +0 -133
- data/lib/judo/setup.rb +0 -115
data/README.markdown
CHANGED
@@ -5,6 +5,14 @@ to get going and powerful.
|
|
5
5
|
|
6
6
|
## CONCEPTS
|
7
7
|
|
8
|
+
Servers and Groups. Servers are identified by a naked string. Groups always
|
9
|
+
have a colon prefix.
|
10
|
+
|
11
|
+
$ judo restart my_server_1 ## this restarts my_server_1
|
12
|
+
$ judo restart my_server_1 other_server ## this restarts my_server_1 and other_server
|
13
|
+
$ judo restart :default ## this restarts all servers in the :default group
|
14
|
+
$ judo restart sammy :default :db ## this restarts all servers in the :default group, the :db group, and a server named sammy
|
15
|
+
|
8
16
|
Config Repo: Judo keeps it configuration for each server group in a git repo.
|
9
17
|
|
10
18
|
State Database: Judo keeps cloud state and information on specific servers in SimpleDB.
|
@@ -22,36 +30,38 @@ Setting up a new judo repo named "my_cloud" would look like this:
|
|
22
30
|
|
23
31
|
$ mkdir my_cloud
|
24
32
|
$ cd my_cloud
|
25
|
-
$
|
26
|
-
|
33
|
+
$ judo setup --accessid AWS_ACCESS_ID --secret AWS_KEY --bucket BUCKET
|
34
|
+
|
35
|
+
Note: you can use the AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID and JUDO_BUCKET
|
36
|
+
enviornment variables instead of the command line switches.
|
27
37
|
|
28
|
-
The 'judo
|
38
|
+
The 'judo setup' command will make a .judo folder to store your EC2 keys and S3
|
29
39
|
bucket. It will also make a folder named "default" to hold the default server
|
30
40
|
config.
|
31
41
|
|
32
42
|
To view all of the groups and servers running in those group you can type:
|
33
43
|
|
34
|
-
$ judo
|
35
|
-
SERVER GROUPS
|
36
|
-
default 0 servers
|
44
|
+
$ judo groups
|
37
45
|
|
38
|
-
To launch a default server you
|
46
|
+
To launch a default server you create it
|
39
47
|
|
40
|
-
$
|
41
|
-
$ judo create my_server_1
|
48
|
+
$ judo create my_server_1:default
|
42
49
|
---> Creating server my_server_1... done (0.6s)
|
43
50
|
$ judo list
|
44
|
-
|
45
|
-
|
51
|
+
SERVERS
|
52
|
+
--------------------------------------------------------------------------------
|
53
|
+
my_server_1 default v12 m1.small ebs:0
|
46
54
|
$ judo start my_server_1
|
47
|
-
|
55
|
+
---> Starting server my_server_1... done (2.3s)
|
56
|
+
$ judo list
|
57
|
+
SERVERS
|
58
|
+
--------------------------------------------------------------------------------
|
59
|
+
my_server_1 default v1 i-6fdf8d09 m1.small running ebs:0
|
48
60
|
|
49
|
-
|
50
|
-
|
51
|
-
scripts and packages it needs to run into your S3 bucket. The config probably
|
52
|
-
looks something like this:
|
61
|
+
You can examine a groups config by looking in the group folder in the repo. The
|
62
|
+
default group will look something like this.
|
53
63
|
|
54
|
-
$ cat config.json
|
64
|
+
$ cat default/config.json
|
55
65
|
{
|
56
66
|
"key_name":"judo14",
|
57
67
|
"instance_size":"m1.small",
|
@@ -62,44 +72,28 @@ looks something like this:
|
|
62
72
|
"availability_zone":"us-east-1d"
|
63
73
|
}
|
64
74
|
|
65
|
-
|
66
|
-
|
67
|
-
The user parameter is the user the 'judo ssh' command attempts to ssh in using
|
68
|
-
the keypair. Other debian based distros can be used assuming they have current
|
69
|
-
enough installations of ruby (1.8.7) and rubygems (1.3.5).
|
75
|
+
Any changes you make to these files does not stick until you've committed them.
|
76
|
+
To commit a group do the following.
|
70
77
|
|
71
|
-
$ judo commit
|
72
|
-
Compiling version 1
|
73
|
-
a default
|
74
|
-
a default/config.json
|
75
|
-
Uploading to s3...
|
76
|
-
$ judo start my_server_1
|
77
|
-
---> Starting server my_server_1... done (2.3s)
|
78
|
-
---> Acquire hostname... ec2-1-2-3-4.compute-1.amazonaws.com (49.8s)
|
79
|
-
---> Wait for ssh... done (9.8s)
|
80
|
-
$ judo list
|
81
|
-
SERVER IN GROUP default
|
82
|
-
my_server_1 v1 i-80000000 m1.small ami-bb709dd2 running 0 volumes ec2-1-2-3-4.compute-1.amazonaws.com
|
78
|
+
$ judo commit :default
|
79
|
+
Compiling version 2... done (1.2s)
|
83
80
|
|
84
81
|
We can now see that 'my_server_1' is running and running with version 1 of the
|
85
82
|
config. We can create and start a server in one step with the launch command.
|
86
83
|
|
87
|
-
$ judo launch my_server_2
|
84
|
+
$ judo launch my_server_2:default
|
88
85
|
---> Creating server my_server_2... done (0.6s)
|
89
86
|
---> Starting server my_server_2... done (1.6s)
|
90
|
-
---> Acquire hostname... ec2-1-2-3-5.compute-1.amazonaws.com (31.1s)
|
91
|
-
---> Wait for ssh... done (6.1s)
|
92
87
|
|
93
88
|
This will create and start two servers. One named 'my_server_1' and one named
|
94
89
|
'my_server_2'. You can ssh into 'my_server_1' you can type:
|
95
90
|
|
96
91
|
$ judo ssh my_server_1
|
97
92
|
|
98
|
-
You can stop all the servers with:
|
93
|
+
You can stop all the servers in the :default group with:
|
99
94
|
|
100
|
-
$ judo stop
|
95
|
+
$ judo stop :default
|
101
96
|
|
102
|
-
Note that since no name was specified it will stop all servers in the group.
|
103
97
|
You could also have typed:
|
104
98
|
|
105
99
|
$ judo stop my_server_1 my_server_2
|
@@ -115,7 +109,7 @@ operation is run on all servers. For instance:
|
|
115
109
|
|
116
110
|
This will restart only the servers named 'primary_db' and 'backup_db'. Where as
|
117
111
|
|
118
|
-
$ judo restart
|
112
|
+
$ judo restart :db
|
119
113
|
|
120
114
|
will restart all servers in the group.
|
121
115
|
|
data/Rakefile
CHANGED
data/TODO
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
### NEEDED for new gem launch
|
2
2
|
|
3
|
-
### [ ]
|
3
|
+
### [ ] ubuntu 10.04
|
4
|
+
### [ ] allocate elastic_ip first
|
5
|
+
### [ ] snapshot percent complete in do_snapshots()
|
4
6
|
### [ ] judo swap (x) (y) -> swaps elastic IP's and name
|
5
7
|
### [ ] snapshots/init/virgin
|
8
|
+
### [ ] bind kuzushi gem version version
|
9
|
+
### [ ] should be able to do ALL actions except commit without the repo!
|
10
|
+
### [ ] ssh - put pem into s3
|
11
|
+
### [ ] store s3 bucket in config
|
12
|
+
### [ ] store things in s3 by sha1sum
|
13
|
+
### [ ] ebs backed root disk
|
14
|
+
### [ ] clone from ebs snapshot on start
|
15
|
+
### [ ] implement start/stop
|
16
|
+
|
17
|
+
### [ ] implement auto security_group creation and setup (6 hrs)
|
6
18
|
|
7
19
|
### [ ] judo does not work with ruby 1.8.6 - :(
|
8
20
|
### [ ] saw a timeout on volume allocation - make sure we build in re-tries - need to allocate the server all together as much as possible
|
9
|
-
### [ ] there is a feature to allow for using that block_mapping feature - faster startup
|
10
21
|
|
11
22
|
### [ ] two phase delete (1 hr)
|
12
23
|
### [-] refactor availability_zone (2 hrs)
|
13
24
|
### [ ] pick availability zone from config "X":"Y" or "X":["Y","Z"]
|
14
25
|
### [ ] assign to state on creation ( could delay till volume creation )
|
15
|
-
### [ ] implement auto security_group creation and setup (6 hrs)
|
16
|
-
### [ ] bind kuzushi gem version version
|
17
26
|
|
18
|
-
### [ ] should be able to do ALL actions except commit without the repo!
|
19
27
|
### [ ] store git commit hash with commit to block a judo commit if there is newer material stored
|
20
|
-
### [ ] remove the tarball - store files a sha hashes in the bucket - makes for faster commits if the files have not changed
|
21
28
|
|
22
29
|
### [ ] use a logger service (1 hr)
|
23
30
|
### [ ] write specs (5 hr)
|
@@ -28,13 +35,9 @@
|
|
28
35
|
|
29
36
|
### Do Later
|
30
37
|
### [ ] use amazon's new conditional write tools so we never have problems from concurrent updates
|
31
|
-
### [ ] is thor really what we want to use here?
|
32
|
-
### [ ] need to be able to pin a config to a version of kuzushi - gem updates can/will break a lot of things
|
33
38
|
### [ ] I want a "judo monitor" command that will make start servers if they go down, and poke a listed port to make sure a service is listening, would be cool if it also detects wrong ami, wrong secuirity group, missing/extra volumes, missing/extra elastic_ip - might not want to force a reboot quite yet in these cases
|
34
|
-
### [ ] Implement "judo snapshot [NAME]" to take a snapshot of the ebs's blocks
|
35
39
|
### [ ] ruby 1.9.1 support
|
36
40
|
### [ ] find a good way to set the hostname or prompt to :name
|
37
|
-
### [ ] remove fog/s3 dependancy
|
38
41
|
### [ ] enforce template files end in .erb to make room for other possible templates as defined by the extensions
|
39
42
|
### [ ] zerigo integration for automatic DNS setup
|
40
43
|
### [ ] How cool would it be if this was all reimplemented in eventmachine and could start lots of boxes in parallel? Would need to evented AWS api calls... Never seen a library to do that - would have to write our own... "Fog Machine?"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/bin/judo
CHANGED
@@ -93,10 +93,11 @@ end
|
|
93
93
|
optparse.parse!
|
94
94
|
|
95
95
|
judo = Judo::Base.new(defaults.merge(options))
|
96
|
-
judo.check_version
|
96
|
+
judo.check_version if action != "setup"
|
97
97
|
|
98
98
|
begin
|
99
99
|
case action
|
100
|
+
when "setup" then judo.setup
|
100
101
|
when "ips" then do_ips(judo)
|
101
102
|
when "volumes" then do_volumes(judo)
|
102
103
|
when "list" then do_list(judo, ARGV)
|
data/lib/judo/base.rb
CHANGED
@@ -60,6 +60,10 @@ module Judo
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
def self.domain
|
64
|
+
"judo_config"
|
65
|
+
end
|
66
|
+
|
63
67
|
def self.default_options(pwd, dir = find_judo_dir(pwd))
|
64
68
|
config = YAML.load File.read("#{dir}/config.yml")
|
65
69
|
repo_dir = config["repo"] || File.dirname(dir)
|
@@ -207,7 +211,7 @@ module Judo
|
|
207
211
|
end
|
208
212
|
|
209
213
|
def bucket
|
210
|
-
@bucket ||= s3.bucket(bucket_name)
|
214
|
+
@bucket ||= s3.bucket(bucket_name, true)
|
211
215
|
end
|
212
216
|
|
213
217
|
def s3_url(k)
|
@@ -247,7 +251,12 @@ module Judo
|
|
247
251
|
def upgrade_db
|
248
252
|
case get_db_version
|
249
253
|
when 0
|
250
|
-
|
254
|
+
task("Upgrading Judo: Creating Snapshots SDB Domain") do
|
255
|
+
sdb.create_domain(Judo::Server.domain)
|
256
|
+
sdb.create_domain(Judo::Snapshot.domain)
|
257
|
+
sdb.create_domain(Judo::Snapshot.domain)
|
258
|
+
set_db_version(2)
|
259
|
+
end
|
251
260
|
when 1
|
252
261
|
task("Upgrading Judo: Creating Snapshots SDB Domain") do
|
253
262
|
sdb.create_domain(Judo::Snapshot.domain)
|
@@ -270,5 +279,81 @@ module Judo
|
|
270
279
|
def check_version
|
271
280
|
upgrade_db if get_db_version != db_version
|
272
281
|
end
|
282
|
+
|
283
|
+
def setup
|
284
|
+
## no need to setup bucket
|
285
|
+
|
286
|
+
@repo ||= "." ## use cwd as default repo dir
|
287
|
+
|
288
|
+
setup_sdb
|
289
|
+
setup_security_group
|
290
|
+
setup_judo_config
|
291
|
+
setup_repo
|
292
|
+
get_group("default").compile
|
293
|
+
end
|
294
|
+
|
295
|
+
def setup_sdb
|
296
|
+
task("Trying to connect to SimpleDB") do
|
297
|
+
sdb.create_domain(Judo::Base.domain)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def setup_security_group
|
302
|
+
begin
|
303
|
+
ec2.create_security_group('judo', 'Judo')
|
304
|
+
ec2.authorize_security_group_IP_ingress("judo", 22, 22,'tcp','0.0.0.0/0')
|
305
|
+
rescue Aws::AwsError => e
|
306
|
+
raise unless e.message =~ /InvalidGroup.Duplicate/
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def setup_judo_config
|
311
|
+
if judo_dir and File.exists?("#{judo_dir}/config.yml")
|
312
|
+
puts "config already exists [#{judo_dir}/config.yml]"
|
313
|
+
return
|
314
|
+
end
|
315
|
+
raise JudoError, "You must specify a repo dir" unless repo
|
316
|
+
task("writing .judo/config.yml") do
|
317
|
+
Dir.chdir(repo) do
|
318
|
+
system "mkdir .judo"
|
319
|
+
File.open(".judo/config.yml","w") do |f|
|
320
|
+
f.write({ "access_id" => @aws_access_id, "access_secret" => @aws_secret_key, "s3_bucket" => @s3_bucket }.to_yaml)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
def setup_repo
|
327
|
+
if File.exists?("#{repo}/default")
|
328
|
+
puts "default group already exists [#{repo}/default]"
|
329
|
+
return
|
330
|
+
end
|
331
|
+
task("Setting up default group") do
|
332
|
+
Dir.chdir(repo) do
|
333
|
+
system "mkdir -p default/keypairs"
|
334
|
+
|
335
|
+
@keypair = "judo#{ec2.describe_key_pairs.map { |k| k[:aws_key_name] }.map { |k| k =~ /^judo(\d*)/; $1.to_i }.sort.last.to_i + 1}"
|
336
|
+
material = ec2.create_key_pair(@keypair)[:aws_material]
|
337
|
+
|
338
|
+
File.open("default/keypairs/#{@keypair}.pem", 'w') { |f| f.write material }
|
339
|
+
File.chmod 0600, "default/keypairs/#{@keypair}.pem"
|
340
|
+
File.open("default/config.json","w") { |f| f.write default_config }
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def default_config
|
346
|
+
<<DEFAULT
|
347
|
+
{
|
348
|
+
"key_name":"#{@keypair}",
|
349
|
+
"instance_size":"m1.small",
|
350
|
+
"ami32":"ami-bb709dd2", // public ubuntu 9.10 ami - 32 bit
|
351
|
+
"ami64":"ami-55739e3c", // public ubuntu 9.10 ami - 64 bit
|
352
|
+
"user":"ubuntu",
|
353
|
+
"security_group":"judo",
|
354
|
+
"availability_zone":"us-east-1d"
|
355
|
+
}
|
356
|
+
DEFAULT
|
357
|
+
end
|
273
358
|
end
|
274
359
|
end
|
@@ -125,7 +125,7 @@ module JudoCommandLineHelpers
|
|
125
125
|
printf "%s\n", ("-" * 80)
|
126
126
|
judo.snapshots.each do |snapshot|
|
127
127
|
next if args and not servers.detect { |s| s == snapshot.server }
|
128
|
-
printf "%-15s %-25s %-15s %-10s %s\n", snapshot.name, snapshot.server_name, snapshot.group_name, snapshot.version_desc, "
|
128
|
+
printf "%-15s %-25s %-15s %-10s %s\n", snapshot.name, snapshot.server_name, snapshot.group_name, snapshot.version_desc, "ebs:#{snapshot.ec2_ids.size}"
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -134,7 +134,7 @@ module JudoCommandLineHelpers
|
|
134
134
|
printf " SERVERS\n"
|
135
135
|
printf "%s\n", ("-" * 80)
|
136
136
|
servers.sort.each do |s|
|
137
|
-
printf "%-32s %-12s %-7s %-11s %-11s %-10s %-3s %s\n", s.name, s.group.name, s.version_desc, s.state["instance_id"], s.size_desc, s.ec2_state, "
|
137
|
+
printf "%-32s %-12s %-7s %-11s %-11s %-10s %-3s %s\n", s.name, s.group.name, s.version_desc, s.state["instance_id"], s.size_desc, s.ec2_state, "ebs:#{s.volumes.keys.size}", s.has_ip? ? "ip" : ""
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
data/lib/judo/group.rb
CHANGED
@@ -36,31 +36,32 @@ module Judo
|
|
36
36
|
|
37
37
|
def compile
|
38
38
|
tmpdir = "/tmp/kuzushi/#{name}"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
39
|
+
@base.task("Compiling #{self} version #{version + 1}") do
|
40
|
+
@version = @version + 1
|
41
|
+
FileUtils.rm_rf(tmpdir)
|
42
|
+
FileUtils.mkdir_p(tmpdir)
|
43
|
+
new_config = build_config
|
44
|
+
Dir.chdir(tmpdir) do |d|
|
45
|
+
attachments(new_config).each do |to,from|
|
46
|
+
FileUtils.mkdir_p(File.dirname(to))
|
47
|
+
if from =~ /^http:\/\//
|
48
|
+
# puts "curl '#{from}'"
|
49
|
+
system "curl '#{from}' > #{to}"
|
50
|
+
# puts "#{to} is #{File.stat(to).size} bytes"
|
51
|
+
else
|
52
|
+
FileUtils.cp(from,to)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
File.open("config.json", "w") { |f| f.write(new_config.to_json) }
|
56
|
+
Dir.chdir("..") do
|
57
|
+
system "tar czf #{tar_file} #{name}"
|
58
|
+
# puts "Uploading to s3..."
|
59
|
+
@base.s3_put(tar_file, File.new(tar_file).read)
|
60
|
+
@base.s3_put(version_config_file, new_config.to_json)
|
53
61
|
end
|
54
62
|
end
|
55
|
-
|
56
|
-
Dir.chdir("..") do
|
57
|
-
system "tar czvf #{tar_file} #{name}"
|
58
|
-
puts "Uploading to s3..."
|
59
|
-
@base.s3_put(tar_file, File.new(tar_file))
|
60
|
-
@base.s3_put(version_config_file, new_config.to_json)
|
61
|
-
end
|
63
|
+
set_version
|
62
64
|
end
|
63
|
-
set_version
|
64
65
|
end
|
65
66
|
|
66
67
|
def version_config_file
|
data/lib/judo/server.rb
CHANGED
@@ -315,7 +315,7 @@ module Judo
|
|
315
315
|
## EC2 terminate_isntaces
|
316
316
|
task("Terminating instance") { @base.ec2.terminate_instances([ instance_id ]) }
|
317
317
|
force_detach_volumes if force
|
318
|
-
|
318
|
+
wait_for_volumes_detached if volumes.size > 0
|
319
319
|
remove "instance_id"
|
320
320
|
end
|
321
321
|
|
@@ -382,14 +382,18 @@ module Judo
|
|
382
382
|
|
383
383
|
def wait_for_volumes_detached
|
384
384
|
begin
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
385
|
+
task("Wait for volumes to detach") do
|
386
|
+
Timeout::timeout(60) do
|
387
|
+
loop do
|
388
|
+
break if ec2_volumes.reject { |v| v[:aws_status] == "available" }.empty?
|
389
|
+
sleep 2
|
390
|
+
end
|
389
391
|
end
|
390
392
|
end
|
391
393
|
rescue Timeout::Error
|
394
|
+
puts "failed!"
|
392
395
|
force_detach_volumes
|
396
|
+
retry
|
393
397
|
end
|
394
398
|
end
|
395
399
|
|
@@ -463,29 +467,6 @@ module Judo
|
|
463
467
|
system "ssh -i #{group.keypair_file} #{config["user"]}@#{hostname}"
|
464
468
|
end
|
465
469
|
|
466
|
-
def self.commit
|
467
|
-
## FIXME
|
468
|
-
Config.group_dirs.each do |group_dir|
|
469
|
-
group = File.basename(group_dir)
|
470
|
-
next if Config.group and Config.group != group
|
471
|
-
puts "commiting #{group}"
|
472
|
-
doc = Config.couchdb.get(group) rescue {}
|
473
|
-
config = Config.read_config(group)
|
474
|
-
config['_id'] = group
|
475
|
-
config['_rev'] = doc['_rev'] if doc.has_key?('_rev')
|
476
|
-
response = Config.couchdb.save_doc(config)
|
477
|
-
doc = Config.couchdb.get(response['id'])
|
478
|
-
|
479
|
-
# walk subdirs and save as _attachments
|
480
|
-
['files', 'templates', 'packages', 'scripts'].each { |subdir|
|
481
|
-
Dir["#{group_dir}/#{subdir}/*"].each do |f|
|
482
|
-
puts "storing attachment #{f}"
|
483
|
-
doc.put_attachment("#{subdir}/#{File.basename(f)}", File.read(f))
|
484
|
-
end
|
485
|
-
}
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
470
|
def ec2_instance_type
|
490
471
|
ec2_instance[:aws_instance_type] rescue nil
|
491
472
|
end
|
@@ -505,6 +486,7 @@ module Judo
|
|
505
486
|
|
506
487
|
export DEBIAN_FRONTEND="noninteractive"
|
507
488
|
export DEBIAN_PRIORITY="critical"
|
489
|
+
export JUDO_ID='#{name}'
|
508
490
|
export SECRET='#{secret}'
|
509
491
|
apt-get update
|
510
492
|
apt-get install ruby rubygems ruby-dev irb libopenssl-ruby libreadline-ruby -y
|
data/lib/judo.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'socket'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
1
|
require 'rubygems'
|
2
|
+
require 'active_support'
|
6
3
|
require 'right_aws'
|
4
|
+
require 'socket'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'yaml'
|
7
7
|
require 'json'
|
8
8
|
require 'pp'
|
9
9
|
|
@@ -13,9 +13,7 @@ class JudoError < RuntimeError ; end
|
|
13
13
|
class JudoInvalid < RuntimeError ; end
|
14
14
|
|
15
15
|
require File.dirname(__FILE__) + '/judo/base'
|
16
|
-
require File.dirname(__FILE__) + '/judo/config'
|
17
16
|
require File.dirname(__FILE__) + '/judo/group'
|
18
17
|
require File.dirname(__FILE__) + '/judo/server'
|
19
18
|
require File.dirname(__FILE__) + '/judo/snapshot'
|
20
|
-
require File.dirname(__FILE__) + '/judo/setup'
|
21
19
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Orion Henry
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-13 00:00:00 -04:00
|
18
18
|
default_executable: judo
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,8 +27,8 @@ dependencies:
|
|
27
27
|
segments:
|
28
28
|
- 2
|
29
29
|
- 3
|
30
|
-
-
|
31
|
-
version: 2.3.
|
30
|
+
- 8
|
31
|
+
version: 2.3.8
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
@@ -61,10 +61,8 @@ files:
|
|
61
61
|
- lib/judo.rb
|
62
62
|
- lib/judo/base.rb
|
63
63
|
- lib/judo/commandline_helpers.rb
|
64
|
-
- lib/judo/config.rb
|
65
64
|
- lib/judo/group.rb
|
66
65
|
- lib/judo/server.rb
|
67
|
-
- lib/judo/setup.rb
|
68
66
|
- lib/judo/snapshot.rb
|
69
67
|
- spec/base.rb
|
70
68
|
- spec/base_spec.rb
|
data/lib/judo/config.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module Judo
|
2
|
-
module Config
|
3
|
-
extend self
|
4
|
-
|
5
|
-
def db_version
|
6
|
-
1
|
7
|
-
end
|
8
|
-
|
9
|
-
def get_db_version
|
10
|
-
version = @sdb.get_attributes("judo_config", "judo")[:attributes]["dbversion"]
|
11
|
-
version and version.first.to_i or db_version
|
12
|
-
end
|
13
|
-
|
14
|
-
def check_version
|
15
|
-
abort "judo db is newer than the current gem - upgrade judo and try again" if get_db_version > db_version
|
16
|
-
end
|
17
|
-
|
18
|
-
def repo_dir
|
19
|
-
judo_config["repo"] || File.dirname(judo_dir)
|
20
|
-
end
|
21
|
-
|
22
|
-
def access_id
|
23
|
-
judo_config["access_id"]
|
24
|
-
end
|
25
|
-
|
26
|
-
def access_secret
|
27
|
-
judo_config["access_secret"]
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_ec2(aws_id, aws_key)
|
31
|
-
Aws::Ec2.new(aws_id, aws_key, :logger => Logger.new(nil))
|
32
|
-
end
|
33
|
-
|
34
|
-
def ec2
|
35
|
-
@ec2 ||= get_ec2(access_id, access_secret)
|
36
|
-
end
|
37
|
-
|
38
|
-
# def create_security_group
|
39
|
-
# ## EC2 create_security_group
|
40
|
-
# ec2.create_security_group('judo', 'Judo')
|
41
|
-
# ## EC2 authorize_security_group
|
42
|
-
# ec2.authorize_security_group_IP_ingress("judo", 22, 22,'tcp','0.0.0.0/0')
|
43
|
-
# rescue Aws::AwsError
|
44
|
-
# end
|
45
|
-
|
46
|
-
def judo_config
|
47
|
-
@config ||= read_judo_config
|
48
|
-
end
|
49
|
-
|
50
|
-
def judo_config_file
|
51
|
-
"#{judo_dir}/config.yml"
|
52
|
-
end
|
53
|
-
|
54
|
-
def judo_dir
|
55
|
-
@judo_dir ||= find_judo_dir(Dir.pwd) || abort("fatal: Not a judo repository (or any of the parent directories): .judo\nrun commands from the judo repository or type 'judo init' to setup the current directory as a new judo repository")
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.dirs
|
59
|
-
Dir["#{Judo::Config.repo_dir}/*/config.json"].map { |d| File.dirname(d) }
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.all
|
63
|
-
@@all ||= (dirs.map { |d| new(d) })
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.current
|
67
|
-
all.detect { |d| Dir.pwd == d.dir or Dir.pwd =~ /^#{d.dir}\// }
|
68
|
-
end
|
69
|
-
|
70
|
-
def default_options(pwd, dir = find_judo_dir(pwd))
|
71
|
-
puts "PWD: #{pwd}"
|
72
|
-
puts "DIR: #{dir}"
|
73
|
-
config = YAML.load File.read("#{dir}/config.yml")
|
74
|
-
repo_dir = config["repo"] || File.dirname(dir)
|
75
|
-
group_config = Dir["#{repo_dir}/*/config.json"].detect { |d| File.dirname(d) == pwd }
|
76
|
-
{
|
77
|
-
:judo_dir => dir,
|
78
|
-
:group => group_config ? File.basename(File.dirname(group_config)) : nil,
|
79
|
-
:repo => repo_dir,
|
80
|
-
:bucket => config["s3_bucket"],
|
81
|
-
:access_id => config["access_id"],
|
82
|
-
:access_secret => config["access_secret"]
|
83
|
-
}.delete_if { |key,value| value.nil? }
|
84
|
-
rescue Object => e
|
85
|
-
puts e.inspect
|
86
|
-
{}
|
87
|
-
end
|
88
|
-
|
89
|
-
def find_judo_dir(check)
|
90
|
-
if check == "/"
|
91
|
-
if File.exists?("#{ENV['HOME']}/.judo")
|
92
|
-
"#{ENV['HOME']}/.judo"
|
93
|
-
else
|
94
|
-
nil
|
95
|
-
end
|
96
|
-
else
|
97
|
-
File.exists?(check + "/.judo") ? check + "/.judo" : find_judo_dir(File.dirname(check))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def read_judo_config
|
102
|
-
YAML.load File.read(judo_config_file)
|
103
|
-
rescue Errno::ENOENT
|
104
|
-
{}
|
105
|
-
end
|
106
|
-
|
107
|
-
def get_sdb(aws_id, aws_key)
|
108
|
-
Aws::SdbInterface.new(aws_id, aws_key, :logger => Logger.new(nil))
|
109
|
-
end
|
110
|
-
|
111
|
-
def sdb
|
112
|
-
@sdb ||= get_sdb(access_id, access_secret)
|
113
|
-
# @version_ok ||= check_version
|
114
|
-
@sdb
|
115
|
-
end
|
116
|
-
|
117
|
-
def s3
|
118
|
-
@s3 ||= Aws::S3.new(access_id, access_secret, :logger => Logger.new(nil))
|
119
|
-
end
|
120
|
-
|
121
|
-
def s3_bucket
|
122
|
-
@s3_bucket ||= s3.bucket(judo_config["s3_bucket"])
|
123
|
-
end
|
124
|
-
|
125
|
-
def s3_url(k)
|
126
|
-
Aws::S3Generator::Key.new(s3_bucket, k).get
|
127
|
-
end
|
128
|
-
|
129
|
-
def s3_put(k, file)
|
130
|
-
s3_bucket.put(k, file)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/lib/judo/setup.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
module Judo
|
2
|
-
class Setup
|
3
|
-
def default_config
|
4
|
-
<<DEFAULT
|
5
|
-
{
|
6
|
-
"key_name":"#{@keypair}",
|
7
|
-
"instance_size":"m1.small",
|
8
|
-
"ami32":"ami-bb709dd2", // public ubuntu 9.10 ami - 32 bit
|
9
|
-
"ami64":"ami-55739e3c", // public ubuntu 9.10 ami - 64 bit
|
10
|
-
"user":"ubuntu",
|
11
|
-
"security_group":"judo",
|
12
|
-
"availability_zone":"us-east-1d"
|
13
|
-
}
|
14
|
-
DEFAULT
|
15
|
-
end
|
16
|
-
|
17
|
-
def getenv(key)
|
18
|
-
printf "Looking in your environment for #{key}..."
|
19
|
-
printf "found!" if ENV[key]
|
20
|
-
printf "\n"
|
21
|
-
ENV[key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def request(query, default = "")
|
25
|
-
printf "#{query} ['#{default}']: "
|
26
|
-
input = STDIN.readline.strip
|
27
|
-
input.empty? and default or input
|
28
|
-
end
|
29
|
-
|
30
|
-
def check_setup
|
31
|
-
abort "you are already inside a judo repository" if Judo::Config.find_judo_dir(Dir.pwd)
|
32
|
-
abort "./.git not found - judo configurations must be kept in a git repo. type 'git init' to setup the git repo." unless File.exists? "./.git"
|
33
|
-
end
|
34
|
-
|
35
|
-
def init
|
36
|
-
check_setup
|
37
|
-
@aws_access_id ||= getenv('AWS_ACCESS_KEY_ID')
|
38
|
-
@aws_access_id ||= getenv('AMAZON_ACCESS_KEY_ID')
|
39
|
-
@aws_secret_key ||= getenv('AWS_SECRET_ACCESS_KEY')
|
40
|
-
@aws_secret_key ||= getenv('AMAZON_SECRET_ACCESS_KEY')
|
41
|
-
@s3_bucket ||= getenv('JUDO_S3_BUCKET')
|
42
|
-
@s3_bucket ||= "judo_#{rand(2**64).to_s(36)}"
|
43
|
-
begin
|
44
|
-
@aws_access_id = request("Please enter your AWS access key", @aws_access_id)
|
45
|
-
@aws_secret_key = request("Please enter your AWS secret key" , @aws_secret_key)
|
46
|
-
@s3_bucket = request("Please enter an S3 bucket to use", @s3_bucket)
|
47
|
-
|
48
|
-
setup_default_server_group
|
49
|
-
setup_default_security_group
|
50
|
-
setup_bucket
|
51
|
-
setup_db
|
52
|
-
setup_judo_config
|
53
|
-
|
54
|
-
rescue *[Interrupt, EOFError]
|
55
|
-
puts "\nGoodbye!"
|
56
|
-
exit(0)
|
57
|
-
rescue Object => e
|
58
|
-
puts "There was an error: #{e.class}:#{e.message}"
|
59
|
-
puts "Try again or hit CTRL-C"
|
60
|
-
retry
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def setup_db
|
65
|
-
puts "Trying to connect to SimpleDB with #{@aws_access_id}"
|
66
|
-
sdb.create_domain(Judo::Server.domain)
|
67
|
-
sdb.create_domain(Judo::Snapshot.domain)
|
68
|
-
sdb.create_domain("judo_config")
|
69
|
-
olddb = sdb.get_attributes("judo_config", "judo")[:attributes]["dbversion"]
|
70
|
-
abort "There is an existing judo database of a newer version - upgrade judo and try again" if olddb and olddb.first.to_i > Judo::Config.db_version
|
71
|
-
sdb.put_attributes("judo_config", "judo", { "dbversion" => Judo::Config.db_version }, :replace)
|
72
|
-
end
|
73
|
-
|
74
|
-
def setup_default_security_group
|
75
|
-
begin
|
76
|
-
ec2.create_security_group('judo', 'Judo')
|
77
|
-
ec2.authorize_security_group_IP_ingress("judo", 22, 22,'tcp','0.0.0.0/0')
|
78
|
-
rescue Aws::AwsError => e
|
79
|
-
raise unless e.message =~ /InvalidGroup.Duplicate/
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def setup_bucket
|
84
|
-
puts "setting up an s3 bucket"
|
85
|
-
Aws::S3.new(@aws_access_id, @aws_secret_key, :logger => Logger.new(nil)).bucket(@s3_bucket, true)
|
86
|
-
end
|
87
|
-
|
88
|
-
def setup_default_server_group
|
89
|
-
puts "Setting up default group and keypair"
|
90
|
-
system "mkdir -p default/keypairs"
|
91
|
-
|
92
|
-
@keypair = "judo#{ec2.describe_key_pairs.map { |k| k[:aws_key_name] }.map { |k| k =~ /^judo(\d*)/; $1.to_i }.sort.last.to_i + 1}"
|
93
|
-
material = ec2.create_key_pair(@keypair)[:aws_material]
|
94
|
-
|
95
|
-
File.open("default/keypairs/#{@keypair}.pem", 'w') { |f| f.write material }
|
96
|
-
File.chmod 0600, "default/keypairs/#{@keypair}.pem"
|
97
|
-
File.open("default/config.json","w") { |f| f.write default_config }
|
98
|
-
end
|
99
|
-
|
100
|
-
def setup_judo_config
|
101
|
-
puts "setting up an .judo/config.yml"
|
102
|
-
system "mkdir .judo"
|
103
|
-
File.open(".judo/config.yml","w") { |f| f.write({ "access_id" => @aws_access_id, "access_secret" => @aws_secret_key, "s3_bucket" => @s3_bucket }.to_yaml) }
|
104
|
-
end
|
105
|
-
|
106
|
-
def ec2
|
107
|
-
@ec2 ||= Judo::Config.get_ec2(@aws_access_id, @aws_secret_key)
|
108
|
-
end
|
109
|
-
|
110
|
-
def sdb
|
111
|
-
@sdb ||= Judo::Config.get_sdb(@aws_access_id, @aws_secret_key)
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|