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 name or package scan path. Signed-off-by: Andrew Su <[email protected]>
- Loading branch information
Showing
6 changed files
with
172 additions
and
58 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