Skip to content

Derive GEM_HOME from ruby binary instead of hardcoding the version#2772

Merged
aramprice merged 1 commit into
mainfrom
fix-ruby-4.0
Jul 14, 2026
Merged

Derive GEM_HOME from ruby binary instead of hardcoding the version#2772
aramprice merged 1 commit into
mainfrom
fix-ruby-4.0

Conversation

@aramprice

@aramprice aramprice commented Jul 14, 2026

Copy link
Copy Markdown
Member

Problem

When the director was switched to Ruby 4.0, three job templates hardcoded ruby/4.0.0 as the GEM_HOME path suffix:

File Hardcoded value
jobs/director/templates/env.erb ruby/4.0.0
jobs/health_monitor/templates/bpm.yml ruby/4.0.0
jobs/nats/templates/bpm.yml ruby/4.0.0

Ruby 3.x always reports Gem.ruby_api_version as X.Y.0 (patch = 0), so the hardcoded suffix worked before. Ruby 4.0.x changed this — it now includes the patch version: 4.0.5, 4.0.6, etc. Gems are bundled into gem_home/ruby/4.0.6 but the director looked in gem_home/ruby/4.0.0, causing every Ruby-dependent job to fail to start:

not running after update: director, worker_1, worker_2, worker_3, health_monitor, credhub

Observed failures: brats-performance/564, bosh-disaster-recovery-acceptance-tests/568.

Fix

Replace the hardcoded version suffix with a shell command substitution that asks the ruby binary from the package itself:

$(ruby -e 'puts Gem.ruby_api_version')

ruby is already in PATH when these expressions are evaluated because each script sources runtime.env from director-ruby-4.0 first. The value is resolved at runtime and will automatically track any future Ruby 4.0.x patch bump without requiring a manual update.

Changes:

  • jobs/director/templates/env.erb — fixes director, scheduler, sync-dns, metrics-server, and all worker processes (they all source this file)
  • jobs/health_monitor/templates/health_monitor — dynamic GEM_HOME added after sourcing runtime.env
  • jobs/health_monitor/templates/bpm.yml — hardcoded GEM_HOME removed (superseded by the startup script)
  • jobs/nats/templates/bosh_nats_sync — dynamic GEM_HOME added after sourcing runtime.env
  • jobs/nats/templates/bpm.yml — hardcoded GEM_HOME removed (superseded by the startup script)

…g the version

Ruby 3.4.x reports Gem.ruby_api_version as "3.4.0" (patch = 0), so the
hardcoded path "ruby/4.0.0" happened to work for the previous default
major version but breaks under Ruby 4.0.x where the patch component is
included in the API version (e.g. "4.0.5", "4.0.6").

Replace the static "4.0.0" suffix in:
- jobs/director/templates/env.erb (sourced by director, scheduler,
  sync-dns, metrics-server, and all worker processes)
- jobs/health_monitor/templates/health_monitor
- jobs/nats/templates/bosh_nats_sync

with a shell command substitution that asks ruby itself:

  $(ruby -e 'puts Gem.ruby_api_version')

"ruby" is already in PATH at this point because each script sources
runtime.env from the director-ruby-4.0 package first.

Also remove the now-redundant hardcoded GEM_HOME from the bpm.yml env
hash for the health_monitor and bosh_nats_sync processes; the value
is correctly set by the startup scripts they exec.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Director, health monitor, and NATS runtime scripts now derive GEM_HOME from Gem.ruby_api_version instead of using Ruby 4.0.0-specific paths. The health monitor and NATS BPM configurations no longer define GEM_HOME, leaving BUNDLE_GEMFILE in their environment blocks.

Suggested reviewers: ay901246, benjaminguttmann-avtq, julian-hj

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: deriving GEM_HOME dynamically instead of hardcoding the Ruby version.
Description check ✅ Passed The description covers the problem, fix, and affected files, but several template sections like tests, release notes, and breaking change are unfilled.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ruby-4.0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes BOSH job startup failures caused by hardcoded GEM_HOME paths that assumed RubyGems’ API version always ended in .0 (e.g., 4.0.0). With Ruby 4.0.x now including patch in Gem.ruby_api_version (e.g., 4.0.6), the jobs must derive the correct suffix at runtime.

Changes:

  • Replace hardcoded .../ruby/4.0.0 with .../ruby/$(ruby -e 'puts Gem.ruby_api_version') where GEM_HOME is set in startup scripts/templates.
  • Remove GEM_HOME from BPM YAML env blocks for health_monitor and nats where it is now set by the executable wrapper script instead.
  • Update the director’s shared env template so all director-related processes inherit the dynamic GEM_HOME.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
jobs/nats/templates/bpm.yml Removes hardcoded GEM_HOME from BPM env for bosh_nats_sync (now set by wrapper script).
jobs/nats/templates/bosh_nats_sync Sets GEM_HOME dynamically after sourcing the Ruby runtime env.
jobs/health_monitor/templates/health_monitor Sets GEM_HOME dynamically after sourcing the Ruby runtime env.
jobs/health_monitor/templates/bpm.yml Removes hardcoded GEM_HOME from BPM env (now set by wrapper script).
jobs/director/templates/env.erb Makes director-wide GEM_HOME dynamic so all sourcing processes track Ruby patch bumps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aramprice
aramprice merged commit d270eff into main Jul 14, 2026
25 checks passed
@aramprice
aramprice deleted the fix-ruby-4.0 branch July 14, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants