Skip to content

Commit e75b9f0

Browse files
committed
Upgrade CNB to latest spec changes
- Requires ruby, with the version it reads from the gemfile - Requires and provides bundler, with the version it reads from the gemfile - Requires and provides rubygems - **This CNB is not yet fully implemented, and is not operational** [#167707118]
1 parent 777d8a3 commit e75b9f0

9 files changed

Lines changed: 84 additions & 58 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ To package this buildpack for consumption:
44
$ ./scripts/package.sh
55
```
66
This builds the buildpack's Go source using GOOS=linux by default. You can supply another value as the first argument to package.sh.
7+
8+
## This CNB is not yet fully implemented.

cmd/build/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package main
22

33
import (
4+
"fmt"
45
"github.com/cloudfoundry/bundler-cnb/bundler"
56
"github.com/cloudfoundry/bundler-cnb/gems"
6-
"fmt"
7-
"github.com/buildpack/libbuildpack/buildplan"
87
"github.com/cloudfoundry/libcfbuildpack/build"
98
)
109

@@ -26,8 +25,5 @@ func runBuild(context build.Build) (int, error) {
2625
}
2726
}
2827

29-
return context.Success(buildplan.BuildPlan{})
30-
31-
32-
return 0, fmt.Errorf("not implemented")
28+
return context.Success()
3329
}

cmd/detect/main.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,26 @@ func runDetect(context detect.Detect) (int, error) {
5050
}
5151

5252

53-
return context.Pass(buildplan.BuildPlan{
54-
ruby.Dependency: buildplan.Dependency{
55-
Version: rubyVersion,
56-
Metadata: buildplan.Metadata{"build": true, "launch": true},
53+
return context.Pass(buildplan.Plan{
54+
Requires: []buildplan.Required{
55+
{
56+
Name: ruby.Dependency,
57+
Version: rubyVersion,
58+
Metadata: buildplan.Metadata{"build": true, "launch": true},
59+
},
60+
{
61+
Name: bundler.Dependency,
62+
Version: bundlerVersion,
63+
Metadata: buildplan.Metadata{"build": true, "launch": true},
64+
},
65+
{
66+
Name: gems.Dependency,
67+
Metadata: buildplan.Metadata{"launch": true},
68+
},
5769
},
58-
bundler.Dependency: buildplan.Dependency{
59-
Version: bundlerVersion,
60-
Metadata: buildplan.Metadata{"build": true, "launch": true},
61-
},
62-
gems.Dependency: buildplan.Dependency{
63-
Metadata: buildplan.Metadata{"launch": true},
70+
Provides: []buildplan.Provided{
71+
{bundler.Dependency},
72+
{gems.Dependency},
6473
},
6574
})
6675
}

cmd/detect/main_test.go

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,26 @@ BUNDLED WITH
7272
code, err := runDetect(factory.Detect)
7373
Expect(err).NotTo(HaveOccurred())
7474
Expect(code).To(Equal(detect.PassStatusCode))
75-
Expect(factory.Output).To(Equal(buildplan.BuildPlan{
76-
ruby.Dependency: buildplan.Dependency{
77-
Version: "'~> 3.2','< 3.2.5'",
78-
Metadata: buildplan.Metadata{"build": true, "launch": true},
79-
},
80-
bundler.Dependency: buildplan.Dependency{
81-
Version: "1.16.4",
82-
Metadata: buildplan.Metadata{"build": true, "launch": true},
75+
Expect(factory.Plans.Plan).To(Equal(buildplan.Plan{
76+
Requires: []buildplan.Required{
77+
{
78+
Name: ruby.Dependency,
79+
Version: "'~> 3.2','< 3.2.5'",
80+
Metadata: buildplan.Metadata{"build": true, "launch": true},
81+
},
82+
{
83+
Name: bundler.Dependency,
84+
Version: "1.16.4",
85+
Metadata: buildplan.Metadata{"build": true, "launch": true},
86+
},
87+
{
88+
Name: gems.Dependency,
89+
Metadata: buildplan.Metadata{"launch": true},
90+
},
8391
},
84-
gems.Dependency: buildplan.Dependency{
85-
Metadata: buildplan.Metadata{"launch": true},
92+
Provides: []buildplan.Provided{
93+
{bundler.Dependency},
94+
{gems.Dependency},
8695
},
8796
}))
8897
})
@@ -118,17 +127,26 @@ BUNDLED WITH
118127
code, err := runDetect(factory.Detect)
119128
Expect(err).NotTo(HaveOccurred())
120129
Expect(code).To(Equal(detect.PassStatusCode))
121-
Expect(factory.Output).To(Equal(buildplan.BuildPlan{
122-
ruby.Dependency: buildplan.Dependency{
123-
Version: "'~> 3.2'",
124-
Metadata: buildplan.Metadata{"build": true, "launch": true},
125-
},
126-
bundler.Dependency: buildplan.Dependency{
127-
Version: "2.0.1",
128-
Metadata: buildplan.Metadata{"build": true, "launch": true},
130+
Expect(factory.Plans.Plan).To(Equal(buildplan.Plan{
131+
Requires: []buildplan.Required{
132+
{
133+
Name: ruby.Dependency,
134+
Version: "'~> 3.2'",
135+
Metadata: buildplan.Metadata{"build": true, "launch": true},
136+
},
137+
{
138+
Name: bundler.Dependency,
139+
Version: "2.0.1",
140+
Metadata: buildplan.Metadata{"build": true, "launch": true},
141+
},
142+
{
143+
Name: gems.Dependency,
144+
Metadata: buildplan.Metadata{"launch": true},
145+
},
129146
},
130-
gems.Dependency: buildplan.Dependency{
131-
Metadata: buildplan.Metadata{"launch": true},
147+
Provides: []buildplan.Provided{
148+
{bundler.Dependency},
149+
{gems.Dependency},
132150
},
133151
}))
134152
})

gems/gems.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ type Contributor struct {
3737
}
3838

3939
func NewContributor(context build.Build, pkgManager PackageManager) (Contributor, bool, error) {
40-
plan, shouldUseBundler := context.BuildPlan[Dependency]
41-
if !shouldUseBundler {
42-
return Contributor{}, false, nil
40+
plan, shouldUseBundler, err := context.Plans.GetShallowMerged(Dependency)
41+
if err != nil || !shouldUseBundler {
42+
return Contributor{}, false, err
4343
}
4444

4545
gemFile := filepath.Join(context.Application.Root, "Gemfile")
@@ -64,13 +64,8 @@ func NewContributor(context build.Build, pkgManager PackageManager) (Contributor
6464
Metadata: Metadata{hex.EncodeToString(hash[:])},
6565
}
6666

67-
if _, ok := plan.Metadata["build"]; ok {
68-
contributor.buildContribution = true
69-
}
70-
71-
if _, ok := plan.Metadata["launch"]; ok {
72-
contributor.launchContribution = true
73-
}
67+
contributor.buildContribution, _ = plan.Metadata["build"].(bool)
68+
contributor.launchContribution, _ = plan.Metadata["launch"].(bool)
7469

7570
return contributor, true, nil
7671
}

gems/gems_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package gems_test
22

33
import (
4+
"github.com/cloudfoundry/libcfbuildpack/buildpackplan"
45
"path/filepath"
56
"testing"
67

7-
"github.com/buildpack/libbuildpack/buildplan"
88
"github.com/cloudfoundry/bundler-cnb/gems"
99
"github.com/cloudfoundry/libcfbuildpack/test"
1010
"github.com/golang/mock/gomock"
@@ -41,7 +41,9 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
4141

4242
when("there is no Gemfile.lock", func() {
4343
it("fails", func() {
44-
factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{})
44+
factory.AddPlan(buildpackplan.Plan{
45+
Name: gems.Dependency,
46+
})
4547

4648
_, _, err := gems.NewContributor(factory.Build, mockPkgManager)
4749
Expect(err).To(HaveOccurred())
@@ -58,7 +60,9 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
5860
})
5961

6062
it("returns true if a build plan exists", func() {
61-
factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{})
63+
factory.AddPlan(buildpackplan.Plan{
64+
Name: gems.Dependency,
65+
})
6266

6367
_, willContribute, err := gems.NewContributor(factory.Build, mockPkgManager)
6468
Expect(err).NotTo(HaveOccurred())
@@ -72,7 +76,9 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
7276
})
7377

7478
it("uses Gemfile for identity", func() {
75-
factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{})
79+
factory.AddPlan(buildpackplan.Plan{
80+
Name: gems.Dependency,
81+
})
7682

7783
contributor, _, _ := gems.NewContributor(factory.Build, mockPkgManager)
7884
name, version := contributor.Metadata.Identity()
@@ -92,7 +98,7 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
9298
// })
9399
//
94100
// it("contributes gems to the cache layer when included in the build plan", func() {
95-
// factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{
101+
// factory.AddPlan(gems.Dependency, buildplan.Dependency{
96102
// Metadata: buildplan.Metadata{"build": true},
97103
// })
98104
//
@@ -110,7 +116,7 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
110116
// })
111117
//
112118
// it("contributes gems to the launch layer when included in the build plan", func() {
113-
// factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{
119+
// factory.AddPlan(gems.Dependency, buildplan.Dependency{
114120
// Metadata: buildplan.Metadata{"launch": true},
115121
// })
116122
//
@@ -133,7 +139,7 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
133139
//when("the app is not vendored", func() {
134140
//
135141
// it("contributes gems to the cache layer when included in the build plan", func() {
136-
// factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{
142+
// factory.AddPlan(gems.Dependency, buildplan.Dependency{
137143
// Metadata: buildplan.Metadata{"build": true},
138144
// })
139145
//
@@ -181,7 +187,7 @@ func testGems(t *testing.T, when spec.G, it spec.S) {
181187
// })
182188
//
183189
// it("contributes gems to the launch layer when included in the build plan", func() {
184-
// factory.AddBuildPlan(gems.Dependency, buildplan.Dependency{
190+
// factory.AddPlan(gems.Dependency, buildplan.Dependency{
185191
// Metadata: buildplan.Metadata{"launch": true},
186192
// })
187193
//

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.12
44

55
require (
66
github.com/buildpack/libbuildpack v1.21.0
7-
github.com/cloudfoundry/libcfbuildpack v1.82.1-0.20190815154108-ebdea9feb73d
7+
github.com/cloudfoundry/libcfbuildpack v1.83.0
88
github.com/golang/mock v1.3.1
99
github.com/onsi/gomega v1.5.0
1010
github.com/sclevine/spec v1.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITg
44
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
55
github.com/buildpack/libbuildpack v1.21.0 h1:94d0/8Xv8Pp2dwFHSKNrFyXYHM01IHpuRE0N0ezWrr4=
66
github.com/buildpack/libbuildpack v1.21.0/go.mod h1:dEDd9Dbp681Gcb39omBAZdsuHZ5YFMgurKGkgxEVzVo=
7-
github.com/cloudfoundry/libcfbuildpack v1.82.1-0.20190815154108-ebdea9feb73d h1:YdbNg8BGGG/xwEYISxDbG9k+yFkP0FV+rAr5eZbrrOM=
8-
github.com/cloudfoundry/libcfbuildpack v1.82.1-0.20190815154108-ebdea9feb73d/go.mod h1:c3ag+OHs0rnwh7C7kMXw3xsGRVLDvm9LfdoRR5tAnko=
7+
github.com/cloudfoundry/libcfbuildpack v1.83.0 h1:rlr5jQcyAIOF2s29HFp2ooS1d8fAfqWt/UwOWsUncqY=
8+
github.com/cloudfoundry/libcfbuildpack v1.83.0/go.mod h1:c3ag+OHs0rnwh7C7kMXw3xsGRVLDvm9LfdoRR5tAnko=
99
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
1010
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
1111
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ github.com/buildpack/libbuildpack/buildpackplan
1515
github.com/buildpack/libbuildpack/platform
1616
github.com/buildpack/libbuildpack/services
1717
github.com/buildpack/libbuildpack/stack
18-
# github.com/cloudfoundry/libcfbuildpack v1.82.1-0.20190815154108-ebdea9feb73d
18+
# github.com/cloudfoundry/libcfbuildpack v1.83.0
1919
github.com/cloudfoundry/libcfbuildpack/build
2020
github.com/cloudfoundry/libcfbuildpack/detect
2121
github.com/cloudfoundry/libcfbuildpack/helper

0 commit comments

Comments
 (0)