Skip to content

Commit 8c595ba

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 03942a1 commit 8c595ba

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"
@@ -614,9 +615,11 @@ func (s *Supplier) UpdateRubygems() error {
614615
// overwrites the buildpack-installed bundler (2.x) with bundler 4.x,
615616
// which has incompatible output format changes and untested behavior.
616617
// Re-install the buildpack's bundler to restore the manifest version.
617-
s.Log.Debug("Re-installing bundler after rubygems update")
618-
if err := s.InstallBundler(); err != nil {
619-
return fmt.Errorf("Could not re-install bundler after rubygems update: %v", err)
618+
if majorVersion, err := strconv.Atoi(strings.SplitN(dep.Version, ".", 2)[0]); err == nil && majorVersion >= 4 {
619+
s.Log.Debug("Re-installing bundler after rubygems %s update", dep.Version)
620+
if err := s.InstallBundler(); err != nil {
621+
return fmt.Errorf("Could not re-install bundler after rubygems update: %v", err)
622+
}
620623
}
621624

622625
return nil

src/ruby/supply/supply_test.go

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

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

@@ -1226,6 +1216,39 @@ var _ = Describe("Supply", func() {
12261216
})
12271217
})
12281218

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

0 commit comments

Comments
 (0)