feat: support FUNC_GIT env in Host builder (#2876)

This commit is contained in:
Luke Kingland 2025-06-27 15:57:06 +09:00 committed by GitHub
parent a90f07fdfb
commit b31a3a4ad3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 3 deletions

View File

@ -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 // the container. This consists of func-provided build metadata envs as well
// as any environment variables provided on the function itself. // as any environment variables provided on the function itself.
func newConfigEnvs(job buildJob) []string { 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{} envs := []string{}
// FUNC_CREATED // FUNC_CREATED
@ -749,14 +759,14 @@ func newConfigEnvs(job buildJob) []string {
// environment FUNC_VERSION will be populated. Otherwise it will exist // environment FUNC_VERSION will be populated. Otherwise it will exist
// (to indicate this logic was executed) but have an empty value. // (to indicate this logic was executed) but have an empty value.
if job.verbose { 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 cmd.Dir = job.function.Root
output, err := cmd.Output() output, err := cmd.Output()
if err != nil { if err != nil {
if job.verbose { 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=") envs = append(envs, "FUNC_VERSION=")
} else { } else {