Skip to content

Commit 39cbad9

Browse files
committed
Make bundler re-install conditional on rubygems >= 4.0
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.
1 parent 8ff5b4b commit 39cbad9

2 files changed

Lines changed: 39 additions & 13 deletions

File tree

src/ruby/supply/supply.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os/exec"
1010
"path/filepath"
1111
"regexp"
12+
"strconv"
1213
"strings"
1314

1415
"github.com/cloudfoundry/libbuildpack"
@@ -624,9 +625,11 @@ func (s *Supplier) UpdateRubygems() error {
624625
// overwrites the buildpack-installed bundler (2.x) with bundler 4.x,
625626
// which has incompatible output format changes and untested behavior.
626627
// Re-install the buildpack's bundler to restore the manifest version.
627-
s.Log.Debug("Re-installing bundler after rubygems update")
628-
if err := s.InstallBundler(); err != nil {
629-
return fmt.Errorf("Could not re-install bundler after rubygems update: %v", err)
628+
if majorVersion, err := strconv.Atoi(strings.SplitN(dep.Version, ".", 2)[0]); err == nil && majorVersion >= 4 {
629+
s.Log.Debug("Re-installing bundler after rubygems %s update", dep.Version)
630+
if err := s.InstallBundler(); err != nil {
631+
return fmt.Errorf("Could not re-install bundler after rubygems update: %v", err)
632+
}
630633
}
631634

632635
return nil

src/ruby/supply/supply_test.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,16 +1185,6 @@ var _ = Describe("Supply", func() {
11851185
})
11861186
mockCommand.EXPECT().Output(gomock.Any(), "ruby", "setup.rb")
11871187

1188-
// After ruby setup.rb, UpdateRubygems re-installs bundler.
1189-
// InstallBundler reads Gemfile.lock (not present here, so defaults
1190-
// to 2.x.x constraint) and installs bundler from the manifest.
1191-
mockInstaller.EXPECT().InstallDependency(gomock.Any(), gomock.Any()).Do(func(dep libbuildpack.Dependency, installDir string) {
1192-
Expect(dep.Name).To(Equal("bundler"))
1193-
Expect(dep.Version).To(Equal("2.7.2"))
1194-
// Create bin dir so LinkDirectoryInDepDir succeeds
1195-
Expect(os.MkdirAll(filepath.Join(installDir, "bin"), 0755)).To(Succeed())
1196-
})
1197-
11981188
Expect(supplier.UpdateRubygems()).To(Succeed())
11991189
})
12001190

@@ -1227,6 +1217,39 @@ var _ = Describe("Supply", func() {
12271217
})
12281218
})
12291219

1220+
Describe("UpdateRubygems with rubygems >= 4 re-installs bundler", func() {
1221+
BeforeEach(func() {
1222+
mockManifest.EXPECT().AllDependencyVersions("rubygems").AnyTimes().Return([]string{"4.0.9"})
1223+
})
1224+
Context("gem version is less than 4.0.9", func() {
1225+
BeforeEach(func() {
1226+
mockCommand.EXPECT().Output(gomock.Any(), "gem", "--version").AnyTimes().Return("3.4.19\n", nil)
1227+
mockVersions.EXPECT().VersionConstraint("3.4.19", ">= 4.0.9").AnyTimes().Return(false, nil)
1228+
})
1229+
1230+
It("updates rubygems and re-installs bundler", func() {
1231+
mockVersions.EXPECT().Engine().Return("ruby", nil)
1232+
mockInstaller.EXPECT().InstallDependency(gomock.Any(), gomock.Any()).Do(func(dep libbuildpack.Dependency, _ string) {
1233+
Expect(dep.Name).To(Equal("rubygems"))
1234+
Expect(dep.Version).To(Equal("4.0.9"))
1235+
})
1236+
mockCommand.EXPECT().Output(gomock.Any(), "ruby", "setup.rb")
1237+
1238+
// Rubygems >= 4 triggers bundler re-install.
1239+
// InstallBundler reads Gemfile.lock (not present here, so defaults
1240+
// to 2.x.x constraint) and installs bundler from the manifest.
1241+
mockInstaller.EXPECT().InstallDependency(gomock.Any(), gomock.Any()).Do(func(dep libbuildpack.Dependency, installDir string) {
1242+
Expect(dep.Name).To(Equal("bundler"))
1243+
Expect(dep.Version).To(Equal("2.7.2"))
1244+
// Create bin dir so LinkDirectoryInDepDir succeeds
1245+
Expect(os.MkdirAll(filepath.Join(installDir, "bin"), 0755)).To(Succeed())
1246+
})
1247+
1248+
Expect(supplier.UpdateRubygems()).To(Succeed())
1249+
})
1250+
})
1251+
})
1252+
12301253
Describe("RewriteShebangs", func() {
12311254
var depDir string
12321255
BeforeEach(func() {

0 commit comments

Comments
 (0)