hugo 0.1.11 → 0.2.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.
@@ -3,9 +3,16 @@ module Hugo; end
3
3
  class Hugo::App
4
4
  include Singleton
5
5
  include Hugo::Mixin::ParamsValidate
6
+
7
+ AMI = ENV['EC2_AMI_ID'] || 'ami-1515f67c'
8
+ ZONE = "us-east-1c"
9
+ TYPE = "m1.small"
10
+
6
11
 
7
12
  attr_accessor :dna
8
13
 
14
+ # How many servers do you want in your cloud
15
+ # This function will give and take away servers
9
16
  def servers(instances=1)
10
17
  if lb
11
18
  if instances > lb.instances.length
@@ -18,30 +25,50 @@ class Hugo::App
18
25
  end
19
26
  end
20
27
 
28
+ # Setup will install chef-solo on server instance
21
29
  def setup
22
30
  if lb
23
31
  lb.instances.each do |i|
24
32
  setup_ec2(i)
25
33
  end
26
34
  else
27
- puts instance
28
35
  setup_ec2(instance)
29
36
  end
30
- puts "Setup Completed"
37
+ # puts "Setup Completed"
31
38
  end
32
39
 
40
+ # deploy will run you json with chef-sole against your cookbooks
33
41
  def deploy
42
+ raise ArgumentError, "app.key_name Required" unless key_name
43
+ raise ArgumentError, "app.key_path Required" unless key_path
44
+ raise ArgumentError, "app.cookbook Required" unless cookbook
45
+ raise ArgumentError, "app.run_list Required" unless run_list
46
+
34
47
  deploy_ec2
35
- puts "Deploy Completed"
48
+ #puts "Deploy Completed"
36
49
  end
37
50
 
51
+ # will kill all app servers
38
52
  def destroy
39
- lb.instances.each do |i|
40
- Hugo::Aws::Ec2.find(i).destroy
41
- end
53
+ if lb
54
+ lb.instances.each do |i|
55
+ Hugo::Aws::Ec2.find(i).destroy
56
+ end
57
+ else
58
+ Hugo::Aws::Ec2.find(instance).destroy
59
+ end
60
+
61
+ end
62
+
63
+ def clear
64
+ @key_name = nil
65
+ @key_path = nil
66
+ @cookbook = nil
67
+ @run_list = nil
42
68
  end
43
69
 
44
70
 
71
+ # Dyanamically add recipes to your json
45
72
  def add_recipe(name, options=nil)
46
73
  run_list [] if run_list.nil?
47
74
  run_list << "recipe[#{name}]"
@@ -52,29 +79,34 @@ class Hugo::App
52
79
  end
53
80
  end
54
81
 
82
+ # Set the instance if you only are deploying one server
55
83
  def instance(arg=nil)
56
84
  set_or_return(:instance, arg, :kind_of => [String])
57
85
  end
58
86
 
87
+ # Name of app - should relate to github repository
59
88
  def name(arg=nil)
60
89
  set_or_return(:name, arg, :kind_of => [String])
61
90
  end
62
91
 
92
+ # Load Balancer Object
63
93
  def lb(arg=nil)
64
94
  set_or_return(:lb, arg, :kind_of => [Hugo::Aws::Elb])
65
95
  end
66
96
 
97
+ # Database Object
67
98
  def db(arg=nil)
68
- set_or_return(:db, arg, :kind_of => [Hugo::Aws::Rds])
99
+ set_or_return(:db, arg, :kind_of => [Hugo::Database])
69
100
  end
70
101
 
71
- def uri(arg=nil)
72
- set_or_return(:uri, arg, :kind_of => [String])
73
- end
102
+ # URI of
103
+ # def uri(arg=nil)
104
+ # set_or_return(:uri, arg, :kind_of => [String])
105
+ # end
74
106
 
75
- def type(arg=nil)
76
- set_or_return(:type, arg, :kind_of => [String])
77
- end
107
+ # def type(arg=nil)
108
+ # set_or_return(:type, arg, :kind_of => [String])
109
+ # end
78
110
 
79
111
  def zone(arg=nil)
80
112
  set_or_return(:zone, arg, :kind_of => [String])
@@ -84,18 +116,10 @@ class Hugo::App
84
116
  set_or_return(:image_id, arg, :kind_of => [String])
85
117
  end
86
118
 
87
- def application(arg=nil)
88
- set_or_return(:application, arg, :kind_of => [String])
89
- end
90
-
91
119
  def security_group(arg=nil)
92
120
  set_or_return(:security_group, arg, :kind_of => [String])
93
121
  end
94
-
95
- def cloud_name(arg=nil)
96
- set_or_return(:cloud_name, arg, :kind_of => [String])
97
- end
98
-
122
+
99
123
  def key_name(arg=nil)
100
124
  set_or_return(:key_name, arg, :kind_of => [String])
101
125
  end
@@ -105,19 +129,61 @@ class Hugo::App
105
129
  end
106
130
 
107
131
  def key_path(arg=nil)
108
- set_or_return(:key_pair_file, arg, :kind_of => [String])
132
+ set_or_return(:key_path, arg, :kind_of => [String])
109
133
  end
110
134
 
111
135
  def run_list(arg=nil)
112
136
  set_or_return(:run_list, arg, :kind_of => [Array])
113
137
  end
138
+
114
139
 
115
- def deploy_info(arg=nil)
116
- set_or_return(:deploy_info, arg, :kind_of => [Hash])
117
- end
118
-
119
-
120
-
140
+ def help
141
+ x = <<HELP
142
+
143
+ Hugo app
144
+ -----------------
145
+ There are two ways to run hugo app, a single instance mode, or
146
+ with a balancer. If you do not use a balancer, then after your
147
+ initial run, which creates the server instance, you need to enter
148
+ the server instance into your config, so it will not create a new
149
+ ec2 everytime
150
+
151
+ Required attributes
152
+ -----------------
153
+ key_name
154
+ key_path
155
+ cookbook
156
+ run_list
157
+
158
+ Methods
159
+ ------------------
160
+ servers
161
+
162
+ deploy
163
+
164
+ add_recipe
165
+
166
+ destroy
167
+
168
+ help
169
+
170
+ Optional Attributes
171
+ -----------------
172
+
173
+ instance
174
+ lb
175
+ db
176
+ uri
177
+ type
178
+ zone
179
+ image_id
180
+
181
+
182
+
183
+ HELP
184
+ puts x
185
+ x
186
+ end
121
187
 
122
188
 
123
189
  private
@@ -133,9 +199,9 @@ private
133
199
  end
134
200
 
135
201
  def create_ec2
136
- ec2 = Hugo::Aws::Ec2.new(:type => type,
137
- :zone => zone,
138
- :image_id => image_id,
202
+ ec2 = Hugo::Aws::Ec2.new(:type => type || TYPE,
203
+ :zone => zone || ZONE,
204
+ :image_id => image_id || AMI,
139
205
  :key_name => key_name,
140
206
  :security_group => "default").create
141
207
 
@@ -169,7 +235,7 @@ private
169
235
  commands << 'if [ -d "./hugo-repos" ]; then echo "setup already run"; else sudo gem install git --no-ri --no-rdoc; fi'
170
236
  commands << "if [ -d \"./hugo-repos\" ]; then echo \"setup already run\"; else git clone #{self.cookbook} ~/hugo-repos; fi"
171
237
  ec2 = Hugo::Aws::Ec2.find(instance_id)
172
- puts ec2.uri
238
+ #puts ec2.uri
173
239
  ec2.ssh(commands, nil, File.join(key_path, key_name))
174
240
  end
175
241
 
@@ -179,25 +245,16 @@ private
179
245
  commands << "cd hugo-repos && git reset --hard && git pull"
180
246
  commands << 'sudo chef-solo -c /home/ubuntu/hugo-repos/config/solo.rb -j /home/ubuntu/dna.json'
181
247
 
182
- database_info = {
183
- :uri => db.uri,
184
- :name => db.db,
185
- :user => db.user,
186
- :password => db.password } unless db.nil?
187
248
 
188
249
  self.dna = {} if self.dna.nil?
189
- self.dna.merge!(:run_list => run_list,
250
+ self.dna.merge!(
251
+ :run_list => run_list,
190
252
  :git => cookbook,
191
253
  :access_key => Hugo::Aws::Ec2::ACCESS_KEY,
192
254
  :secret_key => Hugo::Aws::Ec2::SECRET_KEY,
193
- :database => database_info,
194
-
195
- :application => name,
196
- :customer => cloud_name,
197
-
198
- :app => deploy_info
255
+ :database => db ? db.info : {}
199
256
  )
200
-
257
+
201
258
  if lb
202
259
  lb.instances.each do |i|
203
260
  Hugo::Aws::Ec2.find(i).ssh(commands, dna, File.join(key_path, key_name))
@@ -216,10 +273,6 @@ private
216
273
 
217
274
  end
218
275
  end
219
-
220
- def get_instance(uri)
221
- nil
222
- end
223
-
276
+
224
277
 
225
278
  end
@@ -21,16 +21,19 @@ module Hugo
21
21
 
22
22
  if options["placement"] and options["placement"]["availabilityZone"]
23
23
  @zone = options["placement"]["availabilityZone"]
24
+ elsif options[:zone]
25
+ @zone = option[:zone]
24
26
  else
25
27
  @zone = ZONE
26
28
  end
27
29
 
28
30
  @uri = options["dnsName"] || ""
29
- @type = options["instanceType"] || TYPE
30
- @image_id = options["imageId"] || AMI
31
+ @type = options[:type] || options["instanceType"]
32
+ @image_id = options[:image_id] || options["imageId"]
33
+ @key_name = options[:key_name] || options["keyName"]
34
+
31
35
  @create_time = options["launchTime"] || nil
32
36
 
33
- @key_name = options[:key_name] || options["keyName"] || KEY_NAME
34
37
  if options["instanceState"] and options["instanceState"]["name"]
35
38
  @status = options["instanceState"]["name"]
36
39
  else
@@ -108,7 +108,7 @@ module Hugo
108
108
  rescue
109
109
  @security_groups = @rds.create_db_security_group(:db_security_group_name => name, :db_security_group_description => description)
110
110
  end
111
- puts @security_groups
111
+ #puts @security_groups
112
112
  @security_groups
113
113
  end
114
114
 
@@ -28,6 +28,38 @@ class Hugo::Balancer
28
28
  )
29
29
  end
30
30
 
31
+ def help
32
+ x = <<HELP
33
+
34
+ Hugo balancer
35
+ -----------------
36
+
37
+ optional attributes
38
+ -----------------
39
+ zone - zone
40
+ port - app server port
41
+ web - balancer port
42
+ ssl_port - ssl app server port
43
+ ssl_web - ssl balancer port
44
+ type - port type
45
+
46
+
47
+ defaults
48
+ -----------------
49
+ DEFAULT_ZONE = 'us-east-1c'
50
+ DEFAULT_PORT = '8080'
51
+ DEFAULT_WEB = '80'
52
+ DEFAULT_TYPE = 'http'
53
+ DEFAULT_SSL_PORT = '8443'
54
+ DEFAULT_SSL_WEB = '443'
55
+
56
+
57
+
58
+ HELP
59
+ puts x
60
+ x
61
+ end
62
+
31
63
  def name(arg=nil)
32
64
  set_or_return(:name, arg, :kind_of => [String])
33
65
  end
@@ -9,7 +9,7 @@ class Hugo::Cloud
9
9
 
10
10
  end
11
11
 
12
- def database(db_name, &block)
12
+ def database(db_name, &block)
13
13
  database = Hugo::Database.instance
14
14
 
15
15
  database.db_security_group name
@@ -18,8 +18,7 @@ class Hugo::Cloud
18
18
 
19
19
  database.instance_eval(&block) if block_given?
20
20
  db database.deploy
21
-
22
-
21
+
23
22
  end
24
23
 
25
24
  def balancer(&block)
@@ -34,7 +33,7 @@ class Hugo::Cloud
34
33
  app_info.name name
35
34
  app_info.lb lb
36
35
  app_info.db db
37
- app_info.cloud_name name
36
+ #app_info.cloud_name name
38
37
  app_info.instance_eval(&block) if block_given?
39
38
  cloud_app app_info
40
39
 
@@ -49,9 +48,10 @@ class Hugo::Cloud
49
48
  end
50
49
 
51
50
  def delete
52
- [db, cloud_app, lb].each do |s|
51
+ [cloud_app, lb].each do |s|
53
52
  s.destroy if s
54
53
  end
54
+ db.rds.destroy
55
55
  end
56
56
 
57
57
 
@@ -108,7 +108,7 @@ REPORT
108
108
  end
109
109
 
110
110
  def db(arg=nil)
111
- set_or_return(:db, arg, :kind_of => [Hugo::Aws::Rds])
111
+ set_or_return(:db, arg, :kind_of => [Hugo::Database])
112
112
  end
113
113
 
114
114
  def lb(arg=nil)
@@ -1,5 +1,6 @@
1
1
  module Hugo; end
2
2
 
3
+ # Lauch Database Servers
3
4
  class Hugo::Database
4
5
  include Singleton
5
6
  include Hugo::Mixin::ParamsValidate
@@ -8,16 +9,25 @@ class Hugo::Database
8
9
  DEFAULT_SIZE = 5
9
10
  DEFAULT_ZONE = 'us-east-1c'
10
11
 
12
+ attr_accessor :rds
11
13
 
14
+ # initialize defaults
12
15
  def initialize
13
16
  size DEFAULT_SIZE
14
17
  zone DEFAULT_ZONE
15
18
  server DEFAULT_SERVER
16
19
  db_security_group "default"
17
20
  end
18
-
21
+
22
+ # deploy using AWS RDS
19
23
  def deploy
20
- Hugo::Aws::Rds.find_or_create( :name => name,
24
+ raise ArgumentError, "database.name Required" unless name
25
+ raise ArgumentError, "database.server Required" unless server
26
+ raise ArgumentError, "database.user Required" unless user
27
+ raise ArgumentError, "database.password Required" unless password
28
+
29
+
30
+ @rds = Hugo::Aws::Rds.find_or_create( :name => name,
21
31
  :server => server,
22
32
  :user => user,
23
33
  :password => password,
@@ -25,8 +35,50 @@ class Hugo::Database
25
35
  :zone => zone,
26
36
  :db_security_group => db_security_group
27
37
  )
38
+ self
39
+ end
40
+
41
+ # clear attributes of database object
42
+ def clear
43
+ @user = nil
44
+ @password = nil
45
+ @server = nil
46
+ end
47
+
48
+ def help
49
+
50
+ x = <<HELP
51
+ Welcome to Hugo::Database
52
+ -------------------------
53
+
54
+ Required Methods:
55
+ -------------------------
56
+ name - Name of Database
57
+ server - Name of Server
58
+ user - A Valid User of RDS Server
59
+ password - A Valid Password of RDS Server
60
+
61
+ Optional Methods:
62
+ -------------------------
63
+ size - Storage Size of you db server
64
+ zone - Zone of the AWS:RDS
65
+
66
+ HELP
67
+ puts x
68
+ x
28
69
  end
29
70
 
71
+ def info
72
+ {
73
+ :uri => @rds.uri,
74
+ :name => @rds.db,
75
+ :user => @rds.user,
76
+ :password => @rds.password
77
+ }
78
+
79
+ end
80
+
81
+
30
82
  def name(arg=nil)
31
83
  set_or_return(:name, arg, :kind_of => [String])
32
84
  end
@@ -9,10 +9,25 @@ describe "Hugo App" do
9
9
 
10
10
  block = lambda do
11
11
  cloud "my_cloud" do
12
+ database "my_db" do
13
+ server "my_server"
14
+ user "hello"
15
+ password "world"
16
+ end
17
+
12
18
  balancer
19
+
13
20
  app "testapp" do
21
+ clear
22
+
23
+ key_name "ec2-keypair"
24
+ key_path "~/.ec2"
25
+ cookbook "git@github.com:jackhq/hugo-cookbooks.git"
26
+
14
27
  servers 0
15
28
  end
29
+ #deploy
30
+ #print
16
31
  end
17
32
  end
18
33
 
@@ -21,6 +36,55 @@ describe "Hugo App" do
21
36
  end.should_not raise_error
22
37
  end
23
38
 
39
+ it "should raise error requiring key_name" do
40
+ lambda do
41
+ Hugo do
42
+ cloud "my_cloud" do
43
+ app "testapp" do
44
+ clear
45
+ key_path "~/.ec2"
46
+ cookbook "my_cookbook"
47
+ run_list ["role[base_rack_apache]"]
48
+ end
49
+ deploy
50
+ end
51
+ end
52
+ end.should raise_error('app.key_name Required')
53
+ end
54
+
55
+ it "should raise error requiring key_path" do
56
+ lambda do
57
+ Hugo do
58
+ cloud "my_cloud" do
59
+ app "testapp" do
60
+ clear
61
+ key_name "ec2-keypair"
62
+ cookbook "my_cookbook"
63
+ run_list ["role[base_rack_apache]"]
64
+ end
65
+ deploy
66
+ end
67
+ end
68
+ end.should raise_error('app.key_path Required')
69
+ end
70
+
71
+ it "should raise error requiring cookbook" do
72
+ lambda do
73
+ Hugo do
74
+ cloud "my_cloud" do
75
+ app "testapp" do
76
+ clear
77
+ key_name "ec2-keypair"
78
+ key_path "~/.ec2"
79
+ run_list ["role[base_rack_apache]"]
80
+ end
81
+ deploy
82
+ end
83
+ end
84
+ end.should raise_error('app.cookbook Required')
85
+ end
86
+
87
+
24
88
  it "should save dna" do
25
89
  block = lambda do
26
90
  cloud "my_cloud" do
@@ -28,8 +92,8 @@ describe "Hugo App" do
28
92
  app "testapp" do
29
93
  add_recipe "s3fs", :s3 => {:bucket => "samIam"}
30
94
  servers 0
31
- puts run_list
32
- puts dna.inspect
95
+ #puts run_list
96
+ #puts dna.inspect
33
97
  end
34
98
  end
35
99
  end
@@ -16,6 +16,7 @@ describe "Hugo Balancer" do
16
16
  Hugo &block
17
17
  end.should_not raise_error
18
18
  end
19
+
19
20
 
20
21
  it "should raise error for balancer block not wrapped in cloud block" do
21
22
  block = lambda do
@@ -34,4 +35,11 @@ describe "Hugo Balancer" do
34
35
 
35
36
  end
36
37
 
38
+ it "should print help for balancer" do
39
+ lb = Hugo::Balancer.instance
40
+ lb.name "myserver"
41
+ lb.help.should =~ /^Hugo balancer/
42
+
43
+ end
44
+
37
45
  end
@@ -5,46 +5,80 @@ describe "Hugo Database" do
5
5
  mocks
6
6
  end
7
7
 
8
+ it "should raise error requiring user" do
9
+ lambda do
10
+ Hugo do
11
+ cloud "my_cloud" do
12
+ database "testapp" do
13
+ clear
14
+ server "server"
15
+ password "test_password"
16
+ end
17
+ end
18
+ end
19
+ end.should raise_error('database.user Required')
20
+ end
21
+
22
+ it "should raise error requiring password" do
23
+ lambda do
24
+ Hugo do
25
+ cloud "my_cloud" do
26
+ database "testapp" do
27
+ clear
28
+ server "server"
29
+ user "test_user"
30
+ end
31
+ end
32
+ end
33
+ end.should raise_error('database.password Required')
34
+ end
35
+
36
+ it "should raise error requiring server" do
37
+ lambda do
38
+ Hugo do
39
+ cloud "my_cloud" do
40
+ database "testapp" do
41
+ clear
42
+ password "test_password"
43
+ user "test_user"
44
+ end
45
+ end
46
+ end
47
+ end.should raise_error('database.server Required')
48
+ end
49
+
8
50
  it "should be valid" do
9
-
10
- block = lambda do
11
- cloud "my_cloud" do
12
- database "testapp" do
13
- server "serverx"
14
- user "test_user"
15
- password "test_password"
51
+
52
+ lambda do
53
+ Hugo do
54
+ cloud "my_cloud" do
55
+ database "testapp" do
56
+ server "serverx"
57
+ user "test_user"
58
+ password "test_password"
59
+ end
16
60
  end
17
61
  end
18
- end
19
-
20
- lambda do
21
- Hugo &block
22
62
  end.should_not raise_error
23
63
  end
24
64
 
25
65
  it "should raise error for database block not wrapped in cloud block" do
26
- block = lambda do
27
- database "mydb" do end
28
- end
29
-
30
66
  lambda do
31
- Hugo &block
67
+ Hugo { database "mydb" }
32
68
  end.should raise_error
33
69
  end
34
70
 
35
71
  it "should not raise error for database block wrapped in cloud block" do
36
- block = lambda do
37
- cloud "mycloud" do
38
- database "mydb" do end
39
- end
40
- end
41
-
42
72
  lambda do
43
- Hugo &block
73
+ Hugo do
74
+ cloud "mycloud" do
75
+ database "mydb" do end
76
+ end
77
+ end
44
78
  end.should be_true
45
79
  end
46
80
  end
47
-
81
+ #
48
82
  describe Hugo::Database do
49
83
  before(:each) do
50
84
  mocks
@@ -58,9 +92,40 @@ describe Hugo::Database do
58
92
  db.name "mydb"
59
93
  db.user "admin"
60
94
  db.password "test"
61
- db.deploy.should be_a_kind_of(Hugo::Aws::Rds)
95
+ db.deploy.should be_a_kind_of(Hugo::Database)
62
96
  end
63
97
 
98
+ it "should clear required attributes" do
99
+ db = Hugo::Database.instance
100
+ db.server "myserver"
101
+ db.name "mydb"
102
+ db.user "admin"
103
+ db.password "test"
104
+ db.clear
105
+ db.server.should be_nil
106
+ db.user.should be_nil
107
+ db.password.should be_nil
108
+
109
+ end
110
+
111
+ it "should print help for database" do
112
+ db = Hugo::Database.instance
113
+ db.name "myserver"
114
+ db.help.should =~ /^Welcome to Hugo/
115
+
116
+ end
117
+
118
+ it "should return an info hash" do
119
+ db = Hugo::Database.instance
120
+ db.server "myserver"
121
+ db.name "mydb"
122
+ db.user "admin"
123
+ db.password "test"
124
+ db.deploy
125
+ db.info.inspect.should == '{:user=>"user", :uri=>"test.cwrzj6lxowfj.us-east-1.rds.amazonaws.com", :password=>"test", :name=>"mydb"}'
126
+ end
127
+
128
+
64
129
 
65
130
  end
66
131
 
@@ -23,6 +23,31 @@ describe "Hugo DSL" do
23
23
  end.should be_true
24
24
  end
25
25
 
26
+ it "should deploy a single server app" do
27
+ block = lambda do
28
+ cloud "my_cloud" do
29
+ database "db_name" do
30
+ server "db_server"
31
+ user "admin"
32
+ password "mypassword"
33
+ end
34
+
35
+ balancer
36
+
37
+ app "app_name" do
38
+
39
+
40
+ end
41
+ end
42
+ end
43
+
44
+ lambda do
45
+ Hugo &block
46
+ end.should be_true
47
+
48
+ end
49
+
50
+
26
51
 
27
52
 
28
53
  it "should deploy infrastructure" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hugo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Wilson