Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[close #1072] Don't install bundler twice on CI #1073

Merged
merged 6 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Main (unreleased)

* Fix double installation of bundler on CI runs when no test script is specified (https://github.com/heroku/heroku-buildpack-ruby/pull/1073)
* Bundler 2.x is now 2.1.4 (https://github.com/heroku/heroku-buildpack-ruby/pull/1052)
* Persistent bundler config is now being set using the `BUNDLE_*` env vars (https://github.com/heroku/heroku-buildpack-ruby/pull/1039)
* Rake task "assets:clean" will not get called if it does not exist (https://github.com/heroku/heroku-buildpack-ruby/pull/1018)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GEM
excon
moneta
multi_json (>= 1.9.2)
heroku_hatchet (7.1.3)
heroku_hatchet (7.3.0)
excon (~> 0)
platform-api (~> 3)
rrrretry (~> 1)
Expand Down
30 changes: 20 additions & 10 deletions bin/support/ruby_test
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,36 @@ def execute_command(command)
pipe(command, :user_env => true, :output_object => Kernel)
end

def user_env_hash
LanguagePack::ShellHelpers.user_env_hash
end

# $ bin/test BUILD_DIR ENV_DIR ARTIFACT_DIR
build_dir, env_dir, _ = ARGV
LanguagePack::ShellHelpers.initialize_env(env_dir)
Dir.chdir(build_dir)

# The `ruby_test-compile` program installs a version of Ruby for the
# user's application. It needs the propper `PATH`, where ever Ruby is installed
# otherwise we end up using the buildpack's version of Ruby
#
# This is needed here because LanguagePack::Ruby.slug_vendor_base shells out to the user's ruby binary
user_env_hash["PATH"] = "#{build_dir}/bin:#{ENV["PATH"]}"

bundler = LanguagePack::Helpers::BundlerWrapper.new(
gemfile_path: "#{build_dir}/Gemfile"
gemfile_path: "#{build_dir}/Gemfile",
bundler_path: LanguagePack::Ruby.slug_vendor_base # This was previously installed by bin/support/ruby_test-compile
)

# The `ruby_test-compile` program installs a version of Ruby for the
# user's application. It needs the propper `PATH`, where ever Ruby is installed
# we always add a symlink to the `bin/ruby` file so that is always valid.
# We calculate the gem path the same way we do when compiling.
LanguagePack::ShellHelpers.user_env_hash["PATH"] = "#{build_dir}/bin:#{bundler.bundler_path}/bin:#{ENV["PATH"]}"
LanguagePack::ShellHelpers.user_env_hash["GEM_PATH"] = LanguagePack::Ruby.slug_vendor_base
# - Add bundler's bin directory to the PATH
# - Always make sure `$HOME/bin` is first on the path
user_env_hash["PATH"] = "#{build_dir}/bin:#{bundler.bundler_path}/bin:#{user_env_hash["PATH"]}"
user_env_hash["GEM_PATH"] = LanguagePack::Ruby.slug_vendor_base

# load bundler
# - Sets BUNDLE_GEMFILE
# - Loads bundler's internal Gemfile.lock parser so we can use `bundler.has_gem?`
bundler.install

Dir.chdir(build_dir)

execute_test(
if bundler.has_gem?("rspec-core")
if File.exist?("bin/rspec")
Expand Down
8 changes: 8 additions & 0 deletions lib/language_pack/helpers/bundler_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ def fetch_bundler
topic("Installing bundler #{@version}")
bundler_version_escape_valve!

# Install directory structure (as of Bundler 2.1.4):
# - cache
# - bin
# - gems
# - specifications
# - build_info
# - extensions
# - doc
FileUtils.mkdir_p(bundler_path)
Dir.chdir(bundler_path) do
@fetcher.fetch_untar(@bundler_tar)
Expand Down
11 changes: 6 additions & 5 deletions lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,14 @@ def warn_bundler_upgrade
end
end


# For example "vendor/bundle/ruby/2.6.0"
def self.slug_vendor_base
command = %q(ruby -e "require 'rbconfig';puts \"vendor/bundle/#{RUBY_ENGINE}/#{RbConfig::CONFIG['ruby_version']}\"")
slug_vendor_base = run_no_pipe(command, user_env: true).chomp
error "Problem detecting bundler vendor directory: #{@slug_vendor_base}" unless $?.success?
return slug_vendor_base
@slug_vendor_base ||= begin
command = %q(ruby -e "require 'rbconfig';puts \"vendor/bundle/#{RUBY_ENGINE}/#{RbConfig::CONFIG['ruby_version']}\"")
out = run_no_pipe(command, user_env: true).chomp
error "Problem detecting bundler vendor directory: #{out}" unless $?.success?
out
end
end

# the relative path to the bundler directory of gems
Expand Down
2 changes: 1 addition & 1 deletion lib/language_pack/shell_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def topic(message)
# (indented by 6 spaces)
# @param [String] message to be displayed
def puts(message)
message.each_line do |line|
message.to_s.each_line do |line|
if line.end_with?("\n".freeze)
print " #{line}"
else
Expand Down
3 changes: 3 additions & 0 deletions spec/hatchet/ci_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
it "Does not cause the double ruby rainbow bug" do
Hatchet::Runner.new("heroku-ci-json-example").run_ci do |test_run|
expect(test_run.status).to eq(:succeeded)

install_bundler_count = test_run.output.scan("Installing bundler").count
expect(install_bundler_count).to eq(1), "Expected output to only install bundler once but was found #{install_bundler_count} times. output:\n#{test_run.output}"
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require 'language_pack'
require 'language_pack/shell_helpers'

ENV["HATCHET_BUILDPACK_BASE"] = "https://github.com/heroku/heroku-buildpack-ruby"

ENV['RACK_ENV'] = 'test'

DEFAULT_STACK = 'heroku-18'
Expand Down