engineyard-serverside 1.4.1 → 1.4.3.nodestack

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.
@@ -119,7 +119,7 @@ module EY
119
119
  end
120
120
 
121
121
  def framework_envs
122
- "RAILS_ENV=#{environment} RACK_ENV=#{environment} MERB_ENV=#{environment}"
122
+ "RAILS_ENV=#{environment} RACK_ENV=#{environment} APP_ENV=#{environment} MERB_ENV=#{environment}"
123
123
  end
124
124
 
125
125
  def current_path
@@ -142,7 +142,36 @@ module EY
142
142
 
143
143
  sudo "#{$0} _#{EY::Serverside::VERSION}_ install_bundler #{bundler_installer.version}"
144
144
 
145
+ bundled_gems_path = File.join(c.shared_path, "bundled_gems")
146
+ ruby_version_file = File.join(bundled_gems_path, "RUBY_VERSION")
147
+ system_version_file = File.join(bundled_gems_path, "SYSTEM_VERSION")
148
+ ruby_version = `ruby -v`
149
+ system_version = `uname -m`
150
+
151
+ if File.directory?(bundled_gems_path)
152
+ rebundle = false
153
+
154
+ rebundle = true if File.exist?(ruby_version_file) && File.read(ruby_version_file) != ruby_version
155
+ rebundle = true if File.exist?(system_version_file) && File.read(system_version_file) != system_version
156
+
157
+ if rebundle
158
+ info "~> Ruby version change detected, cleaning bundled gems"
159
+ run "rm -Rf #{bundled_gems_path}"
160
+ end
161
+ end
162
+
145
163
  run "cd #{c.release_path} && bundle _#{bundler_installer.version}_ install #{bundler_installer.options}"
164
+
165
+ run "mkdir -p #{bundled_gems_path} && ruby -v > #{ruby_version_file} && uname -m > #{system_version_file}"
166
+ end
167
+ if File.exist?("#{c.release_path}/package.json")
168
+ unless `which npm` =~ /npm/
169
+ error "~> package.json detected, BUT npm not installed"
170
+ else
171
+ info "~> package.json detected, installing npm packages"
172
+
173
+ run "cd #{c.release_path} && npm install"
174
+ end
146
175
  end
147
176
  end
148
177
 
@@ -308,9 +337,9 @@ module EY
308
337
  parser = LockfileParser.new(File.read(lockfile))
309
338
  case parser.lockfile_version
310
339
  when :bundler09
311
- bundler_09_installer(parser.bundler_version || default_09_bundler)
340
+ bundler_09_installer(parser.bundler_version)
312
341
  when :bundler10
313
- bundler_10_installer(parser.bundler_version || default_10_bundler)
342
+ bundler_10_installer(parser.bundler_version)
314
343
  else
315
344
  raise "Unknown lockfile version #{parser.lockfile_version}"
316
345
  end
@@ -325,10 +354,6 @@ module EY
325
354
  BundleInstaller.new(version,
326
355
  "--deployment --path #{c.shared_path}/bundled_gems --binstubs #{c.binstubs_path} --without development test")
327
356
  end
328
-
329
- def default_09_bundler() "0.9.26" end
330
- def default_10_bundler() "1.0.10" end
331
-
332
357
  end # DeployBase
333
358
 
334
359
  class Deploy < DeployBase
@@ -9,8 +9,6 @@ module EY
9
9
  @lockfile_version, @bundler_version = Parse106.new(lockfile_contents).parse
10
10
  end
11
11
 
12
- private
13
-
14
12
  class BaseParser
15
13
  def initialize(contents)
16
14
  @contents = contents
@@ -21,6 +19,8 @@ module EY
21
19
  end
22
20
 
23
21
  class Parse09 < BaseParser
22
+ DEFAULT = "0.9.26"
23
+
24
24
  def parse
25
25
  from_yaml = safe_yaml_load(@contents)
26
26
  unless from_yaml.is_a?(Hash)
@@ -33,7 +33,7 @@ module EY
33
33
  spec.values.first["version"]
34
34
  end
35
35
  end.compact.first
36
- [:bundler09, bundler_version]
36
+ [:bundler09, bundler_version || DEFAULT]
37
37
  end
38
38
  def safe_yaml_load(loadable)
39
39
  YAML.load(loadable) #won't always raise... soemtimes parses the contents as 1 big string
@@ -43,6 +43,8 @@ module EY
43
43
  end
44
44
 
45
45
  class Parse10 < Parse09
46
+ DEFAULT = "1.0.10"
47
+
46
48
  def parse
47
49
  unless @contents.index(/^DEPENDENCIES/)
48
50
  return super
@@ -64,9 +66,29 @@ module EY
64
66
  exit(1)
65
67
  end
66
68
 
67
- result = dep_section.scan(/^\s*bundler\s*\(=\s*([^\)]+)\)/).first
68
- bundler_version = result ? result.first : nil
69
- [:bundler10, bundler_version]
69
+ result = scan_bundler(dep_section)
70
+ bundler_version = result ? result.last : nil
71
+ version_qualifier = result ? result.first : nil
72
+ [:bundler10, fetch_version(bundler_version, version_qualifier)]
73
+ end
74
+
75
+ def fetch_version(bundler_version, version_qualifier)
76
+ return bundler_version || DEFAULT unless version_qualifier
77
+
78
+ case version_qualifier
79
+ when '='
80
+ bundler_version
81
+ when '>='
82
+ Gem::Version.new(bundler_version) > Gem::Version.new(DEFAULT) ? bundler_version : DEFAULT
83
+ when '~>'
84
+ bundler_gem_version = Gem::Version.new(bundler_version)
85
+ recommendation = bundler_gem_version.spermy_recommendation.gsub(/~>\s*(.+)$/, '\1.')
86
+ DEFAULT.start_with?(recommendation) && Gem::Version.new(DEFAULT) > bundler_gem_version ? DEFAULT : bundler_version
87
+ end
88
+ end
89
+
90
+ def scan_bundler(dep_section)
91
+ dep_section.scan(/^\s*bundler\s*\((>?=|~>)\s*([^,\)]+)/).first
70
92
  end
71
93
  end
72
94
 
@@ -93,7 +115,7 @@ module EY
93
115
  end
94
116
 
95
117
  result = meta_section.scan(/^\s*version:\s*(.*)$/).first
96
- bundler_version = result ? result.first : nil
118
+ bundler_version = result ? result.first : DEFAULT
97
119
  [:bundler10, bundler_version]
98
120
  end
99
121
  end
@@ -41,6 +41,11 @@ module EY
41
41
  EY::Serverside::LoggedOutput.verbose?
42
42
  end
43
43
 
44
+ # TODO color output
45
+ def error(msg)
46
+ info(msg)
47
+ end
48
+
44
49
  def info(msg)
45
50
  with_logfile do |log|
46
51
  Tee.new($stdout, log) << (msg + "\n")
@@ -1,5 +1,5 @@
1
1
  module EY
2
2
  module Serverside
3
- VERSION = '1.4.1'
3
+ VERSION = '1.4.3.nodestack'
4
4
  end
5
5
  end
File without changes
@@ -1,14 +1,16 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "the bundler version retrieved from the lockfile" do
4
+ def get_full_path(file)
5
+ File.expand_path("../support/lockfiles/#{file}", __FILE__)
6
+ end
4
7
  def get_version(file)
5
- full_path = File.expand_path("../support/lockfiles/#{file}", __FILE__)
6
8
  @config = EY::Serverside::Deploy::Configuration.new('deploy_to' => 'dontcare')
7
- EY::Serverside::DeployBase.new(@config).get_bundler_installer(full_path).version
9
+ EY::Serverside::DeployBase.new(@config).get_bundler_installer(get_full_path(file)).version
8
10
  end
9
11
 
10
12
  it "returns the default version for an 0.9 lockfile without a bundler dependency" do
11
- get_version('0.9-no-bundler').should == EY::Serverside::DeployBase.new(@config).send(:default_09_bundler)
13
+ get_version('0.9-no-bundler').should == EY::Serverside::LockfileParser::Parse09::DEFAULT
12
14
  end
13
15
 
14
16
  it "gets the version from an 0.9 lockfile with a bundler dependency" do
@@ -16,7 +18,7 @@ describe "the bundler version retrieved from the lockfile" do
16
18
  end
17
19
 
18
20
  it "returns the default version for a 1.0 lockfile without a bundler dependency" do
19
- get_version('1.0-no-bundler').should == EY::Serverside::DeployBase.new(@config).send(:default_10_bundler)
21
+ get_version('1.0-no-bundler').should == EY::Serverside::LockfileParser::Parse10::DEFAULT
20
22
  end
21
23
 
22
24
  it "gets the version from a 1.0.0.rc.1 lockfile w/dependency on 1.0.0.rc.1" do
@@ -47,4 +49,36 @@ describe "the bundler version retrieved from the lockfile" do
47
49
  lambda { get_version('evil-yaml') }.should raise_error(RuntimeError, /Unknown lockfile format/)
48
50
  end
49
51
 
52
+ context "fetching the right version number" do
53
+ subject { EY::Serverside::LockfileParser::Parse10.new(get_full_path('1.0.6-no-bundler')) }
54
+
55
+ it "uses the default version when there is no bundler version" do
56
+ subject.fetch_version(nil, nil).should == EY::Serverside::LockfileParser::Parse10::DEFAULT
57
+ end
58
+
59
+ it "uses the given version when the qualifier is `='" do
60
+ subject.fetch_version('1.0.1', '=').should == '1.0.1'
61
+ end
62
+
63
+ it "uses the default version when we get a pessimistic qualifier and is lower than the default version" do
64
+ subject.fetch_version('1.0.1', '~>').should == '1.0.10'
65
+ end
66
+
67
+ it "uses the given version when we get a pessimistic qualifier that doesn't match the default version" do
68
+ subject.fetch_version('1.1.0', '~>').should == '1.1.0'
69
+ end
70
+
71
+ it "uses the given version when it's geater of equal than the default version" do
72
+ subject.fetch_version('1.1.0', '>=').should == '1.1.0'
73
+ end
74
+
75
+ it "uses the default version when the given version is lower" do
76
+ subject.fetch_version('1.0.1', '>=').should == EY::Serverside::LockfileParser::Parse10::DEFAULT
77
+ end
78
+
79
+ it "selects only the first version expression" do
80
+ scan = subject.scan_bundler 'bundler (>=1.0.1, <2.0.0)'
81
+ scan.last.should == '1.0.1'
82
+ end
83
+ end
50
84
  end
@@ -46,6 +46,21 @@ DEPENDENCIES
46
46
  rake
47
47
  EOF
48
48
  end
49
+
50
+ File.open('package.json', 'w') do |f|
51
+ f.write <<-EOF
52
+ {
53
+ "name": "application-name"
54
+ , "version": "0.0.1"
55
+ , "private": true
56
+ , "dependencies": {
57
+ "express": "2.3.12"
58
+ , "jade": ">= 0.0.1"
59
+ }
60
+ }
61
+ EOF
62
+ end
63
+
49
64
  end
50
65
  end
51
66
 
@@ -149,6 +164,12 @@ describe "deploying an application" do
149
164
  'framework_env' => 'staging'
150
165
  })
151
166
 
167
+ # pretend there is a shared bundled_gems directory
168
+ FileUtils.mkdir_p(File.join(@deploy_dir, 'shared', 'bundled_gems'))
169
+ %w(RUBY_VERSION SYSTEM_VERSION).each do |name|
170
+ File.open(File.join(@deploy_dir, 'shared', 'bundled_gems', name), "w") { |f| f.write("old\n") }
171
+ end
172
+
152
173
  @binpath = $0 = File.expand_path(File.join(File.dirname(__FILE__), '..', 'bin', 'engineyard-serverside'))
153
174
  @deployer = FullTestDeploy.new(config)
154
175
  @deployer.deploy
@@ -174,6 +195,29 @@ describe "deploying an application" do
174
195
  bundle_install_cmd.should include('--deployment')
175
196
  end
176
197
 
198
+ it "creates a ruby version file" do
199
+ File.exist?(File.join(@deploy_dir, 'shared', 'bundled_gems', 'RUBY_VERSION')).should be_true
200
+ end
201
+
202
+ it "creates a system version file" do
203
+ File.exist?(File.join(@deploy_dir, 'shared', 'bundled_gems', 'SYSTEM_VERSION')).should be_true
204
+ end
205
+
206
+ it "removes bundled_gems directory if the ruby version changed" do
207
+ clear_bundle_cmd = @deployer.commands.grep(/rm -Rf \S+\/bundled_gems/).first
208
+ clear_bundle_cmd.should_not be_nil
209
+ end
210
+
211
+ it "removes bundled_gems directory if the system version changed" do
212
+ clear_bundle_cmd = @deployer.commands.grep(/rm -Rf \S+\/bundled_gems/).first
213
+ clear_bundle_cmd.should_not be_nil
214
+ end
215
+
216
+ it "runs 'npm install'" do
217
+ bundle_install_cmd = @deployer.commands.grep(/npm install/).first
218
+ bundle_install_cmd.should_not be_nil
219
+ end
220
+
177
221
  it "creates binstubs somewhere out of the way" do
178
222
  File.exist?(File.join(@deploy_dir, 'current', 'ey_bundler_binstubs', 'rake')).should be_true
179
223
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard-serverside
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease:
4
+ hash: -1757219187
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 1
10
- version: 1.4.1
9
+ - 3
10
+ - nodestack
11
+ version: 1.4.3.nodestack
11
12
  platform: ruby
12
13
  authors:
13
14
  - EY Cloud Team
@@ -15,8 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-02-17 00:00:00 -08:00
19
- default_executable: engineyard-serverside
19
+ date: 2011-08-31 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description:
@@ -237,6 +237,7 @@ files:
237
237
  - spec/custom_deploy_spec.rb
238
238
  - spec/deploy_hook_spec.rb
239
239
  - spec/deprecation_spec.rb
240
+ - spec/fixtures/gitrepo/bar
240
241
  - spec/fixtures/gitrepo/foo
241
242
  - spec/fixtures/gitrepo.tar.gz
242
243
  - spec/fixtures/invalid_hook.rb
@@ -256,7 +257,6 @@ files:
256
257
  - spec/support/lockfiles/1.0.6-with-bundler
257
258
  - spec/support/lockfiles/evil-yaml
258
259
  - spec/support/lockfiles/not-a-lockfile
259
- has_rdoc: true
260
260
  homepage: http://github.com/engineyard/engineyard-serverside
261
261
  licenses: []
262
262
 
@@ -277,16 +277,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
277
  required_rubygems_version: !ruby/object:Gem::Requirement
278
278
  none: false
279
279
  requirements:
280
- - - ">="
280
+ - - ">"
281
281
  - !ruby/object:Gem::Version
282
- hash: 3
282
+ hash: 25
283
283
  segments:
284
- - 0
285
- version: "0"
284
+ - 1
285
+ - 3
286
+ - 1
287
+ version: 1.3.1
286
288
  requirements: []
287
289
 
288
290
  rubyforge_project:
289
- rubygems_version: 1.4.2
291
+ rubygems_version: 1.8.6
290
292
  signing_key:
291
293
  specification_version: 3
292
294
  summary: A gem that deploys ruby applications on EY Cloud instances
@@ -294,6 +296,7 @@ test_files:
294
296
  - spec/custom_deploy_spec.rb
295
297
  - spec/deploy_hook_spec.rb
296
298
  - spec/deprecation_spec.rb
299
+ - spec/fixtures/gitrepo/bar
297
300
  - spec/fixtures/gitrepo/foo
298
301
  - spec/fixtures/gitrepo.tar.gz
299
302
  - spec/fixtures/invalid_hook.rb