feat: support external deps for host runs (#1882)

This commit is contained in:
Luke Kingland 2023-07-26 04:31:40 +09:00 committed by GitHub
parent 025c457955
commit d7d3f8f052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -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.

View File

@ -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)