Skip to content

Commit

Permalink
feat: support external deps for host runs (#1882)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland authored Jul 25, 2023
1 parent 025c457 commit d7d3f8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions pkg/functions/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d7d3f8f

Please sign in to comment.