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.
feat: Add configuration for Java buildpack
The detect now checks for func.yaml OR they explicitly defined an environment variable for the function class or the default function name. Signed-off-by: Andrew Su <[email protected]>
- Loading branch information
Showing
22 changed files
with
191 additions
and
73 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
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
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,81 @@ | ||
// Copyright 2021-2022 VMware, Inc. | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
package java | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/buildpacks/libcnb" | ||
"github.com/paketo-buildpacks/libpak" | ||
"github.com/paketo-buildpacks/libpak/bard" | ||
knfn "knative.dev/kn-plugin-func" | ||
) | ||
|
||
type FuncYamlEnvs struct { | ||
LayerContributor libpak.LayerContributor | ||
Logger bard.Logger | ||
|
||
Envs map[string]string | ||
} | ||
|
||
func NewFuncYamlEnvs(applicationPath string) FuncYamlEnvs { | ||
envs := getFuncYamlEnvs(applicationPath) | ||
return FuncYamlEnvs{ | ||
LayerContributor: libpak.NewLayerContributor( | ||
"func-yaml-envs", | ||
envs, | ||
libcnb.LayerTypes{ | ||
Launch: true, | ||
}, | ||
), | ||
Envs: envs, | ||
} | ||
} | ||
|
||
func (f FuncYamlEnvs) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { | ||
f.LayerContributor.Logger = f.Logger | ||
return f.LayerContributor.Contribute(layer, func() (libcnb.Layer, error) { | ||
for k, v := range f.Envs { | ||
layer.LaunchEnvironment.Default(k, v) | ||
} | ||
return layer, nil | ||
}) | ||
} | ||
|
||
func (f FuncYamlEnvs) Name() string { | ||
return f.LayerContributor.Name | ||
} | ||
|
||
func getFuncYamlEnvs(applicationPath string) map[string]string { | ||
envs := map[string]string{} | ||
|
||
configFile := filepath.Join(applicationPath, knfn.ConfigFile) | ||
_, err := os.Stat(configFile) | ||
if err != nil { | ||
return envs | ||
} | ||
|
||
f, err := knfn.NewFunction(applicationPath) | ||
if err != nil { | ||
return envs | ||
} | ||
|
||
return envsToMap(f.Envs) | ||
} | ||
|
||
func envsToMap(envs knfn.Envs) map[string]string { | ||
result := map[string]string{} | ||
|
||
for _, e := range envs { | ||
key := *e.Name | ||
val := "" | ||
if e.Value != nil { | ||
val = *e.Value | ||
} | ||
result[key] = val | ||
} | ||
|
||
return result | ||
} |
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
spring.cloud.function.location:/workspace | ||
spring.cloud.function.location:/workspace | ||
spring.cloud.function.scan.enabled:false |
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
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# request-response | ||
|
||
This is a sample function for how to create and send HTTP requests via our Java HTTP function. | ||
This is a sample function for how to create and send HTTP requests via our Java HTTP function. | ||
|
||
# Building | ||
|
||
To build this sample, use the latest buildpack and build with `--env BP_FUNCTION=com.vmware.functions.Handler` set on the `pack` cli command. |
Binary file removed
BIN
-1.6 KB
samples/java/http/request-response-gradle/target/classes/com/vmware/functions/Handler.class
Binary file not shown.
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# request-response | ||
|
||
This is a sample function for how to create and send HTTP requests via our Java HTTP function. | ||
This is a sample function for how to create and send HTTP requests via our Java HTTP function. | ||
|
||
# Building | ||
|
||
To build this sample, use the latest buildpack and build with `--env BP_FUNCTION=com.vmware.functions.Handler` set on the `pack` cli command. |
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
Binary file removed
BIN
-1.6 KB
samples/java/http/request-response-maven/target/classes/com/vmware/functions/Handler.class
Binary file not shown.
Oops, something went wrong.