ey-deploy 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ey-deploy/cli.rb CHANGED
@@ -30,6 +30,9 @@ module EY
30
30
  method_option :config, :type => :string,
31
31
  :desc => "Additional configuration"
32
32
 
33
+ method_option :stack, :type => :string,
34
+ :desc => "Web stack (so we can restart it correctly)"
35
+
33
36
  method_option :instances, :type => :array,
34
37
  :desc => "Instances in cluster"
35
38
 
@@ -60,6 +63,21 @@ module EY
60
63
  EY::DeployHook.new(options).run(hook_name)
61
64
  end
62
65
 
66
+ desc "install_bundler [VERSION]", "Make sure VERSION of bundler is installed (in system ruby)"
67
+ def install_bundler(version)
68
+ egrep_escaped_version = version.gsub(/\./, '\.')
69
+ # the grep "bundler " is so that gems like bundler08 don't get
70
+ # their versions considered too
71
+ #
72
+ # the [,$] is to stop us from looking for e.g. 0.9.2, seeing
73
+ # 0.9.22, and mistakenly thinking 0.9.2 is there
74
+ has_bundler_cmd = "gem list bundler | grep \"bundler \" | egrep -q '#{egrep_escaped_version}[,)]'"
75
+
76
+ unless system(has_bundler_cmd)
77
+ system("gem install bundler -q --no-rdoc --no-ri -v '#{version}'")
78
+ end
79
+ end
80
+
63
81
  desc "propagate", "Propagate the ey-deploy gem to the other instances in the cluster. This will install exactly version #{VERSION} and remove other versions if found."
64
82
  def propagate
65
83
  config = EY::Deploy::Configuration.new
@@ -73,8 +91,11 @@ module EY
73
91
  EY::Server.all.find_all do |server|
74
92
  !server.local? # of course this machine has it
75
93
  end.find_all do |server|
76
- has_gem_cmd = "/usr/local/ey_resin/ruby/bin/gem list ey-deploy | grep -q '(#{VERSION})'"
77
- !server.run(has_gem_cmd) # doesn't have only this exact version
94
+ egrep_escaped_version = VERSION.gsub(/\./, '\.')
95
+ # the [,)] is to stop us from looking for e.g. 0.5.1, seeing
96
+ # 0.5.11, and mistakenly thinking 0.5.1 is there
97
+ has_gem_cmd = "#{gem_binary} list ey-deploy | grep \"ey-deploy \" | egrep -q '#{egrep_escaped_version}[,)]'"
98
+ !server.run(has_gem_cmd) # doesn't have this exact version
78
99
  end.each do |server|
79
100
  puts "~> Installing ey-deploy on #{server.hostname}"
80
101
 
@@ -84,7 +105,6 @@ module EY
84
105
  local_gem_file,
85
106
  "#{config.user}@#{server.hostname}:#{remote_gem_file}",
86
107
  ]))
87
- server.run("sudo #{gem_binary} uninstall -a -x ey-deploy 2>/dev/null")
88
108
  server.run("sudo #{gem_binary} install --no-rdoc --no-ri '#{remote_gem_file}'")
89
109
  end
90
110
  end
@@ -57,10 +57,6 @@ module EY
57
57
  configuration['repository_cache'] || File.join(deploy_to, "/shared/cached-copy")
58
58
  end
59
59
 
60
- def repo
61
- configuration['repo']
62
- end
63
-
64
60
  def deploy_to
65
61
  configuration['deploy_to'] || "/data/#{app}"
66
62
  end
@@ -86,10 +82,6 @@ module EY
86
82
  @copy_exclude ||= Array(configuration.fetch("copy_exclude", []))
87
83
  end
88
84
 
89
- def stack
90
- node['environment']['stack']
91
- end
92
-
93
85
  def environment
94
86
  node['environment']['framework_env']
95
87
  end
@@ -1,6 +1,8 @@
1
1
  # stolen wholesale from capistrano, thanks Jamis!
2
+ require 'base64'
2
3
  require 'fileutils'
3
4
  require 'json'
5
+ require 'yaml'
4
6
 
5
7
  module EY
6
8
  class DeployBase < Task
@@ -113,11 +115,20 @@ module EY
113
115
 
114
116
  # task
115
117
  def bundle
116
- roles :app_master, :app, :solo do
117
- if File.exist?("#{c.latest_release}/Gemfile")
118
- puts "~> Gemfile detected, bundling gems"
119
- run "cd #{c.latest_release} && bundle install"
120
- end
118
+ if File.exist?("#{c.latest_release}/Gemfile")
119
+ puts "~> Gemfile detected, bundling gems"
120
+ lockfile = File.join(c.latest_release, "Gemfile.lock")
121
+
122
+ bundler_version = if File.exist?(lockfile)
123
+ get_bundler_version(lockfile)
124
+ else
125
+ warn_about_missing_lockfile
126
+ DEFAULT_09_BUNDLER
127
+ end
128
+
129
+ sudo "#{$0} _#{VERSION}_ install_bundler #{bundler_version}"
130
+
131
+ run "cd #{c.latest_release} && bundle _#{bundler_version}_ install --without=development --without=test"
121
132
  end
122
133
  end
123
134
 
@@ -201,7 +212,7 @@ module EY
201
212
  @callbacks_reached ||= true
202
213
  if File.exist?("#{c.latest_release}/deploy/#{what}.rb")
203
214
  eysd_path = $0 # invoke others just like we were invoked
204
- run "#{eysd_path} hook '#{what}' --app '#{config.app}' --release-path #{config.release_path}" do |server, cmd|
215
+ run "#{eysd_path} _#{VERSION}_ hook '#{what}' --app '#{config.app}' --release-path #{config.release_path}" do |server, cmd|
205
216
  cmd << " --current-role '#{server.role}'"
206
217
  cmd << " --current-name '#{server.name}'" if server.name
207
218
  cmd
@@ -245,7 +256,55 @@ module EY
245
256
  def cleanup_latest_release
246
257
  sudo "rm -rf #{c.latest_release}"
247
258
  end
248
- end
259
+
260
+ def safe_yaml_load(loadable)
261
+ YAML.load(loadable)
262
+ rescue ArgumentError # not yaml
263
+ nil
264
+ end
265
+
266
+ DEFAULT_09_BUNDLER = '0.9.26'
267
+ DEFAULT_10_BUNDLER = '1.0.0.beta.1'
268
+
269
+ def warn_about_missing_lockfile
270
+ puts "!>"
271
+ puts "!> WARNING: Gemfile.lock is missing!"
272
+ puts "!> You can get different gems in production than what you tested with."
273
+ puts "!> You can get different gems on every deployment even if your Gemfile hasn't changed."
274
+ puts "!> Deploying may take a long time."
275
+ puts "!>"
276
+ puts "!> Fix this by running \"git add Gemfile.lock; git commit\" and deploying again."
277
+ puts "!> If you don't have a Gemfile.lock, run \"bundle lock\" to create one."
278
+ puts "!>"
279
+ puts "!> This deployment will use bundler #{DEFAULT_09_BUNDLER} to run 'bundle install'."
280
+ puts "!>"
281
+ end
282
+
283
+ def get_bundler_version(lockfile)
284
+ contents = File.open(lockfile, 'r') { |f| f.read }
285
+ from_yaml = safe_yaml_load(contents)
286
+
287
+ if from_yaml # 0.9
288
+ from_yaml['specs'].map do |spec|
289
+ # spec is a one-element hash: the key is the gem name, and
290
+ # the value is {"version" => the-version}.
291
+ if spec.keys.first == "bundler"
292
+ spec.values.first["version"]
293
+ end
294
+ end.compact.first || DEFAULT_09_BUNDLER
295
+ else # 1.0 or bust
296
+ gem_section = contents.scan(/GEM\s*\n(.*?)\n\S/m).first
297
+ unless gem_section
298
+ raise "Couldn't parse #{lockfile}; exiting"
299
+ exit(1)
300
+ end
301
+ result = gem_section.first.scan(/^\s*bundler\s*\((\S+)\)/).first
302
+ result ? result.first : DEFAULT_10_BUNDLER
303
+ end
304
+ end
305
+ public :get_bundler_version
306
+
307
+ end # DeployBase
249
308
 
250
309
  class Deploy < DeployBase
251
310
  def self.new(opts={})
@@ -1,3 +1,3 @@
1
1
  module EY
2
- VERSION = '0.6.1'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "the bundler version retrieved from the lockfile" do
4
+ def get_version(file)
5
+ full_path = File.expand_path("../support/lockfiles/#{file}", __FILE__)
6
+ EY::DeployBase.new({}).get_bundler_version(full_path)
7
+ end
8
+
9
+ it "returns the default version for an 0.9 lockfile without a bundler dependency" do
10
+ get_version('0.9-no-bundler').should == EY::DeployBase::DEFAULT_09_BUNDLER
11
+ end
12
+
13
+ it "gets the version from an 0.9 lockfile with a bundler dependency" do
14
+ get_version('0.9-with-bundler').should == '0.9.24'
15
+ end
16
+
17
+ it "returns the default version for a 1.0 lockfile without a bundler dependency" do
18
+ get_version('1.0-no-bundler').should == EY::DeployBase::DEFAULT_10_BUNDLER
19
+ end
20
+
21
+ it "gets the version from a 1.0 lockfile with a bundler dependency" do
22
+ get_version('1.0-with-bundler').should == '1.0.0.beta.1'
23
+ end
24
+
25
+ it "raises an error if it can't parse the file" do
26
+ lambda { get_version('not-a-lockfile') }.should raise_error
27
+ end
28
+ end
@@ -0,0 +1,111 @@
1
+ ---
2
+ dependencies:
3
+ ruby-debug:
4
+ group:
5
+ - :test
6
+ version: ">= 0"
7
+ fakeweb:
8
+ group:
9
+ - :test
10
+ version: ">= 0"
11
+ termios:
12
+ group:
13
+ - :default
14
+ version: ">= 0"
15
+ fakefs:
16
+ group:
17
+ - :test
18
+ version: ">= 0"
19
+ highline:
20
+ group:
21
+ - :default
22
+ version: ~> 1.5.2
23
+ rake:
24
+ group:
25
+ - :test
26
+ version: ">= 0"
27
+ realweb:
28
+ group:
29
+ - :test
30
+ version: ~> 0.1.6
31
+ escape:
32
+ group:
33
+ - :default
34
+ version: ~> 0.0.4
35
+ thor:
36
+ group:
37
+ - :default
38
+ version: ~> 0.13.6
39
+ rspec:
40
+ group:
41
+ - :test
42
+ version: ">= 0"
43
+ require:
44
+ - spec
45
+ sinatra:
46
+ group:
47
+ - :test
48
+ version: ">= 0"
49
+ json:
50
+ group:
51
+ - :default
52
+ version: ~> 1.4.0
53
+ rest-client:
54
+ group:
55
+ - :default
56
+ version: ~> 1.4
57
+ require:
58
+ - rest_client
59
+ fakeweb-matcher:
60
+ group:
61
+ - :test
62
+ version: ">= 0"
63
+ open4:
64
+ group:
65
+ - :test
66
+ version: ">= 0"
67
+ specs:
68
+ - rake:
69
+ version: 0.8.7
70
+ - columnize:
71
+ version: 0.3.1
72
+ - escape:
73
+ version: 0.0.4
74
+ - fakefs:
75
+ version: 0.2.1
76
+ - fakeweb:
77
+ version: 1.2.8
78
+ - rspec:
79
+ version: 1.3.0
80
+ - fakeweb-matcher:
81
+ version: 1.1.0
82
+ - highline:
83
+ version: 1.5.2
84
+ - json:
85
+ version: 1.4.3
86
+ - linecache:
87
+ version: "0.43"
88
+ - mime-types:
89
+ version: "1.16"
90
+ - open4:
91
+ version: 1.0.1
92
+ - rack:
93
+ version: 1.2.1
94
+ - realweb:
95
+ version: 0.1.6
96
+ - rest-client:
97
+ version: 1.5.1
98
+ - ruby-debug-base:
99
+ version: 0.10.3
100
+ - ruby-debug:
101
+ version: 0.10.3
102
+ - sinatra:
103
+ version: "1.0"
104
+ - termios:
105
+ version: 0.9.4
106
+ - thor:
107
+ version: 0.13.6
108
+ hash: fbfa26af5a1ec9a59367fdd0ea866373166d06f0
109
+ sources:
110
+ - Rubygems:
111
+ uri: http://gemcutter.org
@@ -0,0 +1,117 @@
1
+ ---
2
+ dependencies:
3
+ ruby-debug:
4
+ group:
5
+ - :test
6
+ version: ">= 0"
7
+ fakeweb:
8
+ group:
9
+ - :test
10
+ version: ">= 0"
11
+ termios:
12
+ group:
13
+ - :default
14
+ version: ">= 0"
15
+ fakefs:
16
+ group:
17
+ - :test
18
+ version: ">= 0"
19
+ highline:
20
+ group:
21
+ - :default
22
+ version: ~> 1.5.2
23
+ rake:
24
+ group:
25
+ - :test
26
+ version: ">= 0"
27
+ realweb:
28
+ group:
29
+ - :test
30
+ version: ~> 0.1.6
31
+ escape:
32
+ group:
33
+ - :default
34
+ version: ~> 0.0.4
35
+ thor:
36
+ group:
37
+ - :default
38
+ version: ~> 0.13.6
39
+ rspec:
40
+ group:
41
+ - :test
42
+ version: ">= 0"
43
+ require:
44
+ - spec
45
+ sinatra:
46
+ group:
47
+ - :test
48
+ version: ">= 0"
49
+ json:
50
+ group:
51
+ - :default
52
+ version: ~> 1.4.0
53
+ rest-client:
54
+ group:
55
+ - :default
56
+ version: ~> 1.4
57
+ require:
58
+ - rest_client
59
+ bundler:
60
+ group:
61
+ - :test
62
+ version: ">= 0"
63
+ fakeweb-matcher:
64
+ group:
65
+ - :test
66
+ version: ">= 0"
67
+ open4:
68
+ group:
69
+ - :test
70
+ version: ">= 0"
71
+ specs:
72
+ - rake:
73
+ version: 0.8.7
74
+ - bundler:
75
+ version: 0.9.24
76
+ - columnize:
77
+ version: 0.3.1
78
+ - escape:
79
+ version: 0.0.4
80
+ - fakefs:
81
+ version: 0.2.1
82
+ - fakeweb:
83
+ version: 1.2.8
84
+ - rspec:
85
+ version: 1.3.0
86
+ - fakeweb-matcher:
87
+ version: 1.1.0
88
+ - highline:
89
+ version: 1.5.2
90
+ - json:
91
+ version: 1.4.3
92
+ - linecache:
93
+ version: "0.43"
94
+ - mime-types:
95
+ version: "1.16"
96
+ - open4:
97
+ version: 1.0.1
98
+ - rack:
99
+ version: 1.2.1
100
+ - realweb:
101
+ version: 0.1.6
102
+ - rest-client:
103
+ version: 1.5.1
104
+ - ruby-debug-base:
105
+ version: 0.10.3
106
+ - ruby-debug:
107
+ version: 0.10.3
108
+ - sinatra:
109
+ version: "1.0"
110
+ - termios:
111
+ version: 0.9.4
112
+ - thor:
113
+ version: 0.13.6
114
+ hash: fbfa26af5a1ec9a59367fdd0ea866373166d06f0
115
+ sources:
116
+ - Rubygems:
117
+ uri: http://gemcutter.org
@@ -0,0 +1,54 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ columnize (0.3.1)
5
+ escape (0.0.4)
6
+ fakefs (0.2.1)
7
+ fakeweb (1.2.8)
8
+ fakeweb-matcher (1.1.0)
9
+ fakeweb (>= 1.2.5)
10
+ rspec (>= 1.2.0)
11
+ highline (1.5.2)
12
+ json (1.4.3)
13
+ json (1.4.3-x86-mingw32)
14
+ json (1.4.3-x86-mswin32)
15
+ linecache (0.43)
16
+ linecache (0.43-mswin32)
17
+ mime-types (1.16)
18
+ open4 (1.0.1)
19
+ rack (1.2.1)
20
+ rake (0.8.7)
21
+ realweb (0.1.6)
22
+ rack (>= 1.1.0)
23
+ rest-client (1.5.1)
24
+ mime-types (>= 1.16)
25
+ rspec (1.3.0)
26
+ ruby-debug (0.10.3)
27
+ columnize (>= 0.1)
28
+ ruby-debug-base (~> 0.10.3.0)
29
+ ruby-debug-base (0.10.3)
30
+ linecache (>= 0.3)
31
+ sinatra (1.0)
32
+ rack (>= 1.0)
33
+ termios (0.9.4)
34
+ thor (0.13.6)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ escape (~> 0.0.4)
41
+ fakefs
42
+ fakeweb
43
+ fakeweb-matcher
44
+ highline (~> 1.5.2)
45
+ json (~> 1.4.0)
46
+ open4
47
+ rake
48
+ realweb (~> 0.1.6)
49
+ rest-client (~> 1.4)
50
+ rspec
51
+ ruby-debug
52
+ sinatra
53
+ termios
54
+ thor (~> 0.13.6)
@@ -0,0 +1,56 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ bundler (1.0.0.beta.1)
5
+ columnize (0.3.1)
6
+ escape (0.0.4)
7
+ fakefs (0.2.1)
8
+ fakeweb (1.2.8)
9
+ fakeweb-matcher (1.1.0)
10
+ fakeweb (>= 1.2.5)
11
+ rspec (>= 1.2.0)
12
+ highline (1.5.2)
13
+ json (1.4.3)
14
+ json (1.4.3-x86-mingw32)
15
+ json (1.4.3-x86-mswin32)
16
+ linecache (0.43)
17
+ linecache (0.43-mswin32)
18
+ mime-types (1.16)
19
+ open4 (1.0.1)
20
+ rack (1.2.1)
21
+ rake (0.8.7)
22
+ realweb (0.1.6)
23
+ rack (>= 1.1.0)
24
+ rest-client (1.5.1)
25
+ mime-types (>= 1.16)
26
+ rspec (1.3.0)
27
+ ruby-debug (0.10.3)
28
+ columnize (>= 0.1)
29
+ ruby-debug-base (~> 0.10.3.0)
30
+ ruby-debug-base (0.10.3)
31
+ linecache (>= 0.3)
32
+ sinatra (1.0)
33
+ rack (>= 1.0)
34
+ termios (0.9.4)
35
+ thor (0.13.6)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler
42
+ escape (~> 0.0.4)
43
+ fakefs
44
+ fakeweb
45
+ fakeweb-matcher
46
+ highline (~> 1.5.2)
47
+ json (~> 1.4.0)
48
+ open4
49
+ rake
50
+ realweb (~> 0.1.6)
51
+ rest-client (~> 1.4)
52
+ rspec
53
+ ruby-debug
54
+ sinatra
55
+ termios
56
+ thor (~> 0.13.6)
@@ -0,0 +1,10 @@
1
+ require 'spec/rake/spectask'
2
+ Spec::Rake::SpecTask.new(:spec) do |spec|
3
+ spec.libs << 'lib' << 'spec'
4
+ spec.spec_files = FileList['spec/**/*_spec.rb']
5
+ end
6
+ task :default => :spec
7
+
8
+ require 'rake/rdoctask'
9
+
10
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - EY Cloud Team
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-23 00:00:00 -07:00
17
+ date: 2010-06-25 00:00:00 -07:00
18
18
  default_executable: eysd
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -144,4 +144,10 @@ summary: A gem that deploys ruby applications on EY Cloud instances
144
144
  test_files:
145
145
  - spec/custom_deploy_spec.rb
146
146
  - spec/deploy_hook_spec.rb
147
+ - spec/lockfile_parser_spec.rb
147
148
  - spec/spec_helper.rb
149
+ - spec/support/lockfiles/0.9-no-bundler
150
+ - spec/support/lockfiles/0.9-with-bundler
151
+ - spec/support/lockfiles/1.0-no-bundler
152
+ - spec/support/lockfiles/1.0-with-bundler
153
+ - spec/support/lockfiles/not-a-lockfile