Skip to content

Commit b31a3a4

Browse files
authored
feat: support FUNC_GIT env in Host builder (knative#2876)
1 parent a90f07f commit b31a3a4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pkg/oci/builder.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,16 @@ func newConfigFile(job buildJob, p v1.Platform, base v1.Image, imageLayers []ima
737737
// the container. This consists of func-provided build metadata envs as well
738738
// as any environment variables provided on the function itself.
739739
func newConfigEnvs(job buildJob) []string {
740+
// TODO: long-term, the correct architecture is to not read env vars
741+
// from deep within a package, but rather to expose the setting as a
742+
// variable and leave interacting with the environment to main.
743+
// This is a shortcut used by many packages, however, so it will work for
744+
// now.
745+
gitbin := os.Getenv("FUNC_GIT") // Use if provided
746+
if gitbin == "" {
747+
gitbin = "git" // default to looking on PATH
748+
}
749+
740750
envs := []string{}
741751

742752
// FUNC_CREATED
@@ -749,14 +759,14 @@ func newConfigEnvs(job buildJob) []string {
749759
// environment FUNC_VERSION will be populated. Otherwise it will exist
750760
// (to indicate this logic was executed) but have an empty value.
751761
if job.verbose {
752-
fmt.Fprintf(os.Stderr, "cd %v && export FUNC_VERSION=$(git describe --tags)\n", job.function.Root)
762+
fmt.Fprintf(os.Stderr, "cd %v && export FUNC_VERSION=$(%v describe --tags)\n", job.function.Root, gitbin)
753763
}
754-
cmd := exec.CommandContext(job.ctx, "git", "describe", "--tags")
764+
cmd := exec.CommandContext(job.ctx, gitbin, "describe", "--tags")
755765
cmd.Dir = job.function.Root
756766
output, err := cmd.Output()
757767
if err != nil {
758768
if job.verbose {
759-
fmt.Fprintf(os.Stderr, "unable to determine function version. %v\n", err)
769+
fmt.Fprintf(os.Stderr, "WARN: unable to determine function version. %v\n", err)
760770
}
761771
envs = append(envs, "FUNC_VERSION=")
762772
} else {

0 commit comments

Comments
 (0)