engineyard 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/engineyard.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module EY
2
2
  require 'engineyard/ruby_ext'
3
3
  require 'engineyard/version'
4
- require 'engineyard/serverside_version'
5
4
 
6
5
  autoload :API, 'engineyard/api'
7
6
  autoload :Collection, 'engineyard/collection'
@@ -51,7 +51,7 @@ module EY
51
51
 
52
52
  def self.request(path, opts={})
53
53
  require 'rest_client'
54
- require 'json/pure'
54
+ require 'json'
55
55
 
56
56
  url = EY.config.endpoint + "api/v2#{path}"
57
57
  method = ((meth = opts.delete(:method)) && meth.to_s || "get").downcase.to_sym
@@ -61,10 +61,6 @@ module EY
61
61
  raise(DeployArgumentError)
62
62
  end
63
63
 
64
- EY.ui.info "Connecting to the server..."
65
-
66
- loudly_check_engineyard_serverside(environment)
67
-
68
64
  EY.ui.info "Beginning deploy for '#{app.name}' in '#{environment.name}' on server..."
69
65
 
70
66
  deploy_options = {'extras' => options[:extra_deploy_hook_options]}
@@ -148,8 +144,6 @@ module EY
148
144
  app = fetch_app(options[:app])
149
145
  env = fetch_environment(options[:environment], app)
150
146
 
151
- loudly_check_engineyard_serverside(env)
152
-
153
147
  EY.ui.info("Rolling back '#{app.name}' in '#{env.name}'")
154
148
  if env.rollback(app,
155
149
  options[:extra_deploy_hook_options],
@@ -12,7 +12,6 @@ module EY
12
12
  def enable
13
13
  app = fetch_app(options[:app])
14
14
  environment = fetch_environment(options[:environment], app)
15
- loudly_check_engineyard_serverside(environment)
16
15
  EY.ui.info "Taking down maintenance page for '#{app.name}' in '#{environment.name}'"
17
16
  environment.take_down_maintenance_page(app, options[:verbose])
18
17
  end
@@ -39,7 +38,6 @@ module EY
39
38
  def disable
40
39
  app = fetch_app(options[:app])
41
40
  environment = fetch_environment(options[:environment], app)
42
- loudly_check_engineyard_serverside(environment)
43
41
  EY.ui.info "Putting up maintenance page for '#{app.name}' in '#{environment.name}'"
44
42
  environment.put_up_maintenance_page(app, options[:verbose])
45
43
  end
@@ -14,8 +14,10 @@ module EY
14
14
 
15
15
  def self.from_hash(hash)
16
16
  return nil unless hash
17
- members = new.members
18
- values = members.map{|a| hash.has_key?(a.to_sym) ? hash[a.to_sym] : hash[a] }
17
+ # in ruby 1.8, #members is an array of strings
18
+ # in ruby 1.9, #members is an array of symbols
19
+ members = new.members.map {|m| m.to_sym}
20
+ values = members.map{|a| hash.has_key?(a) ? hash[a] : hash[a.to_s] }
19
21
  new(*values)
20
22
  end
21
23
 
@@ -31,10 +31,6 @@ module EY
31
31
  master
32
32
  end
33
33
 
34
- def ensure_engineyard_serverside_present(&blk)
35
- app_master!.ensure_engineyard_serverside_present(&blk)
36
- end
37
-
38
34
  def deploy(app, ref, deploy_options={})
39
35
  app_master!.deploy(app,
40
36
  ref,
@@ -3,99 +3,51 @@ require 'escape'
3
3
  module EY
4
4
  module Model
5
5
  class Instance < ApiStruct.new(:id, :role, :name, :status, :amazon_id, :public_hostname, :environment)
6
- EXIT_STATUS = Hash.new { |h,k| raise EY::Error, "engineyard-serverside version checker exited with unknown status code #{k}" }
7
- EXIT_STATUS.merge!({
8
- 255 => :ssh_failed,
9
- 1 => :engineyard_serverside_missing,
10
- 0 => :ok,
11
- })
12
-
13
6
  alias :hostname :public_hostname
14
7
 
15
-
16
- def deploy(app, ref, migration_command=nil, extra_configuration=nil, verbose=false)
17
- deploy_args = [
18
- '--app', app.name,
19
- '--repo', app.repository_uri,
20
- '--stack', environment.stack_name,
21
- '--branch', ref,
22
- ]
23
-
24
- if extra_configuration
25
- deploy_args << '--config' << extra_configuration.to_json
8
+ def adapter(app, verbose)
9
+ require 'engineyard-serverside-adapter'
10
+ EY::Serverside::Adapter.new("/usr/local/ey_resin/ruby/bin") do |args|
11
+ args.app = app.name
12
+ args.repo = app.repository_uri
13
+ args.instances = instances_data
14
+ args.verbose = verbose || ENV['DEBUG']
15
+ args.stack = environment.stack_name
16
+ args.framework_env = environment.framework_env
26
17
  end
18
+ end
19
+ private :adapter
27
20
 
28
- if migration_command
29
- deploy_args << "--migrate" << migration_command
21
+ def deploy(app, ref, migration_command=nil, extra_configuration=nil, verbose=false)
22
+ deploy_command = adapter(app, verbose).deploy do |args|
23
+ args.config = extra_configuration if extra_configuration
24
+ args.migrate = migration_command if migration_command
25
+ args.ref = ref
30
26
  end
31
27
 
32
- invoke_engineyard_serverside(deploy_args, verbose)
28
+ invoke deploy_command
33
29
  end
34
30
 
35
31
  def rollback(app, extra_configuration=nil, verbose=false)
36
- deploy_args = ['rollback',
37
- '--app', app.name,
38
- '--stack', environment.stack_name,
39
- ]
40
-
41
- if extra_configuration
42
- deploy_args << '--config' << extra_configuration.to_json
32
+ rollback = adapter(app, verbose).rollback do |args|
33
+ args.config = extra_configuration if extra_configuration
43
34
  end
44
-
45
- invoke_engineyard_serverside(deploy_args, verbose)
35
+ invoke rollback
46
36
  end
47
37
 
48
38
 
49
39
  def put_up_maintenance_page(app, verbose=false)
50
- invoke_engineyard_serverside(['enable_maintenance_page', '--app', app.name], verbose)
40
+ invoke adapter(app, verbose).enable_maintenance_page
51
41
  end
52
42
 
53
43
  def take_down_maintenance_page(app, verbose=false)
54
- invoke_engineyard_serverside(['disable_maintenance_page', '--app', app.name], verbose)
44
+ invoke adapter(app, verbose).disable_maintenance_page
55
45
  end
56
46
 
57
-
58
47
  def has_app_code?
59
48
  !["db_master", "db_slave"].include?(role.to_s)
60
49
  end
61
50
 
62
- def ensure_engineyard_serverside_present
63
- case engineyard_serverside_status = engineyard_serverside_check
64
- when :ssh_failed
65
- raise EnvironmentError, "SSH connection to #{hostname} failed"
66
- when :engineyard_serverside_missing
67
- yield :installing if block_given?
68
- install_engineyard_serverside
69
- when :ok
70
- # no action needed
71
- else
72
- raise EY::Error, "Internal error: Unexpected status from Instance#engineyard_serverside_check; got #{engineyard_serverside_status.inspect}"
73
- end
74
- end
75
-
76
- def engineyard_serverside_check
77
- escaped_engineyard_serverside_version = ENGINEYARD_SERVERSIDE_VERSION.gsub(/\./, '\.')
78
-
79
- if ENV["NO_SSH"]
80
- :ok
81
- else
82
- ssh "#{gem_path} list engineyard-serverside | grep \"engineyard-serverside\" | egrep -q '#{escaped_engineyard_serverside_version}[,)]'", false
83
- EXIT_STATUS[$?.exitstatus]
84
- end
85
- end
86
-
87
- def install_engineyard_serverside
88
- ssh(Escape.shell_command([
89
- 'sudo', 'sh', '-c',
90
- # rubygems looks at *.gem in its current directory for
91
- # installation candidates, so we have to make sure it
92
- # runs from a directory with no gem files in it.
93
- #
94
- # rubygems help suggests that --remote will disable this
95
- # behavior, but it doesn't.
96
- "cd `mktemp -d` && #{gem_path} install engineyard-serverside --no-rdoc --no-ri -v #{ENGINEYARD_SERVERSIDE_VERSION}"]))
97
- end
98
-
99
51
  protected
100
52
 
101
53
  def engineyard_serverside_hostname
@@ -123,50 +75,26 @@ module EY
123
75
  end
124
76
  end
125
77
 
126
- def invoke_engineyard_serverside(deploy_args, verbose=false)
127
- start = [engineyard_serverside_path, "_#{ENGINEYARD_SERVERSIDE_VERSION}_", 'deploy']
128
-
129
- instances = environment.instances.select { |inst| inst.has_app_code? }
130
- instance_args = ['']
131
- if !instances.empty?
132
- instance_args << '--instances'
133
- instance_args += instances.collect { |i| i.engineyard_serverside_hostname }
134
-
135
- instance_args << '--instance-roles'
136
- instance_args += instances.collect { |i| [i.engineyard_serverside_hostname, i.role].join(':') }
137
-
138
- instance_names = instances.collect { |i| i.name ? [i.engineyard_serverside_hostname, i.name].join(':') : nil }.compact
139
- unless instance_names.empty?
140
- instance_args << '--instance-names'
141
- instance_args += instance_names
142
- end
78
+ def invoke(action)
79
+ action.call do |cmd|
80
+ puts cmd if action.verbose
81
+ ssh cmd
143
82
  end
144
-
145
- framework_arg = ['--framework-env', environment.framework_env]
146
-
147
- verbose_arg = (verbose || ENV['DEBUG']) ? ['--verbose'] : []
148
-
149
- cmd = Escape.shell_command(start + deploy_args + framework_arg + instance_args + verbose_arg)
150
- puts cmd if verbose
151
- ssh cmd
152
83
  end
153
84
 
154
- def engineyard_serverside_path
155
- "/usr/local/ey_resin/ruby/bin/engineyard-serverside"
85
+ def instances_data
86
+ environment.instances.select { |inst| inst.has_app_code? }.map do |i|
87
+ {
88
+ :hostname => i.engineyard_serverside_hostname,
89
+ :roles => [i.role],
90
+ :name => i.name,
91
+ }
92
+ end
156
93
  end
157
94
 
158
95
  def app_master?
159
96
  environment.app_master == self
160
97
  end
161
-
162
- def gem_path
163
- "/usr/local/ey_resin/ruby/bin/gem"
164
- end
165
-
166
- def ruby_path
167
- "/usr/local/ey_resin/ruby/bin/ruby"
168
- end
169
-
170
98
  end
171
99
  end
172
100
  end
@@ -21,7 +21,7 @@ module EY
21
21
  end
22
22
 
23
23
  def urls
24
- lines = `git config -f #{Escape.shell_command(@path)}/.git/config --get-regexp 'remote.*.url'`.split(/\n/)
24
+ lines = `git config -f #{Escape.shell_command([@path])}/.git/config --get-regexp 'remote.*.url'`.split(/\n/)
25
25
  raise NoRemotesError.new(@path) if lines.empty?
26
26
  lines.map { |c| c.split.last }
27
27
  end
@@ -11,20 +11,6 @@ module EY
11
11
  @repo ||= EY::Repo.new
12
12
  end
13
13
 
14
- def loudly_check_engineyard_serverside(environment)
15
- environment.ensure_engineyard_serverside_present do |action|
16
- case action
17
- when :installing
18
- EY.ui.warn "Instance does not have server-side component installed"
19
- EY.ui.info "Installing server-side component..."
20
- when :upgrading
21
- EY.ui.info "Upgrading server-side component..."
22
- else
23
- # nothing slow is happening, so there's nothing to say
24
- end
25
- end
26
- end
27
-
28
14
  # if an app is supplied, it is used as a constraint for implied environment lookup
29
15
  def fetch_environment(env_name, app = nil)
30
16
  env_name ||= EY.config.default_environment
@@ -1,3 +1,3 @@
1
1
  module EY
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -165,6 +165,17 @@ describe "ey deploy" do
165
165
  end
166
166
  end
167
167
 
168
+ context "the --framework-env option" do
169
+ before(:each) do
170
+ api_scenario "one app, one environment"
171
+ end
172
+
173
+ it "passes the framework environment" do
174
+ ey "deploy"
175
+ @ssh_commands.last.should match(/--framework-env production/)
176
+ end
177
+ end
178
+
168
179
  context "choosing something to deploy" do
169
180
  define_git_repo('deploy test') do
170
181
  # we'll have one commit on master
@@ -188,27 +199,27 @@ describe "ey deploy" do
188
199
  context "without a configured default branch" do
189
200
  it "defaults to the checked-out local branch" do
190
201
  ey "deploy"
191
- @ssh_commands.last.should =~ /--branch current-branch/
202
+ @ssh_commands.last.should =~ /--ref current-branch/
192
203
  end
193
204
 
194
205
  it "deploys another branch if given" do
195
206
  ey "deploy --ref master"
196
- @ssh_commands.last.should =~ /--branch master/
207
+ @ssh_commands.last.should =~ /--ref master/
197
208
  end
198
209
 
199
210
  it "deploys a tag if given" do
200
211
  ey "deploy --ref v1"
201
- @ssh_commands.last.should =~ /--branch v1/
212
+ @ssh_commands.last.should =~ /--ref v1/
202
213
  end
203
214
 
204
215
  it "allows using --branch to specify a branch" do
205
216
  ey "deploy --branch master"
206
- @ssh_commands.last.should match(/--branch master/)
217
+ @ssh_commands.last.should match(/--ref master/)
207
218
  end
208
219
 
209
220
  it "allows using --tag to specify the tag" do
210
221
  ey "deploy --tag v1"
211
- @ssh_commands.last.should match(/--branch v1/)
222
+ @ssh_commands.last.should match(/--ref v1/)
212
223
  end
213
224
  end
214
225
 
@@ -238,7 +249,7 @@ describe "ey deploy" do
238
249
 
239
250
  it "deploys the default branch by default" do
240
251
  ey "deploy"
241
- @ssh_commands.last.should =~ /--branch master/
252
+ @ssh_commands.last.should =~ /--ref master/
242
253
  end
243
254
 
244
255
  it "complains about a non-default branch without --ignore-default_branch" do
@@ -248,7 +259,7 @@ describe "ey deploy" do
248
259
 
249
260
  it "deploys a non-default branch with --ignore-default-branch" do
250
261
  ey "deploy -r current-branch --ignore-default-branch"
251
- @ssh_commands.last.should =~ /--branch current-branch/
262
+ @ssh_commands.last.should =~ /--ref current-branch/
252
263
  end
253
264
  end
254
265
  end
@@ -315,7 +326,7 @@ describe "ey deploy" do
315
326
  it "allows you to specify an app when not in a directory" do
316
327
  ey "deploy --app rails232app --ref master"
317
328
  @ssh_commands.last.should match(/--app rails232app/)
318
- @ssh_commands.last.should match(/--branch master/)
329
+ @ssh_commands.last.should match(/--ref master/)
319
330
  end
320
331
 
321
332
  it "requires that you specify a ref when specifying the application" do
@@ -55,7 +55,7 @@ describe "ey rollback" do
55
55
  after { File.unlink("ey.yml") }
56
56
 
57
57
  it "overrides what's in ey.yml" do
58
- ey "deploy --extra-deploy-hook-options beer:esb"
58
+ ey "rollback --extra-deploy-hook-options beer:esb"
59
59
  extra_deploy_hook_options['beer'].should == 'esb'
60
60
  end
61
61
  end
@@ -150,8 +150,8 @@ shared_examples_for "it invokes engineyard-serverside" do
150
150
 
151
151
  it "passes along instance information to engineyard-serverside" do
152
152
  instance_args = [
153
- /--instances localhost app_hostname[^\s]+ util_fluffy/,
154
- /--instance-roles localhost:app_master app_hostname[^\s]+:app util_fluffy[^\s]+:util/,
153
+ /--instances app_hostname[^\s]+ localhost util_fluffy/,
154
+ /--instance-roles app_hostname[^\s]+:app localhost:app_master util_fluffy[^\s]+:util/,
155
155
  /--instance-names util_fluffy_hostname[^\s]+:fluffy/
156
156
  ]
157
157
 
@@ -166,9 +166,6 @@ shared_examples_for "it invokes engineyard-serverside" do
166
166
  @ssh_commands.last.should_not =~ /#{db_instance}/
167
167
  end
168
168
 
169
- it "passes the framework environment" do
170
- @ssh_commands.last.should match(/--framework-env production/)
171
- end
172
169
  end
173
170
 
174
171
  context "when no instances have names" do
@@ -181,48 +178,6 @@ shared_examples_for "it invokes engineyard-serverside" do
181
178
  @ssh_commands.last.should_not include("--instance-names")
182
179
  end
183
180
  end
184
-
185
-
186
- context "engineyard-serverside installation" do
187
- before(:all) do
188
- api_scenario "one app, one environment"
189
- end
190
-
191
- before(:each) do
192
- ENV.delete "NO_SSH"
193
- end
194
-
195
- after(:each) do
196
- ENV['NO_SSH'] = "true"
197
- end
198
-
199
- def exiting_ssh(exit_code)
200
- "#!/usr/bin/env ruby\n exit!(#{exit_code}) if ARGV.to_s =~ /gem list engineyard-serverside/"
201
- end
202
-
203
- it "raises an error if SSH fails" do
204
- run_ey({:env => 'giblets'},
205
- {:prepend_to_path => {'ssh' => exiting_ssh(255)}, :expect_failure => true})
206
- @err.should =~ /SSH connection to \S+ failed/
207
- end
208
-
209
- it "installs engineyard-serverside if it's missing" do
210
- run_ey({:env => 'giblets'}, {:prepend_to_path => {'ssh' => exiting_ssh(1)}})
211
-
212
- gem_install_command = @ssh_commands.find do |command|
213
- command =~ /gem install engineyard-serverside/
214
- end
215
- gem_install_command.should_not be_nil
216
- gem_install_command.should =~ %r{/usr/local/ey_resin/ruby/bin/gem install.*engineyard-serverside}
217
- end
218
-
219
- it "does not try to install engineyard-serverside if it's already there" do
220
- run_ey({:env => 'giblets'}, {:prepend_to_path => {'ssh' => exiting_ssh(0)}})
221
- @ssh_commands.should_not have_command_like(/gem install engineyard-serverside/)
222
- ver = Regexp.quote(EY::ENGINEYARD_SERVERSIDE_VERSION)
223
- @ssh_commands.should have_command_like(/engineyard-serverside _#{ver}_ deploy/)
224
- end
225
- end
226
181
  end
227
182
 
228
183
  shared_examples_for "model collections" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 0
10
- version: 1.3.0
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - EY Cloud Team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-13 00:00:00 -07:00
18
+ date: 2010-09-20 00:00:00 -07:00
19
19
  default_executable: ey
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -109,6 +109,22 @@ dependencies:
109
109
  type: :runtime
110
110
  name: escape
111
111
  prerelease: false
112
+ - !ruby/object:Gem::Dependency
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - "="
117
+ - !ruby/object:Gem::Version
118
+ hash: 29
119
+ segments:
120
+ - 1
121
+ - 3
122
+ - 3
123
+ version: 1.3.3
124
+ requirement: *id007
125
+ type: :runtime
126
+ name: engineyard-serverside-adapter
127
+ prerelease: false
112
128
  description: This gem allows you to deploy your rails application to the Engine Yard cloud directly from the command line.
113
129
  email: cloud@engineyard.com
114
130
  executables:
@@ -139,7 +155,6 @@ files:
139
155
  - lib/engineyard/model.rb
140
156
  - lib/engineyard/repo.rb
141
157
  - lib/engineyard/ruby_ext.rb
142
- - lib/engineyard/serverside_version.rb
143
158
  - lib/engineyard/thor.rb
144
159
  - lib/engineyard/version.rb
145
160
  - lib/engineyard.rb
@@ -1,3 +0,0 @@
1
- module EY
2
- ENGINEYARD_SERVERSIDE_VERSION = ENV['ENGINEYARD_SERVERSIDE_VERSION'] || '1.3.1'
3
- end