Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
Buildpack API 0.5 (#100)
Browse files Browse the repository at this point in the history
Signed-off-by: Emily Casey <ecasey@vmware.com>
  • Loading branch information
ekcasey authored Feb 4, 2021
1 parent 93bd318 commit 3d4c961
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

api = "0.4"
api = "0.5"

[buildpack]
id = "projectriff/command-function"
Expand Down
3 changes: 2 additions & 1 deletion command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
return libcnb.BuildResult{}, fmt.Errorf("unable to find dependency\n%w", err)
}

i := NewInvoker(dep, dc, result.Plan)
i, be := NewInvoker(dep, dc)
i.Logger = b.Logger
result.Layers = append(result.Layers, i)
result.BOM.Entries = append(result.BOM.Entries, be)

f, err := NewFunction(context.Application.Path, e.Metadata["artifact"].(string))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions command/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
libcnb.Process{Type: "function", Command: "command-function-invoker"},
libcnb.Process{Type: "web", Command: "command-function-invoker"},
))

Expect(result.BOM.Entries).To(HaveLen(1))
Expect(result.BOM.Entries[0].Name).To(Equal("invoker"))
})

}
11 changes: 8 additions & 3 deletions command/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ func NewFunction(applicationPath string, artifactPath string) (Function, error)
}

return Function{
LayerContributor: libpak.NewLayerContributor(libfnbuildpack.FormatFunction("Command", artifactPath),
map[string]interface{}{"artifact": artifactPath}),
LayerContributor: libpak.NewLayerContributor(
libfnbuildpack.FormatFunction("Command", artifactPath),
map[string]interface{}{"artifact": artifactPath},
libcnb.LayerTypes{
Launch: true,
},
),
Path: file,
}, nil
}
Expand All @@ -59,7 +64,7 @@ func (f Function) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
layer.LaunchEnvironment.Default("FUNCTION_URI", f.Path)

return layer, nil
}, libpak.LaunchLayer)
})
}

func (Function) Name() string {
Expand Down
9 changes: 6 additions & 3 deletions command/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ type Invoker struct {
Logger bard.Logger
}

func NewInvoker(dependency libpak.BuildpackDependency, cache libpak.DependencyCache, plan *libcnb.BuildpackPlan) Invoker {
return Invoker{LayerContributor: libpak.NewDependencyLayerContributor(dependency, cache, plan)}
func NewInvoker(dependency libpak.BuildpackDependency, cache libpak.DependencyCache) (Invoker, libcnb.BOMEntry) {
contributor, entry := libpak.NewDependencyLayer(dependency, cache, libcnb.LayerTypes{
Launch: true,
})
return Invoker{LayerContributor: contributor}, entry
}

func (i Invoker) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
Expand All @@ -52,7 +55,7 @@ func (i Invoker) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
}

return layer, nil
}, libpak.LaunchLayer)
})
}

func (i Invoker) Name() string {
Expand Down
2 changes: 1 addition & 1 deletion command/invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func testInvoker(t *testing.T, context spec.G, it spec.S) {
}
dc := libpak.DependencyCache{CachePath: "testdata"}

i := command.NewInvoker(dep, dc, &libcnb.BuildpackPlan{})
i, _ := command.NewInvoker(dep, dc)
layer, err := ctx.Layers.Layer("test-layer")
Expect(err).NotTo(HaveOccurred())

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/projectriff/command-function-buildpack
go 1.15

require (
github.com/buildpacks/libcnb v1.18.1
github.com/buildpacks/libcnb v1.19.0
github.com/onsi/gomega v1.10.5
github.com/paketo-buildpacks/libpak v1.50.1
github.com/paketo-buildpacks/libpak v1.51.0
github.com/projectriff/libfnbuildpack v0.10.0
github.com/sclevine/spec v1.4.0
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030I
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/buildpacks/libcnb v1.18.0 h1:Q7I+HjQ1Cq02/AqhTOrzecuNESip9xE2axckxnymYLQ=
github.com/buildpacks/libcnb v1.18.0/go.mod h1:yzAQd//jyUXVx6Z/F0cKk/hrl49QZq1OE/hP5+/ZPuQ=
github.com/buildpacks/libcnb v1.18.1 h1:NcAqtyLmSkpcgIOl83GOHY5Mk2ltBFiAI8mmAvavvEs=
github.com/buildpacks/libcnb v1.18.1/go.mod h1:ozKZYold67tlck+1cobg11YhGmJqkQr8bMAH5gSvEvw=
github.com/buildpacks/libcnb v1.19.0 h1:7Frn3qErlVmQydk95YXmHtpmf5bZ1l7h4rK/C+SKAmY=
github.com/buildpacks/libcnb v1.19.0/go.mod h1:slnOsywO4mNdkShkwX1GYR+kQF1tH2F9Urfr66lWGQs=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -53,8 +53,8 @@ github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/paketo-buildpacks/libpak v1.49.0 h1:Yf3wt1RBb5Psjmc1X7joMal/tL15kSl8lz07Rfh48m4=
github.com/paketo-buildpacks/libpak v1.49.0/go.mod h1:8vMe0mZNZj1vqngvtH6KCrs98mL+KW9mTymOb5PE6pw=
github.com/paketo-buildpacks/libpak v1.50.1 h1:FumhbCg/sY3xzCyTj7je+0c4aQsVBU9T5ZJIBCexu9M=
github.com/paketo-buildpacks/libpak v1.50.1/go.mod h1:8EpJg+Lju6Vqb21ot4FXxTJbX8h6p0+xRWPF3uu5jPo=
github.com/paketo-buildpacks/libpak v1.51.0 h1:l9qhxIAn0K4KkcrScR4cnu8sNk5h+j9MynX6bbcCwHY=
github.com/paketo-buildpacks/libpak v1.51.0/go.mod h1:HPC3yyLkRW1P4ObNt3fxpFxldFrS1J0AkxpoFkqyB/Y=
github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM=
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit 3d4c961

Please sign in to comment.