Derive GEM_HOME from ruby binary instead of hardcoding the version#2772
Conversation
…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.
WalkthroughDirector, health monitor, and NATS runtime scripts now derive Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.0with.../ruby/$(ruby -e 'puts Gem.ruby_api_version')whereGEM_HOMEis set in startup scripts/templates. - Remove
GEM_HOMEfrom BPM YAML env blocks forhealth_monitorandnatswhere 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.
Problem
When the director was switched to Ruby 4.0, three job templates hardcoded
ruby/4.0.0as theGEM_HOMEpath suffix:jobs/director/templates/env.erbruby/4.0.0jobs/health_monitor/templates/bpm.ymlruby/4.0.0jobs/nats/templates/bpm.ymlruby/4.0.0Ruby 3.x always reports
Gem.ruby_api_versionasX.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 intogem_home/ruby/4.0.6but the director looked ingem_home/ruby/4.0.0, causing every Ruby-dependent job to fail to start: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')rubyis already inPATHwhen these expressions are evaluated because each script sourcesruntime.envfromdirector-ruby-4.0first. 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— fixesdirector,scheduler,sync-dns,metrics-server, and all worker processes (they all source this file)jobs/health_monitor/templates/health_monitor— dynamicGEM_HOMEadded after sourcingruntime.envjobs/health_monitor/templates/bpm.yml— hardcodedGEM_HOMEremoved (superseded by the startup script)jobs/nats/templates/bosh_nats_sync— dynamicGEM_HOMEadded after sourcingruntime.envjobs/nats/templates/bpm.yml— hardcodedGEM_HOMEremoved (superseded by the startup script)