dew 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require 'opensrs'
2
+
1
3
  class Cloud
2
4
 
3
5
  attr_reader :region, :account_name, :profile_name
@@ -64,6 +66,14 @@ class Cloud
64
66
  account_dir = File.join(ENV['HOME'], '.dew','accounts')
65
67
  File.join(account_dir, 'keys', account_name, region, "#{key_name}.pem")
66
68
  end
69
+
70
+ def has_dns?
71
+ account.has_dns?
72
+ end
73
+
74
+ def dns
75
+ @dns ||= OpenSRS::Server.new(account.opensrs_credentials)
76
+ end
67
77
 
68
78
  private
69
79
 
@@ -20,6 +20,7 @@ class DeployCommand < Clamp::Command
20
20
  option ['--ssl-certificate'], 'FILE', "SSL Certificate file"
21
21
  option ['--ssl-private-key'], 'FILE', "SSL Private Key file"
22
22
  option ['--[no-]passenger'], :flag, "Use passenger (just server public/* if unset)", :default => true, :attribute_name => :use_passenger
23
+ option ['--gamej-proxy'], 'GAMEJ_PROXY', "GameJ Reverse Proxy"
23
24
 
24
25
  def check_and_remove_rvmrc
25
26
  if ssh.exist? "#{application_name}/.rvmrc"
@@ -75,14 +76,14 @@ class DeployCommand < Clamp::Command
75
76
 
76
77
  check_and_remove_rvmrc
77
78
  Inform.debug("Checking out version %{version}", :version => revision)
78
- ssh.run "cd #{application_name} && git checkout -q -f origin/#{revision}"
79
+ ssh.run "cd #{application_name} && git checkout -q -f #{revision}"
79
80
  check_and_remove_rvmrc
80
81
  end
81
82
 
82
83
  cd_and_rvm = "cd #{application_name} && . /usr/local/rvm/scripts/rvm && rvm use ruby-1.9.2 && RAILS_ENV=#{rails_env} "
83
84
 
84
85
  Inform.info("Updating/installing gems") do
85
- ssh.run cd_and_rvm + "bundle install"
86
+ ssh.run cd_and_rvm + "bundle install --without development"
86
87
  end
87
88
 
88
89
  if ssh.exist?("#{application_name}/config/database.yml")
@@ -109,6 +110,9 @@ class DeployCommand < Clamp::Command
109
110
  end
110
111
 
111
112
  if use_ssl?
113
+ Inform.info "Enabling Mod SSL" do
114
+ ssh.run "sudo a2enmod ssl"
115
+ end
112
116
  Inform.info "Uploading SSL Certificate & Private Key" do
113
117
  ssh.run "sudo mkdir -p /etc/apache2/certs" unless ssh.exist?("/etc/apache2/certs")
114
118
  ssh.upload ssl_certificate, "/tmp/sslcert"
@@ -117,6 +121,13 @@ class DeployCommand < Clamp::Command
117
121
  ssh.run "sudo mv -f /tmp/sslkey /etc/apache2/certs/#{application_name}.key"
118
122
  end
119
123
  end
124
+
125
+ if gamej_proxy
126
+ Inform.info "Enabling Mod Proxy" do
127
+ ssh.run "sudo a2enmod proxy"
128
+ ssh.run "sudo a2enmod proxy_http"
129
+ end
130
+ end
120
131
 
121
132
  Inform.info("Starting application") do
122
133
  if ssh.exist?('/etc/apache2/sites-enabled/000-default')
@@ -130,7 +141,8 @@ class DeployCommand < Clamp::Command
130
141
  :server_name => server_name,
131
142
  :rails_env => rails_env,
132
143
  :application_name => application_name,
133
- :working_directory => "/home/ubuntu/#{application_name}"
144
+ :working_directory => "/home/ubuntu/#{application_name}",
145
+ :gamej_proxy => gamej_proxy
134
146
  ).instance_eval {binding})
135
147
  ssh.write passenger_config, "/tmp/apache.conf"
136
148
  ssh.run "sudo cp /tmp/apache.conf /etc/apache2/sites-available/#{application_name}"
@@ -34,8 +34,21 @@
34
34
  LogLevel warn
35
35
 
36
36
  CustomLog /var/log/apache2/<%= application_name %>-access.log combined
37
+
38
+ <% if gamej_proxy %>
39
+ <Location /api>
40
+ Order allow,deny
41
+ Allow from all
42
+ </Location>
43
+
44
+ # Proxy off to the engine
45
+ ProxyRequests Off
46
+ ProxyPass /api/ http://<%= gamej_proxy %>/
47
+ ProxyPassReverse /api/ http://<%= server_name %>/
48
+ <% end %>
37
49
  </VirtualHost>
38
50
  <% if use_ssl? %>
51
+ NameVirtualHost *:443
39
52
  <VirtualHost *:443>
40
53
  ServerAdmin admin@playup.com
41
54
 
@@ -77,6 +90,17 @@
77
90
 
78
91
  CustomLog /var/log/apache2/<%= application_name %>-access.log combined
79
92
 
93
+ <% if gamej_proxy %>
94
+ <Location /api>
95
+ Order allow,deny
96
+ Allow from all
97
+ </Location>
98
+
99
+ # Proxy off to the engine
100
+ SSLProxyEngine on
101
+ ProxyRequests Off
102
+ ProxyPass /api/ https://<%= gamej_proxy %>/
103
+ ProxyPassReverse /api/ https://<%= server_name %>/
104
+ <% end %>
80
105
  </VirtualHost>
81
106
  <% end %>
82
-
@@ -88,6 +88,34 @@ class EnvironmentsCommand < Clamp::Command
88
88
  end
89
89
  end
90
90
  end
91
+
92
+ subcommand "run", "Run a script or command on each instance in the environment" do
93
+ parameter "ENVIRONMENT_NAME", "Name of the environment"
94
+ option ['-s', '--script'], "FILENAME", "Script to run on each instance"
95
+ option ['-c', '--command'], "COMMAND", "Command to run on each instance"
96
+
97
+ def execute
98
+ raise "Please supply either -s or -c" unless script or command
99
+
100
+ env = Environment.get(environment_name)
101
+
102
+ Inform.info("Running on %{l} servers", :l => env.servers.length) do
103
+ env.servers.each do |server|
104
+ start = Time.now
105
+ ssh = server.ssh
106
+ if script
107
+ ssh.upload(script, '/tmp/script')
108
+ ssh.run("chmod +x /tmp/script")
109
+ ssh.run("/tmp/script", :quiet => false)
110
+ ssh.run("rm /tmp/script")
111
+ else
112
+ ssh.run(command, :quiet => false)
113
+ end
114
+ Inform.debug("%{s} took %{time} seconds", :s => server.id, :time => (Time.now - start))
115
+ end
116
+ end
117
+ end
118
+ end
91
119
 
92
120
  subcommand "destroy", "Destroy an existing environment" do
93
121
 
@@ -23,6 +23,26 @@ class Account
23
23
  def aws_user_id
24
24
  @yaml['aws']['user_id'].gsub('-', '')
25
25
  end
26
+
27
+ def has_dns?
28
+ @yaml.include?('dns')
29
+ end
30
+
31
+ def dns_username
32
+ @yaml['dns']['username']
33
+ end
34
+
35
+ def dns_password
36
+ @yaml['dns']['password']
37
+ end
38
+
39
+ def dns_domain
40
+ @yaml['dns']['domain']
41
+ end
42
+
43
+ def dns_prefix
44
+ @yaml['dns']['prefix']
45
+ end
26
46
 
27
47
  def initialize(yaml)
28
48
  @yaml = yaml
@@ -1,3 +1,3 @@
1
1
  module Dew
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -7,8 +7,8 @@ describe :Cloud do
7
7
  let (:profile_name) { 'test-light' }
8
8
 
9
9
  let (:aws_credentials) { {:aws_access_key_id => '1234', :aws_secret_access_key => '5678', :region => region} }
10
- let (:root_aws_credentials) { aws_credentials.merge(:provider => 'AWS')}
11
- let (:account) { double('Account', aws_credentials) }
10
+ let (:root_aws_credentials) { aws_credentials.merge(:provider => 'AWS') }
11
+ let (:account) { double('Account', aws_credentials.merge(:has_dns? => false)) }
12
12
  let (:profile) { double('Profile') }
13
13
 
14
14
  context "after connect is called" do
@@ -86,5 +86,19 @@ describe :Cloud do
86
86
  end
87
87
  end
88
88
 
89
+ it { Cloud.has_dns?.should be_false }
90
+
91
+ context "with DNS credentials in the account" do
92
+ before :each do
93
+ account.stub(:has_dns? => true)
94
+ end
95
+ it { Cloud.has_dns?.should be_true }
96
+
97
+ it "should provide an OpenSRS DNS handle" do
98
+ Cloud.account.should_receive(:opensrs_credentials).and_return('opensrs creds')
99
+ OpenSRS::Server.should_receive(:new).with('opensrs creds').and_return('server')
100
+ Cloud.dns.should == 'server'
101
+ end
102
+ end
89
103
  end
90
104
  end
@@ -12,26 +12,43 @@ describe Account do
12
12
 
13
13
  describe "parsing yaml" do
14
14
  before :each do
15
- yaml =
15
+ File.stub(:read).and_return(yaml)
16
+ end
17
+
18
+ subject { Account.read('foo') }
19
+
20
+ describe "with an aws section" do
21
+ let (:yaml) {
16
22
  "aws:
17
23
  user_id: 9999-3333-2222
18
24
  access_key_id: foo
19
25
  secret_access_key: bar"
26
+ }
20
27
 
21
- File.stub(:read).and_return(yaml)
22
- @account = Account.read('foo')
23
- end
24
-
25
- it "should have a user_id stripped of dashes" do
26
- @account.aws_user_id.should == '999933332222'
27
- end
28
+ it "should have a user_id stripped of dashes" do
29
+ subject.aws_user_id.should == '999933332222'
30
+ end
28
31
 
29
- it "should have an aws access key id" do
30
- @account.aws_access_key_id.should == 'foo'
32
+ it { subject.aws_access_key_id.should == 'foo' }
33
+ it { subject.aws_secret_access_key.should == 'bar' }
34
+ it { subject.has_dns?.should be_false }
31
35
  end
32
36
 
33
- it "should have an aws secret access key" do
34
- @account.aws_secret_access_key.should == 'bar'
37
+ describe "with a DNS section" do
38
+ let (:yaml) {
39
+ "
40
+ dns:
41
+ username: bob
42
+ domain: mydomain.com
43
+ password: steve
44
+ prefix: env
45
+ "
46
+ }
47
+ it { subject.has_dns?.should be_true }
48
+ it { subject.dns_username.should == 'bob' }
49
+ it { subject.dns_domain.should == 'mydomain.com' }
50
+ it { subject.dns_password.should == 'steve' }
51
+ it { subject.dns_prefix.should == 'env' }
35
52
  end
36
53
  end
37
54
 
@@ -43,5 +60,6 @@ describe Account do
43
60
  Account.user_ids.sort.should == ['id1', 'id2']
44
61
  end
45
62
  end
63
+
46
64
 
47
65
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dew
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - PlayUp Devops
@@ -15,12 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-05 00:00:00 Z
18
+ date: 2011-07-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: inform
22
22
  prerelease: false
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ~>
@@ -32,11 +32,11 @@ dependencies:
32
32
  - 4
33
33
  version: 0.0.4
34
34
  type: :runtime
35
- requirement: *id001
35
+ version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: clamp
38
38
  prerelease: false
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -48,11 +48,11 @@ dependencies:
48
48
  - 0
49
49
  version: 0.2.0
50
50
  type: :runtime
51
- requirement: *id002
51
+ version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: fog
54
54
  prerelease: false
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -64,11 +64,11 @@ dependencies:
64
64
  - 2
65
65
  version: 0.8.2
66
66
  type: :runtime
67
- requirement: *id003
67
+ version_requirements: *id003
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: gofer
70
70
  prerelease: false
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -80,11 +80,11 @@ dependencies:
80
80
  - 5
81
81
  version: 0.2.5
82
82
  type: :runtime
83
- requirement: *id004
83
+ version_requirements: *id004
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: highline
86
86
  prerelease: false
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
90
90
  - - ~>
@@ -96,11 +96,11 @@ dependencies:
96
96
  - 2
97
97
  version: 1.6.2
98
98
  type: :runtime
99
- requirement: *id005
99
+ version_requirements: *id005
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: terminal-table
102
102
  prerelease: false
103
- version_requirements: &id006 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
104
104
  none: false
105
105
  requirements:
106
106
  - - ~>
@@ -112,11 +112,25 @@ dependencies:
112
112
  - 2
113
113
  version: 1.4.2
114
114
  type: :runtime
115
- requirement: *id006
115
+ version_requirements: *id006
116
+ - !ruby/object:Gem::Dependency
117
+ name: opensrs
118
+ prerelease: false
119
+ requirement: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ type: :runtime
129
+ version_requirements: *id007
116
130
  - !ruby/object:Gem::Dependency
117
131
  name: nokogiri
118
132
  prerelease: false
119
- version_requirements: &id007 !ruby/object:Gem::Requirement
133
+ requirement: &id008 !ruby/object:Gem::Requirement
120
134
  none: false
121
135
  requirements:
122
136
  - - ">="
@@ -126,11 +140,11 @@ dependencies:
126
140
  - 0
127
141
  version: "0"
128
142
  type: :runtime
129
- requirement: *id007
143
+ version_requirements: *id008
130
144
  - !ruby/object:Gem::Dependency
131
145
  name: rake
132
146
  prerelease: false
133
- version_requirements: &id008 !ruby/object:Gem::Requirement
147
+ requirement: &id009 !ruby/object:Gem::Requirement
134
148
  none: false
135
149
  requirements:
136
150
  - - ~>
@@ -142,11 +156,11 @@ dependencies:
142
156
  - 7
143
157
  version: 0.8.7
144
158
  type: :development
145
- requirement: *id008
159
+ version_requirements: *id009
146
160
  - !ruby/object:Gem::Dependency
147
161
  name: rspec
148
162
  prerelease: false
149
- version_requirements: &id009 !ruby/object:Gem::Requirement
163
+ requirement: &id010 !ruby/object:Gem::Requirement
150
164
  none: false
151
165
  requirements:
152
166
  - - ~>
@@ -158,11 +172,11 @@ dependencies:
158
172
  - 0
159
173
  version: 2.6.0
160
174
  type: :development
161
- requirement: *id009
175
+ version_requirements: *id010
162
176
  - !ruby/object:Gem::Dependency
163
177
  name: cucumber
164
178
  prerelease: false
165
- version_requirements: &id010 !ruby/object:Gem::Requirement
179
+ requirement: &id011 !ruby/object:Gem::Requirement
166
180
  none: false
167
181
  requirements:
168
182
  - - ~>
@@ -174,11 +188,11 @@ dependencies:
174
188
  - 3
175
189
  version: 0.10.3
176
190
  type: :development
177
- requirement: *id010
191
+ version_requirements: *id011
178
192
  - !ruby/object:Gem::Dependency
179
193
  name: simplecov
180
194
  prerelease: false
181
- version_requirements: &id011 !ruby/object:Gem::Requirement
195
+ requirement: &id012 !ruby/object:Gem::Requirement
182
196
  none: false
183
197
  requirements:
184
198
  - - ~>
@@ -190,11 +204,11 @@ dependencies:
190
204
  - 0
191
205
  version: 0.4.0
192
206
  type: :development
193
- requirement: *id011
207
+ version_requirements: *id012
194
208
  - !ruby/object:Gem::Dependency
195
209
  name: flay
196
210
  prerelease: false
197
- version_requirements: &id012 !ruby/object:Gem::Requirement
211
+ requirement: &id013 !ruby/object:Gem::Requirement
198
212
  none: false
199
213
  requirements:
200
214
  - - ~>
@@ -206,11 +220,11 @@ dependencies:
206
220
  - 2
207
221
  version: 1.4.2
208
222
  type: :development
209
- requirement: *id012
223
+ version_requirements: *id013
210
224
  - !ruby/object:Gem::Dependency
211
225
  name: geminabox
212
226
  prerelease: false
213
- version_requirements: &id013 !ruby/object:Gem::Requirement
227
+ requirement: &id014 !ruby/object:Gem::Requirement
214
228
  none: false
215
229
  requirements:
216
230
  - - ">="
@@ -220,7 +234,7 @@ dependencies:
220
234
  - 0
221
235
  version: "0"
222
236
  type: :development
223
- requirement: *id013
237
+ version_requirements: *id014
224
238
  description: |
225
239
  Dew is a layer between fog and the ground
226
240