mirror of https://github.com/knative/func.git
feat: support external deps for host runs (#1882)
This commit is contained in:
parent
025c457955
commit
d7d3f8f052
|
@ -203,7 +203,7 @@ func runRun(cmd *cobra.Command, args []string, newClient ClientFactory) (err err
|
|||
|
||||
// Run
|
||||
//
|
||||
// Runs the code either via a container or the default host-based runniner.
|
||||
// Runs the code either via a container or the default host-based runner.
|
||||
// For the former, build is required and a container runtime. For the
|
||||
// latter, scaffolding is first applied and the local host must be
|
||||
// configured to build/run the language of the function.
|
||||
|
|
|
@ -102,18 +102,29 @@ func getRunFunc(ctx context.Context, job *Job) (runFn func() error, err error) {
|
|||
}
|
||||
|
||||
func runGo(ctx context.Context, job *Job) (err error) {
|
||||
// BUILD
|
||||
// -----
|
||||
// TODO: extract the build command code from the OCI Container Builder
|
||||
// and have both the runner and OCI Container Builder use the same.
|
||||
// and have both the runner and OCI Container Builder use the same here.
|
||||
if job.verbose {
|
||||
fmt.Printf("cd %v && go build -o f.bin\n", job.Dir())
|
||||
}
|
||||
|
||||
// Get the dependencies of the function
|
||||
cmd := exec.CommandContext(ctx, "go", "get", "f")
|
||||
cmd.Dir = job.Dir()
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
if err = cmd.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Build
|
||||
args := []string{"build", "-o", "f.bin"}
|
||||
if job.verbose {
|
||||
args = append(args, "-v")
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "go", args...)
|
||||
cmd = exec.CommandContext(ctx, "go", args...)
|
||||
cmd.Dir = job.Dir()
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
@ -123,6 +134,7 @@ func runGo(ctx context.Context, job *Job) (err error) {
|
|||
}
|
||||
|
||||
// Run
|
||||
// ---
|
||||
bin := filepath.Join(job.Dir(), "f.bin")
|
||||
if job.verbose {
|
||||
fmt.Printf("cd %v && PORT=%v %v\n", job.Function.Root, job.Port, bin)
|
||||
|
|
Loading…
Reference in New Issue