mirror of https://github.com/knative/func.git
feat: support FUNC_GIT env in Host builder (#2876)
This commit is contained in:
parent
a90f07fdfb
commit
b31a3a4ad3
|
@ -737,6 +737,16 @@ func newConfigFile(job buildJob, p v1.Platform, base v1.Image, imageLayers []ima
|
|||
// the container. This consists of func-provided build metadata envs as well
|
||||
// as any environment variables provided on the function itself.
|
||||
func newConfigEnvs(job buildJob) []string {
|
||||
// TODO: long-term, the correct architecture is to not read env vars
|
||||
// from deep within a package, but rather to expose the setting as a
|
||||
// variable and leave interacting with the environment to main.
|
||||
// This is a shortcut used by many packages, however, so it will work for
|
||||
// now.
|
||||
gitbin := os.Getenv("FUNC_GIT") // Use if provided
|
||||
if gitbin == "" {
|
||||
gitbin = "git" // default to looking on PATH
|
||||
}
|
||||
|
||||
envs := []string{}
|
||||
|
||||
// FUNC_CREATED
|
||||
|
@ -749,14 +759,14 @@ func newConfigEnvs(job buildJob) []string {
|
|||
// environment FUNC_VERSION will be populated. Otherwise it will exist
|
||||
// (to indicate this logic was executed) but have an empty value.
|
||||
if job.verbose {
|
||||
fmt.Fprintf(os.Stderr, "cd %v && export FUNC_VERSION=$(git describe --tags)\n", job.function.Root)
|
||||
fmt.Fprintf(os.Stderr, "cd %v && export FUNC_VERSION=$(%v describe --tags)\n", job.function.Root, gitbin)
|
||||
}
|
||||
cmd := exec.CommandContext(job.ctx, "git", "describe", "--tags")
|
||||
cmd := exec.CommandContext(job.ctx, gitbin, "describe", "--tags")
|
||||
cmd.Dir = job.function.Root
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
if job.verbose {
|
||||
fmt.Fprintf(os.Stderr, "unable to determine function version. %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "WARN: unable to determine function version. %v\n", err)
|
||||
}
|
||||
envs = append(envs, "FUNC_VERSION=")
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue