Skip to content

Commit

Permalink
Add Next Gemfile Support
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
JuanVqz committed Mar 21, 2024
1 parent 7866d1e commit fcf946a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
5 changes: 4 additions & 1 deletion bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ APP_DIR=$(pwd)
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)

# legacy buildpack uses $STACK
# legacy buildpack uses $STACK
export STACK=$CNB_STACK_ID

echo "-----> build JUAN"
printenv

source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"

Expand Down
3 changes: 3 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ENV_DIR=$3
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)

echo "-----> compile JUAN"
printenv

source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"

Expand Down
9 changes: 7 additions & 2 deletions lib/language_pack/helpers/bundler_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def initialize(version_hash, major_minor)
attr_reader :bundler_path

def initialize(options = {})
puts ENV.inspect
@bundler_tmp = Pathname.new(Dir.mktmpdir)
@fetcher = options[:fetcher] || LanguagePack::Fetcher.new(LanguagePack::Base::VENDOR_URL) # coupling
@gemfile_path = options[:gemfile_path] || Pathname.new("./Gemfile")
@gemfile_path = options[:gemfile_path] || Pathname.new(ENV["BUNDLE_GEMFILE"] || "./Gemfile")
@gemfile_lock_path = Pathname.new("#{@gemfile_path}.lock")

@version = self.class.detect_bundler_version(contents: @gemfile_lock_path.read(mode: "rt"))
Expand All @@ -114,7 +115,9 @@ def initialize(options = {})
end

def install
warn("bundle_wrapper install start #{ENV['BUNDLE_GEMFILE']}")
ENV['BUNDLE_GEMFILE'] = @gemfile_path.to_s
warn("bundle_wrapper install end #{ENV['BUNDLE_GEMFILE']}")

fetch_bundler
$LOAD_PATH << @path
Expand All @@ -123,7 +126,9 @@ def install
end

def clean
warn("bundle_wrapper clean start #{ENV['BUNDLE_GEMFILE']}")
ENV['BUNDLE_GEMFILE'] = @orig_bundle_gemfile
warn("bundle_wrapper clean end #{ENV['BUNDLE_GEMFILE']}")
@bundler_tmp.rmtree if @bundler_tmp.directory?
end

Expand Down Expand Up @@ -223,7 +228,7 @@ def needs_ruby_global_append_path?
end

def bundler_version_escape_valve!
topic("Removing BUNDLED WITH version in the Gemfile.lock")
topic("Removing BUNDLED WITH version in the #{@gemfile_lock_path}")
contents = File.read(@gemfile_lock_path, mode: "rt")
File.open(@gemfile_lock_path, "w") do |f|
f.write contents.sub(/^BUNDLED WITH$(\r?\n) (?<major>\d+)\.\d+\.\d+/m, '')
Expand Down
29 changes: 26 additions & 3 deletions lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,26 @@ def self.use?
end

def self.bundler
warn("setting bundler", inline: true)
@@bundler ||= LanguagePack::Helpers::BundlerWrapper.new.install
end

def bundler
self.class.bundler
end

def current_gemfile
ENV["BUNDLE_GEMFILE"] || "Gemfile"
end

def gemfile_path
Pathname.new(current_gemfile)
end

def gemfile_lock_path
Pathname.new("#{current_gemfile}.lock")
end

def initialize(*args)
super(*args)
@fetchers[:mri] = LanguagePack::Fetcher.new(VENDOR_URL, @stack)
Expand All @@ -55,6 +68,7 @@ def default_addons
def default_config_vars
vars = {
"LANG" => env("LANG") || "en_US.UTF-8",
"BUNDLE_GEMFILE" => env("BUNDLE_GEMFILE") || "Gemfile",
}

ruby_version.jruby? ? vars.merge({
Expand All @@ -81,6 +95,8 @@ def best_practice_warnings

def compile
# check for new app at the beginning of the compile
warn("JUAN current 1", inline: true)
warn("JUAN starting compile #{ENV['BUNDLE_GEMFILE']}", inline: true)
new_app?
Dir.chdir(build_path)
remove_vendor_bundle
Expand All @@ -93,6 +109,7 @@ def compile
bundle_path: "vendor/bundle",
bundle_default_without: "development:test"
)
warn("JUAN starting compile allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
allow_git do
install_bundler_in_app(slug_vendor_base)
load_bundler_cache
Expand All @@ -102,12 +119,14 @@ def compile
install_binaries
run_assets_precompile_rake_task
end
warn("JUAN ending compile allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
config_detect
best_practice_warnings
warn_outdated_ruby
setup_profiled(ruby_layer_path: "$HOME", gem_layer_path: "$HOME") # $HOME is set to /app at run time
setup_export
cleanup
warn("JUAN ending compile #{ENV['BUNDLE_GEMFILE']}", inline: true)
super
rescue => e
warn_outdated_ruby
Expand All @@ -116,6 +135,7 @@ def compile


def build
warn("JUAN starting build #{ENV['BUNDLE_GEMFILE']}", inline: true)
new_app?
remove_vendor_bundle
warn_bad_binstubs
Expand All @@ -134,6 +154,7 @@ def build
bundle_path: "#{gem_layer.path}/vendor/bundle",
bundle_default_without: "development:test"
)
warn("JUAN starting build allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
allow_git do
# TODO install bundler in separate layer
topic "Loading Bundler Cache"
Expand All @@ -144,7 +165,7 @@ def build
build_bundler
# TODO post_bundler might need to be done in a new layer
bundler.clean
gem_layer.metadata[:gems] = Digest::SHA2.hexdigest(File.read("Gemfile.lock"))
gem_layer.metadata[:gems] = Digest::SHA2.hexdigest(File.read(gemfile_lock_path))
gem_layer.metadata[:stack] = @stack
gem_layer.metadata[:ruby_version] = run_stdout(%q(ruby -v)).strip
gem_layer.metadata[:rubygems_version] = run_stdout(%q(gem -v)).strip
Expand All @@ -156,12 +177,14 @@ def build
install_binaries
run_assets_precompile_rake_task
end
warn("JUAN ending build allow_git #{ENV['BUNDLE_GEMFILE']}", inline: true)
setup_profiled(ruby_layer_path: ruby_layer.path, gem_layer_path: gem_layer.path)
setup_export(gem_layer)
config_detect
best_practice_warnings
cleanup

warn("JUAN ending build #{ENV['BUNDLE_GEMFILE']}", inline: true)
super
end

Expand Down Expand Up @@ -779,7 +802,7 @@ def build_bundler
if bundler.windows_gemfile_lock?
log("bundle", "has_windows_gemfile_lock")

File.unlink("Gemfile.lock")
File.unlink(gemfile_lock_path)
ENV.delete("BUNDLE_DEPLOYMENT")

warn(<<~WARNING, inline: true)
Expand Down Expand Up @@ -816,7 +839,7 @@ def build_bundler

# we need to set BUNDLE_CONFIG and BUNDLE_GEMFILE for
# codon since it uses bundler.
env_vars["BUNDLE_GEMFILE"] = "#{pwd}/Gemfile"
env_vars["BUNDLE_GEMFILE"] = "#{pwd}/#{gemfile_path}"
env_vars["BUNDLE_CONFIG"] = "#{pwd}/.bundle/config"
env_vars["CPATH"] = noshellescape("#{yaml_include}:$CPATH")
env_vars["CPPATH"] = noshellescape("#{yaml_include}:$CPPATH")
Expand Down

0 comments on commit fcf946a

Please sign in to comment.