judo 0.0.9 → 0.1.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/Rakefile +1 -2
- data/VERSION +1 -1
- data/bin/judo +102 -212
- data/lib/judo.rb +18 -0
- data/lib/judo/base.rb +199 -0
- data/lib/judo/commandline_helpers.rb +151 -0
- data/lib/judo/config.rb +133 -0
- data/lib/judo/group.rb +221 -0
- data/lib/judo/server.rb +513 -0
- data/lib/judo/setup.rb +114 -0
- data/spec/base.rb +1 -1
- data/spec/base_spec.rb +9 -0
- metadata +16 -26
- data/lib/all.rb +0 -12
- data/lib/config.rb +0 -105
- data/lib/group.rb +0 -185
- data/lib/server.rb +0 -491
- data/lib/setup.rb +0 -114
data/lib/setup.rb
DELETED
@@ -1,114 +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('AWS_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_servers")
|
67
|
-
sdb.create_domain("judo_config")
|
68
|
-
olddb = sdb.get_attributes("judo_config", "judo")[:attributes]["dbversion"]
|
69
|
-
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
|
70
|
-
sdb.put_attributes("judo_config", "judo", { "dbversion" => Judo::Config.db_version }, :replace)
|
71
|
-
end
|
72
|
-
|
73
|
-
def setup_default_security_group
|
74
|
-
begin
|
75
|
-
ec2.create_security_group('judo', 'Judo')
|
76
|
-
ec2.authorize_security_group_IP_ingress("judo", 22, 22,'tcp','0.0.0.0/0')
|
77
|
-
rescue Aws::AwsError => e
|
78
|
-
raise unless e.message =~ /InvalidGroup.Duplicate/
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def setup_bucket
|
83
|
-
puts "setting up an s3 bucket"
|
84
|
-
Aws::S3.new(@aws_access_id, @aws_secret_key, :logger => Logger.new(nil)).bucket(@s3_bucket, true)
|
85
|
-
end
|
86
|
-
|
87
|
-
def setup_default_server_group
|
88
|
-
puts "Setting up default group and keypair"
|
89
|
-
system "mkdir -p default/keypairs"
|
90
|
-
|
91
|
-
@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}"
|
92
|
-
material = ec2.create_key_pair(@keypair)[:aws_material]
|
93
|
-
|
94
|
-
File.open("default/keypairs/#{@keypair}.pem", 'w') { |f| f.write material }
|
95
|
-
File.chmod 0600, "default/keypairs/#{@keypair}.pem"
|
96
|
-
File.open("default/config.json","w") { |f| f.write default_config }
|
97
|
-
end
|
98
|
-
|
99
|
-
def setup_judo_config
|
100
|
-
puts "setting up an .judo/config.yml"
|
101
|
-
system "mkdir .judo"
|
102
|
-
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) }
|
103
|
-
end
|
104
|
-
|
105
|
-
def ec2
|
106
|
-
@ec2 ||= Judo::Config.get_ec2(@aws_access_id, @aws_secret_key)
|
107
|
-
end
|
108
|
-
|
109
|
-
def sdb
|
110
|
-
@sdb ||= Judo::Config.get_sdb(@aws_access_id, @aws_secret_key)
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|