This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(python, java): Extract common buildpack code
Signed-off-by: Andrew Meyer <[email protected]>
- Loading branch information
1 parent
86c3a76
commit bac7bd5
Showing
27 changed files
with
2,240 additions
and
580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
RULES.MK ?= ../../rules.mk | ||
include $(RULES.MK) | ||
|
||
path ?= . | ||
buildpacks.common.path := $(abspath $(path)) | ||
|
||
include $(buildpacks.common.path)/../rules.mk | ||
|
||
######### | ||
# Testing | ||
######### | ||
|
||
buildpacks.common.tests.sources := \ | ||
$(buildpacks.common.path)/go.mod \ | ||
$(buildpacks.common.path)/go.sum \ | ||
$(shell find '$(buildpacks.common.path)/tests' -type f -iname '*.go') \ | ||
$(buildpacks.common.path)/tests \ | ||
|
||
######### | ||
# Targets | ||
######### | ||
|
||
buildpacks.common.tests: $(buildpacks.common.tests.sources) | ||
cd $(buildpacks.common.path) && go test -v -count=1 -timeout 30s kn-fn/buildpacks/tests | ||
|
||
buildpacks.tests .PHONY: buildpacks.common.tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2021-2022 VMware, Inc. | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
package command | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
//go:generate mockgen -destination ../mock_command/runner.go . Runner | ||
type Runner interface { | ||
Run(cmd *exec.Cmd) (output string, err error) | ||
} | ||
|
||
type DefaultRunner struct{} | ||
|
||
func NewDefaultRunner() *DefaultRunner { | ||
return &DefaultRunner{} | ||
} | ||
|
||
func (dcr *DefaultRunner) Run(cmd *exec.Cmd) (output string, err error) { | ||
buff, err := cmd.CombinedOutput() | ||
return string(buff), err | ||
} |
2 changes: 1 addition & 1 deletion
2
buildpacks/java/java/func_yaml.go → buildpacks/common/config/func_yaml.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module kn-fn/buildpacks | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/paketo-buildpacks/libpak v1.61.0 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
knative.dev/kn-plugin-func v0.19.0 | ||
knative.dev/pkg v0.0.0-20210902173607-844a6bc45596 | ||
) | ||
|
||
require ( | ||
github.com/BurntSushi/toml v1.1.0 // indirect | ||
github.com/Masterminds/semver/v3 v3.1.1 // indirect | ||
github.com/Microsoft/go-winio v0.5.0 // indirect | ||
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect | ||
github.com/acomagu/bufpipe v1.0.3 // indirect | ||
github.com/buildpacks/libcnb v1.26.0 // indirect | ||
github.com/emirpasic/gods v1.12.0 // indirect | ||
github.com/go-git/gcfg v1.5.0 // indirect | ||
github.com/go-git/go-billy/v5 v5.3.1 // indirect | ||
github.com/go-git/go-git/v5 v5.4.2 // indirect | ||
github.com/gobuffalo/here v0.6.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/heroku/color v0.0.6 // indirect | ||
github.com/imdario/mergo v0.3.13 // indirect | ||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | ||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect | ||
github.com/markbates/pkger v0.17.1 // indirect | ||
github.com/mattn/go-colorable v0.1.8 // indirect | ||
github.com/mattn/go-isatty v0.0.12 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/onsi/gomega v1.20.2 // indirect | ||
github.com/sergi/go-diff v1.1.0 // indirect | ||
github.com/xanzy/ssh-agent v0.3.0 // indirect | ||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/warnings.v0 v0.1.2 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
k8s.io/apimachinery v0.20.7 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2021-2022 VMware, Inc. | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
package tests | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/paketo-buildpacks/libpak/bard" | ||
knfn "knative.dev/kn-plugin-func" | ||
) | ||
|
||
func NewLogger() bard.Logger { | ||
buf := bytes.NewBuffer(nil) | ||
return bard.NewLogger(buf) | ||
} | ||
|
||
type SetupOpts func(directory string) | ||
|
||
func SetupTestDirectory(opts ...SetupOpts) (string, func()) { | ||
dir, err := ioutil.TempDir(os.TempDir(), "python-functions-buildpack-*") | ||
if err != nil { | ||
panic(fmt.Sprintf("unable to create test directory: %v", err)) | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(dir) | ||
} | ||
|
||
cleanup := func() { | ||
if err := os.RemoveAll(dir); err != nil { | ||
log.Printf("Failed to delete temp directory %s: %v", dir, err) | ||
} | ||
|
||
} | ||
return dir, cleanup | ||
} | ||
|
||
func WithFuncYaml() SetupOpts { | ||
return func(directory string) { | ||
cfg, err := knfn.NewFunction(directory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = cfg.WriteConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func WithFuncEnvs(envs map[string]string) SetupOpts { | ||
return func(directory string) { | ||
cfg, err := knfn.NewFunction(directory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for envName, envValue := range envs { | ||
name := envName | ||
value := envValue | ||
cfg.Envs = append(cfg.Envs, knfn.Env{ | ||
Name: &name, | ||
Value: &value, | ||
}) | ||
} | ||
|
||
err = cfg.WriteConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func WithFuncScale(scale knfn.ScaleOptions) SetupOpts { | ||
return func(directory string) { | ||
cfg, err := knfn.NewFunction(directory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
cfg.Options.Scale = &scale | ||
|
||
err = cfg.WriteConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func WithFuncResourceRequests(requests knfn.ResourcesRequestsOptions) SetupOpts { | ||
return func(directory string) { | ||
cfg, err := knfn.NewFunction(directory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if cfg.Options.Resources == nil { | ||
cfg.Options.Resources = &knfn.ResourcesOptions{} | ||
} | ||
|
||
cfg.Options.Resources.Requests = &requests | ||
|
||
err = cfg.WriteConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func WithFuncResourceLimits(limits knfn.ResourcesLimitsOptions) SetupOpts { | ||
return func(directory string) { | ||
cfg, err := knfn.NewFunction(directory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if cfg.Options.Resources == nil { | ||
cfg.Options.Resources = &knfn.ResourcesOptions{} | ||
} | ||
|
||
cfg.Options.Resources.Limits = &limits | ||
|
||
err = cfg.WriteConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.