Skip to content

Commit 1766e6f

Browse files
matejvasekopenshift-cherrypick-robot
authored andcommitted
Fix non-containerized build/run /w external deps
It's necessary to call "go mod tidy" on scaffolded code. Signed-off-by: Matej Vašek <mvasek@redhat.com>
1 parent cc9882e commit 1766e6f

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/containerize_go.go

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

68+
cmd := exec.CommandContext(cfg.ctx, gobin, "mod", "tidy")
69+
cmd.Env = envs
70+
cmd.Dir = cfg.buildDir()
71+
cmd.Stderr = os.Stderr
72+
cmd.Stdout = os.Stdout
73+
err = cmd.Run()
74+
if err != nil {
75+
return "", fmt.Errorf("cannot sync deps: %w", err)
76+
}
77+
6878
// Build the function
69-
cmd := exec.CommandContext(cfg.ctx, gobin, args...)
79+
cmd = exec.CommandContext(cfg.ctx, gobin, args...)
7080
cmd.Env = envs
7181
cmd.Dir = cfg.buildDir()
7282
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)