Skip to content

Commit 9a23973

Browse files
authored
Fix non-containerized build/run /w external deps (#1317)
It's necessary to call "go mod tidy" on scaffolded code. Signed-off-by: Matej Vašek <[email protected]>
1 parent 924a057 commit 9a23973

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkg/functions/runner.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ func runGo(ctx context.Context, job *Job) (err error) {
110110
fmt.Printf("cd %v && go build -o f.bin\n", job.Dir())
111111
}
112112

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

126+
// Build
127+
args = []string{"build", "-o", "f.bin"}
128+
if job.verbose {
129+
args = append(args, "-v")
130+
}
131+
cmd = exec.CommandContext(ctx, "go", args...)
132+
cmd.Dir = job.Dir()
133+
cmd.Stdout = os.Stdout
134+
cmd.Stderr = os.Stderr
135+
err = cmd.Run()
136+
if err != nil {
137+
return
138+
}
139+
127140
// Run
128141
// ---
129142
bin := filepath.Join(job.Dir(), "f.bin")

pkg/oci/go_builder.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,18 @@ func goBuild(cfg buildJob, p v1.Platform) (binPath string, err error) {
8686
fmt.Printf(" %v\n", filepath.Base(outpath))
8787
}
8888

89+
cmd := exec.CommandContext(cfg.ctx, gobin, "mod", "tidy")
90+
cmd.Env = envs
91+
cmd.Dir = cfg.buildDir()
92+
cmd.Stderr = os.Stderr
93+
cmd.Stdout = os.Stdout
94+
err = cmd.Run()
95+
if err != nil {
96+
return "", fmt.Errorf("cannot sync deps: %w", err)
97+
}
98+
8999
// Build the function
90-
cmd := exec.CommandContext(cfg.ctx, gobin, args...)
100+
cmd = exec.CommandContext(cfg.ctx, gobin, args...)
91101
cmd.Env = envs
92102
cmd.Dir = cfg.buildDir()
93103
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)