Skip to content

Commit 47d5c8f

Browse files
authored
Clearing off (unreleased) main (#1653)
* Revert "Remove Cache dependency from Metadata (#1649)" This reverts commit 6c15f18. * Revert "Improve message on `bin/detect` failure (#1647)" This reverts commit 79ad8d7.
1 parent 6c15f18 commit 47d5c8f

File tree

7 files changed

+56
-109
lines changed

7 files changed

+56
-109
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## [Unreleased]
44

5-
- Internal refactor: Remove Cache class dependency from Metadata class (https://github.com/heroku/heroku-buildpack-ruby/pull/1649)
6-
- Improve message on `bin/detect` failure to include the list of files in the root directory (https://github.com/heroku/heroku-buildpack-ruby/pull/1647)
75

86
## [v322] - 2025-09-29
97

bin/detect

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,6 @@ APP_DIR=$1
77
if [ -f "$APP_DIR/Gemfile" ]; then
88
echo "Ruby"
99
exit 0
10+
else
11+
exit 1
1012
fi
11-
12-
output::error <<EOF
13-
Error: Your app is configured to use the Ruby buildpack,
14-
but we couldn't find any supported Ruby project files ('Gemfile.lock').
15-
16-
A Ruby app on Heroku must have a 'Gemfile.lock' in the root directory of its source code.
17-
18-
Currently the root directory of your app contains:
19-
20-
$(ls -1A --indicator-style=slash "${BUILD_DIR}" || true)
21-
22-
If your app already has a package manager file, check that it:
23-
24-
1. Is in the top level directory (not a subdirectory).
25-
2. Has the correct spelling (the filenames are case-sensitive).
26-
3. Isn't listed in '.gitignore' or '.slugignore'.
27-
4. Has been added to the Git repository using 'git add --all'
28-
and then committed using 'git commit'.
29-
30-
Otherwise, add a package manager file to your app. If your app has
31-
no dependencies, then create an empty 'Gemfile', run 'bundle install' and
32-
commit the results to git.
33-
34-
For help with using Ruby on Heroku, see:
35-
https://devcenter.heroku.com/articles/getting-started-with-ruby
36-
https://devcenter.heroku.com/articles/ruby-support
37-
EOF
38-
39-
exit 1

lib/language_pack/base.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def initialize(app_path: , cache_path: , gemfile_lock: )
2626
@app_path = app_path
2727
@stack = ENV.fetch("STACK")
2828
@cache = LanguagePack::Cache.new(cache_path)
29-
@metadata = LanguagePack::Metadata.new(cache_path: cache_path)
30-
@new_app = @metadata.empty?
29+
@metadata = LanguagePack::Metadata.new(@cache)
3130
@bundler_cache = LanguagePack::BundlerCache.new(@cache, @stack)
3231
@fetchers = {:buildpack => LanguagePack::Fetcher.new(VENDOR_URL) }
3332
@arch = get_arch
@@ -48,10 +47,6 @@ def get_arch
4847
arch
4948
end
5049

51-
def new_app?
52-
@new_app
53-
end
54-
5550
def self.===(app_path)
5651
raise "must subclass"
5752
end

lib/language_pack/metadata.rb

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
11
require "language_pack"
22
require "language_pack/base"
33

4-
# Store data about the build in the cache
5-
#
6-
# Uses `<cache_path>/vendor/heroku` as the metadata directory. Which
7-
# is special cased in cache clearing code to be durable. This allows
8-
# for persistant generated data such as SECRET_KEY_BASE that would otherwise
9-
# cause session invalidation if it changed unexpectedly between deploys.
104
class LanguagePack::Metadata
11-
def initialize(cache_path: )
12-
@dir = Pathname(cache_path)
13-
.join("vendor")
14-
.join("heroku")
15-
.tap(&:mkpath)
5+
FOLDER = "vendor/heroku"
6+
7+
def initialize(cache)
8+
if cache
9+
@cache = cache
10+
@cache.load FOLDER
11+
end
12+
end
13+
14+
def [](key)
15+
read(key)
1616
end
1717

18-
def empty?
19-
@dir.children.empty?
18+
def []=(key, value)
19+
write(key, value)
2020
end
2121

2222
def read(key)
23-
@dir.join(key).read&.strip
23+
full_key = "#{FOLDER}/#{key}"
24+
File.read(full_key).strip if exists?(key)
2425
end
2526

2627
def exists?(key)
27-
@dir.join(key).file?
28+
full_key = "#{FOLDER}/#{key}"
29+
File.exist?(full_key) && !Dir.exist?(full_key)
2830
end
31+
alias_method :include?, :exists?
2932

30-
def write(key, value)
31-
@dir.join(key).write(value)
33+
def write(key, value, isave = true)
34+
FileUtils.mkdir_p(FOLDER)
35+
36+
full_key = "#{FOLDER}/#{key}"
37+
File.open(full_key, 'w') {|f| f.puts value }
38+
save if isave
39+
40+
return true
41+
end
42+
43+
def touch(key)
44+
write(key, "true")
3245
end
3346

3447
def fetch(key)
35-
if exists?(key)
36-
read(key)
37-
else
38-
value = yield
39-
write(key, value.to_s)
40-
value
41-
end
48+
return read(key) if exists?(key)
49+
50+
value = yield
51+
52+
write(key, value.to_s)
53+
return value
54+
end
55+
56+
def save(file = FOLDER)
57+
@cache ? @cache.add(file) : false
4258
end
4359
end

lib/language_pack/ruby.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def warn_bad_binstubs
192192

193193
def default_malloc_arena_max?
194194
return true if @metadata.exists?("default_malloc_arena_max")
195-
return @metadata.write("default_malloc_arena_max", "true") if new_app?
195+
return @metadata.touch("default_malloc_arena_max") if new_app?
196196

197197
return false
198198
end
@@ -613,6 +613,10 @@ def install_ruby(install_path: )
613613
error message
614614
end
615615

616+
def new_app?
617+
@new_app ||= !app_path.join("vendor").join("heroku").exist?
618+
end
619+
616620
# find the ruby install path for its binstubs during build
617621
# @return [String] resulting path or empty string if ruby is not vendored
618622
def ruby_install_binstub_path(ruby_layer_path = ".")
@@ -1082,6 +1086,7 @@ def load_bundler_cache
10821086

10831087
full_ruby_version = run_stdout(%q(ruby -v)).strip
10841088
rubygems_version = run_stdout(%q(gem -v)).strip
1089+
heroku_metadata = "vendor/heroku"
10851090
old_rubygems_version = nil
10861091
ruby_version_cache = "ruby_version"
10871092
buildpack_version_cache = "buildpack_version"
@@ -1114,11 +1119,13 @@ def load_bundler_cache
11141119
purge_bundler_cache
11151120
end
11161121

1117-
@metadata.write(ruby_version_cache, full_ruby_version)
1118-
@metadata.write(buildpack_version_cache, BUILDPACK_VERSION)
1119-
@metadata.write(bundler_version_cache, bundler.version)
1120-
@metadata.write(rubygems_version_cache, rubygems_version)
1121-
@metadata.write(stack_cache, @stack)
1122+
FileUtils.mkdir_p(heroku_metadata)
1123+
@metadata.write(ruby_version_cache, full_ruby_version, false)
1124+
@metadata.write(buildpack_version_cache, BUILDPACK_VERSION, false)
1125+
@metadata.write(bundler_version_cache, bundler.version, false)
1126+
@metadata.write(rubygems_version_cache, rubygems_version, false)
1127+
@metadata.write(stack_cache, @stack, false)
1128+
@metadata.save
11221129
end
11231130

11241131
def purge_bundler_cache(stack = nil)

spec/hatchet/getting_started_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,18 @@
44
it "works on Heroku-24" do
55
Hatchet::Runner.new("ruby-getting-started", stack: "heroku-24").deploy do |app|
66
expect(app.output).to_not include("Purging Cache")
7-
expect(app.output).to include("Fetching puma")
8-
9-
secret_key_base = app.run("echo $SECRET_KEY_BASE")
107

118
# Re-deploy with cache
129
run!("git commit --allow-empty -m empty")
1310
app.push!
1411

15-
# Assert used cached gems
16-
expect(app.output).to_not include("Fetching puma")
17-
1812
# Assert no warnings from `cp`
1913
# https://github.com/heroku/heroku-buildpack-ruby/pull/1586/files#r2064284286
2014
expect(app.output).to_not include("cp --help")
2115
expect(app.run("which ruby").strip).to eq("/app/bin/ruby")
2216

2317
environment_variables = app.run("env")
2418
expect(environment_variables).to match("PUMA_PERSISTENT_TIMEOUT")
25-
# Assert cached value persisted
26-
expect(environment_variables).to match("SECRET_KEY_BASE=#{secret_key_base}")
2719

2820
profile_d = app.run("cat .profile.d/ruby.sh")
2921
.strip

spec/helpers/metadata_spec.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)