Skip to content

Fix bundler 4.x incompatibility and switchblade multi-stack deletion#1131

Open
tnikolova82 wants to merge 4 commits intomasterfrom
fix-bundler-4x-compatibility
Open

Fix bundler 4.x incompatibility and switchblade multi-stack deletion#1131
tnikolova82 wants to merge 4 commits intomasterfrom
fix-bundler-4x-compatibility

Conversation

@tnikolova82
Copy link
Copy Markdown
Contributor

@tnikolova82 tnikolova82 commented Apr 6, 2026

Summary

This PR fixes two issues blocking the CF integration tests with cflinuxfs4 + cflinuxfs5:

1. Bundler 4.x incompatibility (Bug 5)

Rubygems 4.0.9 ships bundler 4.x as a default gem. When UpdateRubygems() runs
ruby setup.rb, it installs bundler 4.0.9 which overwrites the buildpack's bundler 2.7.2.

Changes:

  • src/ruby/versions/ruby.go — Updated GetBundlerVersion() regex to handle both
    Bundler version X.Y.Z (bundler 2.x) and X.Y.Z (date hash) (bundler 4.x) formats
  • supply/supply.go UpdateRubygems() — Re-install bundler 2.x after rubygems update
    when rubygems major version >= 4
  • supply/supply.go InstallBundler() — Fixed version selection: bundler 1.x uses
    "1.x.x" dependency, everything else uses "2.x.x"
  • supply/supply.go VendorBundlePath() — Only bundler 1.x uses nested vendor path
  • supply/supply.go InstallGems() — Bundler removal applies to bundler 2+
  • Added tests for bundler 2.x BUNDLED WITH, bundler 4.x vendor_bundle, and
    rubygems 4.x re-install scenarios

2. Switchblade multi-stack buildpack deletion (Bug 8)

When CF has both cflinuxfs4 and cflinuxfs5 stacks deployed, multiple buildpacks share
the same name (e.g., ruby_buildpack for each stack). The switchblade Initialize()
method called cf delete-buildpack -f <name> without -s <stack>, which fails with:

Multiple buildpacks named ruby_buildpack found. Specify a stack name by using a '-s' flag.

Changes:

  • vendor/.../switchblade/internal/cloudfoundry/initialize.go — Parse stack field
    from /v3/buildpacks API response and iterate over all resources, deleting each
    with the appropriate -s <stack> flag. Handles null-stack buildpacks by omitting
    the -s flag when stack is empty.

This is a vendored fix; the upstream switchblade repo (v0.9.4) has the same bug.

Rubygems 4.0.9 ships bundler 4.x as a default gem. When UpdateRubygems()
runs 'ruby setup.rb', it installs bundler 4.0.9 which overwrites the
buildpack's bundler 2.x. Bundler 4.x changed 'bundle version' output
format (omits 'Bundler version' prefix), breaking GetBundlerVersion().

Changes:
- GetBundlerVersion() regex: handle both bundler 2.x and 4.x output formats
- UpdateRubygems(): re-install manifest bundler after 'ruby setup.rb'
- InstallBundler(): invert version selection to default to 2.x.x
- VendorBundlePath(): only bundler 1.x uses nested path (future-proof)
- InstallGems(): only bundler 1.x skips BUNDLED WITH removal (future-proof)
- Tests: add bundler 2.x/4.x test cases, update UpdateRubygems test
The unconditional re-install caused the integration cache test to fail:
on first deploy, the second InstallBundler() call (from UpdateRubygems)
produced a 'Copy' line since libbuildpack had already cached the tarball
from the initial Download, violating the cache test assertion that no
Copy lines appear on first deploy.

Fix: only re-install bundler when rubygems major version >= 4, since
only rubygems 4.x ships bundler 4.x as a default gem. Rubygems 3.x
ships bundler 2.x which doesn't overwrite the buildpack's bundler.
When multiple buildpacks share the same name across different stacks
(e.g. ruby_buildpack for cflinuxfs4 and cflinuxfs5), cf delete-buildpack
requires -s <stack> to disambiguate. Without it, the command fails with:
'Multiple buildpacks named ruby_buildpack found. Specify a stack name
by using a -s flag.'

Parse the stack field from the /v3/buildpacks API response and iterate
over all resources, deleting each with the appropriate -s flag. This
fixes the CF integration test failure in Initialize() when both
cflinuxfs4 and cflinuxfs5 stacks are deployed.
@tnikolova82 tnikolova82 changed the title Fix bundler 4.x incompatibility caused by rubygems 4.x update Fix bundler 4.x incompatibility and switchblade multi-stack deletion Apr 9, 2026
Replace vendored switchblade patch with upstream fix from
cloudfoundry/switchblade#126, released as v0.9.5.
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.

1 participant