Skip to content

Commit 88d5afd

Browse files
dzuelkeschneems
andauthored
Set WEB_CONCURRENCY_SET_BY=heroku/ruby if WEB_CONCURRENCY gets auto-set (#1700)
* Set WEB_CONCURRENCY_SET_BY=heroku/ruby if WEB_CONCURRENCY gets auto-set The Ruby buildpack sets the `WEB_CONCURRENCY` env var at app boot based on the current dyno size if the (deprecated) `SENSIBLE_DEFAULTS` mode is enabled, so long as the user hasn't specified a custom value via the app's config vars. Now, in addition to setting the `WEB_CONCURRENCY` env var, the buildpack will also set `WEB_CONCURRENCY_SET_BY=heroku/ruby` to allow the app, other boot time scripts, or humans more easily differentiate between a user and a buildpack provided `WEB_CONCURRENCY` (and determine which buildpack actually set it). In addition to assisting with debugging, this allows for UX improvements in other buildpacks such as the PHP buildpack, which can now check for `WEB_CONCURRENCY_SET_BY` in its boot time Apache/Nginx `heroku-php-...` scripts to ignore `WEB_CONCURRENCY` in cases where users have ordered the buildpacks on their app in the wrong order (the "primary" language is supposed to be listed last, otherwise the wrong concurrency value will be used). See also: heroku/heroku-buildpack-nodejs#932 heroku/heroku-buildpack-python#2015 GUS-W-20882005 * Track SENSIBLE_DEFAULTS usage This feature is deprecated, let's see how many people still rely on it. --------- Signed-off-by: Richard Schneeman <[email protected]> Co-authored-by: Richard Schneeman <[email protected]>
1 parent b1fee1f commit 88d5afd

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Set `WEB_CONCURRENCY_SET_BY=heroku/ruby` if `WEB_CONCURRENCY` gets set in (deprecated) `SENSIBLE_DEFAULTS` mode (https://github.com/heroku/heroku-buildpack-ruby/pull/1700)
56
- Default Node.js version now 24.13.0 (https://github.com/heroku/heroku-buildpack-ruby/pull/1704)
67

78
## [v344] - 2026-01-14

lib/language_pack/ruby.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def compile
113113
best_practice_warnings
114114
warn_outdated_ruby
115115
default_config_vars = self.class.default_config_vars(metadata: @metadata, ruby_version: @ruby_version, bundler: bundler, environment_name: environment_name)
116-
setup_profiled(ruby_layer_path: "$HOME", gem_layer_path: "$HOME", ruby_version: @ruby_version, default_config_vars: default_config_vars) # $HOME is set to /app at run time
116+
setup_profiled(ruby_layer_path: "$HOME", gem_layer_path: "$HOME", ruby_version: @ruby_version, default_config_vars: default_config_vars, report: @report) # $HOME is set to /app at run time
117117
setup_export(app_path: app_path, ruby_version: @ruby_version, default_config_vars: default_config_vars)
118118
cleanup
119119
super
@@ -240,18 +240,22 @@ def set_default_web_concurrency
240240
256)
241241
export HEROKU_RAM_LIMIT_MB=${HEROKU_RAM_LIMIT_MB:-512}
242242
export WEB_CONCURRENCY=${WEB_CONCURRENCY:-2}
243+
export WEB_CONCURRENCY_SET_BY=heroku/ruby
243244
;;
244245
512)
245246
export HEROKU_RAM_LIMIT_MB=${HEROKU_RAM_LIMIT_MB:-1024}
246247
export WEB_CONCURRENCY=${WEB_CONCURRENCY:-4}
248+
export WEB_CONCURRENCY_SET_BY=heroku/ruby
247249
;;
248250
16384)
249251
export HEROKU_RAM_LIMIT_MB=${HEROKU_RAM_LIMIT_MB:-2560}
250252
export WEB_CONCURRENCY=${WEB_CONCURRENCY:-8}
253+
export WEB_CONCURRENCY_SET_BY=heroku/ruby
251254
;;
252255
32768)
253256
export HEROKU_RAM_LIMIT_MB=${HEROKU_RAM_LIMIT_MB:-6144}
254257
export WEB_CONCURRENCY=${WEB_CONCURRENCY:-16}
258+
export WEB_CONCURRENCY_SET_BY=heroku/ruby
255259
;;
256260
*)
257261
;;
@@ -335,7 +339,7 @@ def setup_export(app_path: , ruby_version: , default_config_vars: )
335339
end
336340

337341
# sets up the profile.d script for this buildpack
338-
def setup_profiled(ruby_layer_path: , gem_layer_path:, ruby_version: , default_config_vars: )
342+
def setup_profiled(ruby_layer_path: , gem_layer_path:, ruby_version: , default_config_vars: , report:)
339343
profiled_path = []
340344

341345
default_config_vars.each do |key, value|
@@ -361,6 +365,7 @@ def setup_profiled(ruby_layer_path: , gem_layer_path:, ruby_version: , default_c
361365
set_env_default "MALLOC_ARENA_MAX", "2" if default_malloc_arena_max?
362366

363367
web_concurrency = env("SENSIBLE_DEFAULTS") ? set_default_web_concurrency : ""
368+
report.capture("web_concurrency.sensible_defaults" => web_concurrency.empty?)
364369
add_to_profiled(web_concurrency, filename: "WEB_CONCURRENCY.sh", mode: "w") # always write that file, even if its empty (meaning no defaults apply), for interop with other buildpacks - and we overwrite the file rather than appending (which is the default)
365370

366371
# TODO handle JRUBY

lib/language_pack/test/ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def compile
1515
install_binaries
1616
prepare_tests
1717
default_config_vars = self.class.default_config_vars(metadata: @metadata, ruby_version: @ruby_version, bundler: bundler, environment_name: environment_name)
18-
setup_profiled(ruby_layer_path: "$HOME", gem_layer_path: "$HOME", ruby_version: @ruby_version, default_config_vars: default_config_vars) # $HOME is set to /app at run time
18+
setup_profiled(ruby_layer_path: "$HOME", gem_layer_path: "$HOME", ruby_version: @ruby_version, default_config_vars: default_config_vars, report: @report) # $HOME is set to /app at run time
1919
setup_export(app_path: app_path, ruby_version: @ruby_version, default_config_vars: default_config_vars)
2020
super
2121
end

spec/hatchet/ruby_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,12 @@
381381
expect(app.run("echo $WEB_CONCURRENCY", :heroku => {:env => "WEB_CONCURRENCY=0"}).strip).to eq("0")
382382
end
383383
end
384+
385+
it "with SENSIBLE_DEFAULTS on sets environment variables" do
386+
Hatchet::Runner.new('default_ruby', stack: DEFAULT_STACK, config: { "SENSIBLE_DEFAULTS" => "1" }).deploy do |app|
387+
expect(app.run("cat .profile.d/WEB_CONCURRENCY.sh").strip).not_to be_empty
388+
expect(app.run("echo $HEROKU_RAM_LIMIT_MB $WEB_CONCURRENCY $WEB_CONCURRENCY_SET_BY").strip).to eq("512 2 heroku/ruby")
389+
expect(app.run("echo $WEB_CONCURRENCY", :heroku => {:env => "WEB_CONCURRENCY=3"}).strip).to eq("3")
390+
end
391+
end
384392
end

0 commit comments

Comments
 (0)