Skip to content

[release-v1.16] Fix non-containerized build/run with external deps #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release-v1.16
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pkg/functions/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func runGo(ctx context.Context, job *Job) (err error) {
fmt.Printf("cd %v && go build -o f.bin\n", job.Dir())
}

// Build
args := []string{"build", "-o", "f.bin"}
args := []string{"mod", "tidy"}
if job.verbose {
args = append(args, "-v")
}
Expand All @@ -124,6 +123,20 @@ func runGo(ctx context.Context, job *Job) (err error) {
return
}

// Build
args = []string{"build", "-o", "f.bin"}
if job.verbose {
args = append(args, "-v")
}
cmd = exec.CommandContext(ctx, "go", args...)
cmd.Dir = job.Dir()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
return
}

// Run
// ---
bin := filepath.Join(job.Dir(), "f.bin")
Expand Down
12 changes: 11 additions & 1 deletion pkg/oci/go_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,18 @@ func goBuild(cfg buildJob, p v1.Platform) (binPath string, err error) {
fmt.Printf(" %v\n", filepath.Base(outpath))
}

cmd := exec.CommandContext(cfg.ctx, gobin, "mod", "tidy")
cmd.Env = envs
cmd.Dir = cfg.buildDir()
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err = cmd.Run()
if err != nil {
return "", fmt.Errorf("cannot sync deps: %w", err)
}

// Build the function
cmd := exec.CommandContext(cfg.ctx, gobin, args...)
cmd = exec.CommandContext(cfg.ctx, gobin, args...)
cmd.Env = envs
cmd.Dir = cfg.buildDir()
cmd.Stderr = os.Stderr
Expand Down
Loading