From b31a3a4ad34a3df326cf29027b07cf7b4150993f Mon Sep 17 00:00:00 2001 From: Luke Kingland Date: Fri, 27 Jun 2025 15:57:06 +0900 Subject: [PATCH] feat: support FUNC_GIT env in Host builder (#2876) --- pkg/oci/builder.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/oci/builder.go b/pkg/oci/builder.go index bdcca33fe..c2d0435a0 100644 --- a/pkg/oci/builder.go +++ b/pkg/oci/builder.go @@ -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 {