summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-09-18 12:24:27 -0700
committerGitHub <noreply@github.com>2019-09-18 12:24:27 -0700
commitb00b2ffc76a4ba3649fc5874bc593a37ea395ba8 (patch)
tree2c9aad2c41b9977fcb634f65bde5ce0e9d02e99a
parent36df720b496f7303baa434d74f694e55c056f64f (diff)
parentb4ea9af80e28309a086efd15825fb840f3d9d670 (diff)
downloadchef-b00b2ffc76a4ba3649fc5874bc593a37ea395ba8.tar.gz
Merge pull request #8901 from jjustice6/backport_8847
Backport #8847 into Chef 14: Added support to provide additional options to bundle install
-rw-r--r--lib/chef/cookbook/gem_installer.rb9
-rw-r--r--spec/unit/cookbook/gem_installer_spec.rb23
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb
index 79b62f7a72..4b871b33b4 100644
--- a/lib/chef/cookbook/gem_installer.rb
+++ b/lib/chef/cookbook/gem_installer.rb
@@ -66,8 +66,13 @@ class Chef
tf.close
Chef::Log.trace("generated Gemfile contents:")
Chef::Log.trace(IO.read(tf.path))
- so = shell_out!("bundle install", cwd: dir, env: { "PATH" => path_with_prepended_ruby_bin })
- Chef::Log.info(so.stdout)
+ # Skip installation only if Chef::Config[:skip_gem_metadata_installation] option is true
+ unless Chef::Config[:skip_gem_metadata_installation]
+ # Add additional options to bundle install
+ cmd = [ "bundle", "install", Chef::Config[:gem_installer_bundler_options] ]
+ so = shell_out!(cmd, cwd: dir, env: { "PATH" => path_with_prepended_ruby_bin })
+ Chef::Log.info(so.stdout)
+ end
end
end
Gem.clear_paths
diff --git a/spec/unit/cookbook/gem_installer_spec.rb b/spec/unit/cookbook/gem_installer_spec.rb
index b7c8db514a..858710d952 100644
--- a/spec/unit/cookbook/gem_installer_spec.rb
+++ b/spec/unit/cookbook/gem_installer_spec.rb
@@ -59,23 +59,25 @@ describe Chef::Cookbook::GemInstaller do
expect(File).to receive(:open).and_yield(gemfile)
expect(gemfile).to receive(:path).and_return("")
expect(IO).to receive(:read).and_return("")
- expect(gem_installer).to receive(:shell_out!).and_return(shell_out)
end
it "generates a valid Gemfile" do
+ expect(gem_installer).to receive(:shell_out!).and_return(shell_out)
expect { gem_installer.install }.to_not raise_error
expect { bundler_dsl }.to_not raise_error
end
it "generate a Gemfile with all constraints" do
+ expect(gem_installer).to receive(:shell_out!).and_return(shell_out)
expect { gem_installer.install }.to_not raise_error
expect(bundler_dsl.dependencies.find { |d| d.name == "httpclient" }.requirements_list.length).to eql(2)
end
it "generates a valid Gemfile when Chef::Config[:rubygems_url] is set to a String" do
+ expect(gem_installer).to receive(:shell_out!).and_return(shell_out)
Chef::Config[:rubygems_url] = "https://www.rubygems.org"
expect { gem_installer.install }.to_not raise_error
@@ -83,10 +85,29 @@ describe Chef::Cookbook::GemInstaller do
end
it "generates a valid Gemfile when Chef::Config[:rubygems_url] is set to an Array" do
+ expect(gem_installer).to receive(:shell_out!).and_return(shell_out)
Chef::Config[:rubygems_url] = [ "https://www.rubygems.org" ]
expect { gem_installer.install }.to_not raise_error
expect(bundler_dsl.dependencies.find { |d| d.name == "httpclient" }.requirements_list.length).to eql(2)
end
+
+ it "skip metadata installation when Chef::Config[:skip_gem_metadata_installation] is set to true" do
+ Chef::Config[:skip_gem_metadata_installation] = true
+ expect(gem_installer.install).to_not receive(:shell_out!)
+ end
+
+ it "install metadata when Chef::Config[:skip_gem_metadata_installation] is not true" do
+ expect(gem_installer).to receive(:shell_out!).and_return(shell_out)
+ expect(Chef::Log).to receive(:info).and_return("")
+ expect(gem_installer.install).to be_empty
+ end
+
+ it "install from local cache when Chef::Config[:gem_installer_bundler_options] is set to local" do
+ Chef::Config[:gem_installer_bundler_options] = "--local"
+ expect(gem_installer).to receive(:shell_out!).with(["bundle", "install", "--local"], any_args).and_return(shell_out)
+ expect(Chef::Log).to receive(:info).and_return("")
+ expect(gem_installer.install).to be_empty
+ end
end