Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Redirect gemfile task logging to stdout

- Use staging plugin logger in gemfile_task

- Install bundler gem first

Change-Id: I2c392e686f6a1ec4a59434572e72dcb1e2b1f049
  • Loading branch information...
commit c71f47e5c8d8af79e4c378ff2659fbeb6c3ef8c9 1 parent 806bd6e
Jesse Zhang and Maria Shaldibina authored April Yu & Jesse Zhang committed
View
4 lib/vcap/staging/plugin/gemfile_support.rb
@@ -18,8 +18,8 @@ def compile_gems
return unless uses_bundler?
return if packaged_with_bundler_in_deployment_mode?
- gem_task.install
gem_task.install_bundler
+ gem_task.install
gem_task.remove_gems_cached_in_app
write_bundle_config
@@ -42,7 +42,7 @@ def gem_task
return @task if @task
base_dir = StagingPlugin.platform_config["cache"]
@task = GemfileTask.new(app_dir, library_version, ruby_cmd, base_dir,
- runtime[:version], {:bundle_without=>bundle_without}, @staging_uid, @staging_gid)
+ runtime[:version], logger, {:bundle_without=>bundle_without}, @staging_uid, @staging_gid)
end
def library_version
View
10 lib/vcap/staging/plugin/gemfile_task.rb
@@ -8,7 +8,7 @@
class GemfileTask
include SecureOperations
- def initialize(app_dir, library_version, ruby_cmd, base_dir, ruby_version, options={}, uid=nil, gid=nil)
+ def initialize(app_dir, library_version, ruby_cmd, base_dir, ruby_version, logger, options={}, uid=nil, gid=nil)
@app_dir = File.expand_path(app_dir)
@library_version = library_version
@cache_base_dir = File.join(base_dir, ruby_version)
@@ -19,13 +19,7 @@ def initialize(app_dir, library_version, ruby_cmd, base_dir, ruby_version, optio
@uid = uid
@gid = gid
@options = options
-
- log_file = File.expand_path(File.join(@app_dir, "..", "logs", "staging.log"))
- FileUtils.mkdir_p(File.dirname(log_file))
-
- @logger = Logger.new(log_file)
- @logger.level = ENV["DEBUG"] ? Logger::DEBUG : Logger::INFO
- @logger.formatter = lambda { |sev, time, pname, msg| "#{msg}\n" }
+ @logger = logger
@cache = GemCache.new(File.join(@cache_base_dir, "gem_cache"))
git_repo_dir = File.join(base_dir, "git_cache")
View
11 spec/unit/gemfile_support_spec.rb
@@ -187,17 +187,6 @@
end
end
-# TODO revisit this when we upgrade to Bundler 1.2.0, which adds the "ruby" method
-describe 'An app being staged with Ruby version specified in Gemfile' do
- before do
- app_fixture :sinatra_ruby_version_in_gemfile
- end
-
- it 'causes an error' do
- lambda {stage(sinatra_staging_env)}.should raise_error(RuntimeError, /undefined method `ruby'/)
- end
-end
-
describe 'An app being staged containing a gem designated for a specific Ruby platform' do
before do
app_fixture :sinatra_platforms_gemfile
View
31 spec/unit/gemfile_task_spec.rb
@@ -17,11 +17,21 @@
FileUtils.rm_rf(@git_working_dir)
end
+ let(:logger) do
+ logger = mock("logger")
+ stub(logger).warn
+ stub(logger).info
+ stub(logger).error
+ stub(logger).debug
+ logger
+ end
+
describe "Sinatra app with Gemfile.lock" do
before :each do
test_app = app_fixture_base_directory.join("sinatra_gemfile", "source")
FileUtils.cp_r(File.join(test_app, "."), @app_dir)
- @task = GemfileTask.new(@app_dir, "1.9.1", @ruby_cmd, @working_dir, "1.9.2p180")
+ @task = GemfileTask.new(@app_dir, "1.9.1", @ruby_cmd, @working_dir, "1.9.2p180", logger)
+ @task.install_bundler
end
it "should return specs in the order where dependent gems go first" do
@@ -37,7 +47,6 @@
end
end
end
-
end
describe "Sinatra app with git dependencies" do
@@ -47,7 +56,8 @@
@git_gems = %w(eventmachine vcap_logging)
- @task = GemfileTask.new(@app_dir, "1.9.1", @ruby_cmd, @working_dir, "1.9.2p180")
+ @task = GemfileTask.new(@app_dir, "1.9.1", @ruby_cmd, @working_dir, "1.9.2p180", logger)
+ @task.install_bundler
end
it "should include git gems in specs" do
@@ -72,10 +82,10 @@
it "should fail if revision is not specified" do
spec = {:name => "vcap_logging", :version => "1.0.2",
- :source => {:url => "git://github.com/cloudfoundry/common.git"}}
- lambda {
+ :source => {:url => "git://github.com/cloudfoundry/common.git"}}
+ expect {
@task.install_git_gem(spec)
- }.should raise_error
+ }.to raise_error
end
it "should put git gems in bundler path" do
@@ -94,10 +104,11 @@
test_gem = app_fixture_base_directory.join("sinatra_git", "test_gem")
FileUtils.cp_r(test_gem, @git_working_dir)
@spec = {:name => "hello", :version => "0.0.1",
- :source => {:url => "url",
- :revision => "revision",
- :git_scope => "git_scope"}}
- @task = GemfileTask.new(@app_dir, "1.9.1", @ruby_cmd, @working_dir, "1.9.2p180")
+ :source => {:url => "url",
+ :revision => "revision",
+ :git_scope => "git_scope"}}
+ @task = GemfileTask.new(@app_dir, "1.9.1", @ruby_cmd, @working_dir, "1.9.2p180", logger)
+ @task.install_bundler
@task_git_cache = @task.instance_variable_get(:@git_cache)
stub(@task_git_cache).get_source do |source, where|
File.join(@git_working_dir, "test_gem")
Please sign in to comment.
Something went wrong with that request. Please try again.