Skip to content

Commit ec66c1a

Browse files
authored
feat: support FUNC_GO env in Host builder (knative#2877)
1 parent 243059b commit ec66c1a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/functions/runner.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ func getRunFunc(ctx context.Context, job *Job) (runFn func() error, err error) {
113113
}
114114

115115
func runGo(ctx context.Context, job *Job) (err error) {
116+
// TODO: long-term, the correct architecture is to not read env vars
117+
// from deep within a package, but rather to expose the setting as a
118+
// variable and leave interacting with the environment to main.
119+
// This is a shortcut used by many packages, however, so it will work for
120+
// now.
121+
gobin := os.Getenv("FUNC_GO") // Use if provided
122+
if gobin == "" {
123+
gobin = "go" // default to looking on PATH
124+
}
125+
116126
// BUILD
117127
// -----
118128
// TODO: extract the build command code from the OCI Container Builder
@@ -125,7 +135,7 @@ func runGo(ctx context.Context, job *Job) (err error) {
125135
if job.verbose {
126136
args = append(args, "-v")
127137
}
128-
cmd := exec.CommandContext(ctx, "go", args...)
138+
cmd := exec.CommandContext(ctx, gobin, args...)
129139
cmd.Dir = job.Dir()
130140
cmd.Stdout = os.Stdout
131141
cmd.Stderr = os.Stderr
@@ -139,7 +149,8 @@ func runGo(ctx context.Context, job *Job) (err error) {
139149
if job.verbose {
140150
args = append(args, "-v")
141151
}
142-
cmd = exec.CommandContext(ctx, "go", args...)
152+
153+
cmd = exec.CommandContext(ctx, gobin, args...)
143154
cmd.Dir = job.Dir()
144155
cmd.Stdout = os.Stdout
145156
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)