torquebox-rake-support 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -159,42 +159,115 @@ module TorqueBox
159
159
  ENV.delete('BUNDLE_GEMFILE')
160
160
  # If called from rake within a rails app, bundler will try
161
161
  # to init itself via RUBYOPT, which we don't want
162
- ENV.delete('RUBYOPT')
163
- # Match load-path of booted TorqueBox to the load-path of
164
- # this process so that we know we can find bundler and our
165
- # own gems if used with bundle install --deployment
166
- ENV['RUBYLIB'] = "#{ENV['RUBYLIB']}:#{$:.join(':')}"
167
-
168
- set_java_opts("#{options[:jvm_options]} #{jruby_opts_properties}")
162
+ ENV.delete('RUBYOPT')
163
+ # Ensure bundler gets on the Ruby load path of the booted
164
+ # TorqueBox instance if it's on the load path of this Ruby
165
+ # runtime so we can find bundler and our own gems if used
166
+ # with bundle install --deployment
167
+ ENV['RUBYLIB'] = rubylib_with_bundler($:)
168
+
169
+ options[:jvm_options] ||= ''
170
+ options[:jvm_options] << " #{jruby_opts_properties}"
171
+ options[:jvm_options] << " #{strip_jvm_properties_from_jruby_opts}"
172
+
173
+ set_java_opts(options[:jvm_options].strip)
169
174
  print_server_config(options[:clustered])
170
175
  exec_command(run_command_line(options).join(' '))
171
176
  end
172
177
  end
173
178
 
179
+ # name: (string) what to call the resulting knob file
180
+ # app_dir: (string) where the application to be packaged is
181
+ # dest_dir: (string) where to put the resulting knob file
182
+ # excludes: (string) string or regex of files to exclude from the archive
183
+ # precompile_assets: (boolean) whether or not to precompile assets. this is rails-specific.
184
+ # package_gems: (boolean) whether or not to install all bundle gems to vendor/bundle (this
185
+ # is rather convenient as it means that you don't have to run bundle
186
+ # install on your production servers)
187
+ # package_without: (array) all the bundler groups to run bundle install without (cuts down
188
+ # on package size by snipping out potentially inappropriate
189
+ # dependencies for a production environment).
174
190
  def create_archive(opts = {})
175
-
176
191
  archive = normalize_archive_name( find_option( opts, 'name' ) || archive_name )
177
- app_dir = find_option( opts, 'app_dir') || Dir.pwd
178
- dest_dir = find_option( opts, 'dest_dir') || Dir.pwd
192
+ app_dir = find_option( opts, 'app_dir' ) || Dir.pwd
193
+ dest_dir = find_option( opts, 'dest_dir' ) || Dir.pwd
194
+ excludes = find_option( opts, 'exclude' ) || ""
195
+ should_precompile_assets = find_option( opts, 'precompile_assets' ) == true
196
+ should_package_gems = find_option( opts, 'package_gems' ) == true
197
+ package_without = find_option( opts, 'package_without' ) || Array.new
198
+
199
+ if should_precompile_assets
200
+ precompile_assets( app_dir )
201
+ raise 'Error precompiling assets' unless $? == 0
202
+ end
203
+
204
+ archive_path = File.join( dest_dir, archive )
205
+ archive_proc = lambda { create_knob_archive( app_dir, archive_path, excludes ) }
206
+
207
+ if should_package_gems
208
+ package_gems( app_dir, package_without ) {
209
+ raise 'Error packaging gems' unless $? == 0
210
+ archive_proc.call
211
+ }
212
+ else
213
+ archive_proc.call
214
+ end
215
+
216
+ archive_path
217
+ end
218
+
219
+ def precompile_assets(app_dir)
220
+ Dir.chdir( app_dir ) do
221
+ jruby_command( "-S rake assets:precompile" )
222
+ end
223
+ end
224
+
225
+ def package_gems(app_dir, package_without)
226
+ # note - this is used instead of freeze gems because it
227
+ # should cause the archive to capture .bundle/config,
228
+ # thereby forcing the app to use the bundled gems. we delete
229
+ # the deployment configuration for rubygems afterward
230
+ bundler_config = File.join( app_dir, '.bundle/config' )
231
+ if File.exists?( bundler_config )
232
+ old_config = File.read( bundler_config )
233
+ else
234
+ old_config = nil
235
+ end
236
+ cmd = %w{-S bundle install --local --deployment}
237
+ unless package_without.empty?
238
+ cmd << '--without'
239
+ cmd << package_without
240
+ end
241
+ Dir.chdir( app_dir ) do
242
+ jruby_command( '-S bundle package' )
243
+ jruby_command( cmd.flatten.join(' ') )
244
+ end
245
+ yield if block_given?
246
+ ensure
247
+ if File.exists?( bundler_config )
248
+ if old_config
249
+ File.open( bundler_config, 'w' ) { |io| io.write( old_config ) }
250
+ else
251
+ File.delete( bundler_config ) # there wasn't originally a config file there
252
+ end
253
+ end
254
+ end
179
255
 
256
+ def create_knob_archive(app_dir, archive_path, excludes)
180
257
  default_skip_files = %w{ ^log/ ^tmp/ ^test/ ^spec/ ^[^/]*\.knob$ vendor/.*cache/.*\.gem$ }
181
- opts_skip_files = (find_option(opts, 'exclude') || "").
182
- split(/,/).
183
- map { |r| "^[^/]*#{r}"}
258
+ opts_skip_files = excludes.split( /,/ ).map { |r| "^[^/]*#{r}" }
184
259
  skip_files = default_skip_files + opts_skip_files
185
260
 
186
- archive_path = File.join(dest_dir, archive)
187
-
188
261
  Dir.chdir( app_dir ) do
189
262
  include_files = []
190
263
  Dir[ "**/**", ".bundle/**/**" ].each do |entry|
191
- unless File.directory?(entry) || skip_files.any? {|regex| entry.match(regex)}
264
+ unless File.directory?( entry ) || skip_files.any? { |regex| entry.match( regex ) }
192
265
  include_files << '"' + entry.to_s + '"'
193
266
  end
194
267
  end
195
268
 
196
- includes = Tempfile.new("include-files")
197
- includes.write(include_files.join("\n"))
269
+ includes = Tempfile.new( "include-files" )
270
+ includes.write( include_files.join( "\n" ) )
198
271
  includes.flush
199
272
 
200
273
  cmd = "jar cvf '#{archive_path}' @#{includes.path}"
@@ -202,16 +275,12 @@ module TorqueBox
202
275
  run_command( cmd )
203
276
  includes.close( true )
204
277
  end
205
-
206
- archive_path
207
278
  end
208
279
 
209
280
  def freeze_gems(app_dir = Dir.pwd)
210
281
  Dir.chdir( app_dir ) do
211
- jruby = File.join( RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'] )
212
- jruby << " --1.9" if RUBY_VERSION =~ /^1\.9\./
213
- run_command( "#{jruby} -S bundle package" )
214
- run_command( "#{jruby} -S bundle install --local --path vendor/bundle" )
282
+ jruby_command( '-S bundle package' )
283
+ jruby_command( '-S bundle install --local --path vendor/bundle' )
215
284
  end
216
285
  end
217
286
 
@@ -299,6 +368,12 @@ module TorqueBox
299
368
  success
300
369
  end
301
370
 
371
+ def jruby_command(cmd)
372
+ jruby = File.join( RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'] )
373
+ RUBY_VERSION =~ /^1\.9\./ ? jruby << " --1.9" : jruby << " --1.8"
374
+ run_command( "#{jruby} #{cmd}" )
375
+ end
376
+
302
377
  def run_command(cmd)
303
378
  puts `#{cmd} 2>&1`
304
379
  end
@@ -410,10 +485,35 @@ module TorqueBox
410
485
  jruby_opts = ENV['JRUBY_OPTS']
411
486
  return "" if jruby_opts.nil?
412
487
  # Only convert -Xa.b, -Xa.b.c, -Xa.b.c.d style options to properties
413
- properties = jruby_opts.scan(/-X(\w+\..+?)\s/)
488
+ properties = jruby_opts.scan(/-X(\w+\..+?)(\s|$)/)
414
489
  properties.map { |matches| "-Djruby.#{matches.first}" }.join(' ')
415
490
  end
416
491
 
492
+ def strip_jvm_properties_from_jruby_opts
493
+ jruby_opts = ENV['JRUBY_OPTS']
494
+ return '' if jruby_opts.nil?
495
+ jvm_properties = []
496
+ properties = jruby_opts.split(' ')
497
+ properties.each do |property|
498
+ if property =~ /^-J.+/
499
+ jvm_properties << property.sub(/-J/, '')
500
+ ENV['JRUBY_OPTS'] = ENV['JRUBY_OPTS'].sub(property, '')
501
+ end
502
+ end
503
+ # get rid of any leftover spaces
504
+ ENV['JRUBY_OPTS'] = ENV['JRUBY_OPTS'].split(' ').join(' ')
505
+ jvm_properties.join(' ')
506
+ end
507
+
508
+ def rubylib_with_bundler(load_path)
509
+ bundler_load_paths = load_path.select { |p| p.include?('bundler') }
510
+ rubylib = (ENV['RUBYLIB'] || '').dup # ENV strings are frozen
511
+ unless rubylib.empty? || bundler_load_paths.empty?
512
+ rubylib << ':'
513
+ end
514
+ rubylib << bundler_load_paths.join(':')
515
+ end
516
+
417
517
  private
418
518
 
419
519
  def undeploy(name, opts = {})
@@ -23,6 +23,7 @@ rescue LoadError
23
23
  end
24
24
 
25
25
  module TorqueBox
26
+ # @api private
26
27
  class Rails
27
28
 
28
29
  def self.new_app( root )
@@ -251,13 +251,13 @@ describe TorqueBox::DeployUtils do
251
251
  end
252
252
 
253
253
  it 'should set java options' do
254
- @util.should_receive(:set_java_opts).with('java options ')
254
+ @util.should_receive(:set_java_opts).with('java options')
255
255
  @util.run_server(:jvm_options => 'java options')
256
256
  end
257
257
 
258
258
  it 'should pass JRUBY_OPTS properties' do
259
- ENV['JRUBY_OPTS'] = '--1.9 -Xjit.logging=true -Xthread.pool.enabled=true -X+C'
260
- @util.should_receive(:set_java_opts).with(' -Djruby.jit.logging=true -Djruby.thread.pool.enabled=true')
259
+ ENV['JRUBY_OPTS'] = '--1.9 -Xjit.logging=true -Xthread.pool.enabled=true'
260
+ @util.should_receive(:set_java_opts).with('-Djruby.jit.logging=true -Djruby.thread.pool.enabled=true')
261
261
  @util.run_server
262
262
  end
263
263
 
@@ -266,6 +266,13 @@ describe TorqueBox::DeployUtils do
266
266
  @util.should_receive(:set_java_opts).with('java options -Djruby.jit.logging=true')
267
267
  @util.run_server(:jvm_options => 'java options')
268
268
  end
269
+
270
+ it 'should strip and pass JRUBY_OPTS jvm options' do
271
+ ENV['JRUBY_OPTS'] = '--1.9 -J-Xmx1024m -J-Xss2048k -Xjit.logging=true'
272
+ @util.should_receive(:set_java_opts).with('some java options -Djruby.jit.logging=true -Xmx1024m -Xss2048k')
273
+ @util.run_server(:jvm_options => 'some java options')
274
+ ENV['JRUBY_OPTS'].should == '--1.9 -Xjit.logging=true'
275
+ end
269
276
  end
270
277
 
271
278
  describe '.is_deployed?' do
@@ -449,4 +456,35 @@ describe TorqueBox::DeployUtils do
449
456
  @util.deployment_status[@appname][:status].should == 'deployment failed'
450
457
  end
451
458
  end
459
+
460
+ describe '.rubylib_with_bundler' do
461
+ before(:each) do
462
+ @rubylib = ENV['RUBYLIB']
463
+ end
464
+
465
+ after(:each) do
466
+ ENV['RUBYLIB'] = @rubylib
467
+ end
468
+
469
+ it 'should equal ENV["RUBYLIB"] if bundler not in load path' do
470
+ ENV['RUBYLIB'] = '/path/to/somewhere'
471
+ @util.rubylib_with_bundler([]).should == '/path/to/somewhere'
472
+ end
473
+
474
+ it 'should be empty if ENV["RUBYLIB"] not set and bundler not on load path' do
475
+ ENV['RUBYLIB'] = nil
476
+ @util.rubylib_with_bundler([]).should be_empty
477
+ end
478
+
479
+ it 'should not include ENV["RUBYLIB"] if not set' do
480
+ ENV['RUBYLIB'] = nil
481
+ @util.rubylib_with_bundler(['/some/bundler/path']).should == '/some/bundler/path'
482
+ end
483
+
484
+ it 'should only include load path entries containing bundler' do
485
+ ENV['RUBYLIB'] = '/path/to/abc'
486
+ load_path = ['/some/bundler/path', '/some/other/path']
487
+ @util.rubylib_with_bundler(load_path).should =='/path/to/abc:/some/bundler/path'
488
+ end
489
+ end
452
490
  end
metadata CHANGED
@@ -1,109 +1,112 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: torquebox-rake-support
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 2.1.2
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 2.2.0
6
6
  platform: ruby
7
- authors:
8
- - The TorqueBox Team
9
- autorequire:
7
+ authors:
8
+ - The TorqueBox Team
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-09-24 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.8.7
24
- - - <
25
- - !ruby/object:Gem::Version
26
- version: 1.0.0
27
- type: :runtime
28
- version_requirements: *id001
29
- - !ruby/object:Gem::Dependency
30
- name: rspec
31
- prerelease: false
32
- requirement: &id002 !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - "="
36
- - !ruby/object:Gem::Version
37
- version: 2.7.0
38
- type: :development
39
- version_requirements: *id002
40
- description: ""
41
- email:
42
- - torquebox-dev@torquebox.org
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.8.7
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.7
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '='
35
+ - !ruby/object:Gem::Version
36
+ version: 2.7.0
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '='
41
+ - !ruby/object:Gem::Version
42
+ version: 2.7.0
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ description: ''
47
+ email:
48
+ - torquebox-dev@torquebox.org
43
49
  executables: []
44
-
45
50
  extensions: []
46
-
47
51
  extra_rdoc_files: []
48
-
49
- files:
50
- - licenses/lgpl-2.1.txt
51
- - lib/org.torquebox.rake-support.rb
52
- - lib/torquebox-rake-support.rb
53
- - lib/torquebox/server.rb
54
- - lib/torquebox/upstart.rb
55
- - lib/torquebox/deploy_utils.rb
56
- - lib/torquebox/rails.rb
57
- - lib/torquebox/launchd.rb
58
- - lib/torquebox/rake/tasks.rb
59
- - lib/torquebox/rake/tasks/deployment.rb
60
- - lib/torquebox/rake/tasks/server.rb
61
- - lib/torquebox/rake/tasks/archive.rb
62
- - generators/USAGE
63
- - generators/torquebox_queue_generator.rb
64
- - generators/templates/queue.rb
65
- - spec/spec_helper.rb
66
- - spec/server_spec.rb
67
- - spec/deploy_utils_spec.rb
68
- - spec/upstart_spec.rb
69
- - spec/rails_spec.rb
70
- - spec/fixtures/simpleapp/simpleapp.box
71
- - spec/fixtures/simpleapp/config.ru
72
- - spec/fixtures/simpleapp/puppet/puppet.rb
73
- - spec/fixtures/simpleapp/app/app.rb
74
- - spec/fixtures/simpleapp/app/a-non-cached.gem
75
- - spec/fixtures/simpleapp/app/puppet-master.rb
76
- - spec/fixtures/simpleapp/app/app.box
77
- - spec/fixtures/simpleapp/vendor/vendor.rb
52
+ files:
53
+ - licenses/lgpl-2.1.txt
54
+ - lib/org.torquebox.rake-support.rb
55
+ - lib/torquebox-rake-support.rb
56
+ - lib/torquebox/rails.rb
57
+ - lib/torquebox/deploy_utils.rb
58
+ - lib/torquebox/upstart.rb
59
+ - lib/torquebox/launchd.rb
60
+ - lib/torquebox/server.rb
61
+ - lib/torquebox/rake/tasks.rb
62
+ - lib/torquebox/rake/tasks/deployment.rb
63
+ - lib/torquebox/rake/tasks/archive.rb
64
+ - lib/torquebox/rake/tasks/server.rb
65
+ - generators/USAGE
66
+ - generators/torquebox_queue_generator.rb
67
+ - generators/templates/queue.rb
68
+ - spec/server_spec.rb
69
+ - spec/deploy_utils_spec.rb
70
+ - spec/rails_spec.rb
71
+ - spec/upstart_spec.rb
72
+ - spec/spec_helper.rb
73
+ - spec/fixtures/simpleapp/simpleapp.box
74
+ - spec/fixtures/simpleapp/config.ru
75
+ - spec/fixtures/simpleapp/vendor/vendor.rb
76
+ - spec/fixtures/simpleapp/puppet/puppet.rb
77
+ - spec/fixtures/simpleapp/app/app.box
78
+ - spec/fixtures/simpleapp/app/a-non-cached.gem
79
+ - spec/fixtures/simpleapp/app/app.rb
80
+ - spec/fixtures/simpleapp/app/puppet-master.rb
78
81
  homepage: http://torquebox.org/
79
- licenses:
80
- - lgpl
81
- post_install_message:
82
+ licenses:
83
+ - lgpl
84
+ post_install_message:
82
85
  rdoc_options: []
83
-
84
- require_paths:
85
- - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: !binary |-
93
+ MA==
87
94
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
92
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: !binary |-
100
+ MA==
93
101
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
98
102
  requirements: []
99
-
100
- rubyforge_project:
103
+ rubyforge_project:
101
104
  rubygems_version: 1.8.24
102
- signing_key:
105
+ signing_key:
103
106
  specification_version: 3
104
107
  summary: TorqueBox Rake Support
105
- test_files:
106
- - spec/server_spec.rb
107
- - spec/deploy_utils_spec.rb
108
- - spec/upstart_spec.rb
109
- - spec/rails_spec.rb
108
+ test_files:
109
+ - spec/server_spec.rb
110
+ - spec/deploy_utils_spec.rb
111
+ - spec/rails_spec.rb
112
+ - spec/upstart_spec.rb