forked from netgusto/nodebook
/
stdrecipe.go
67 lines (58 loc) · 1.7 KB
/
stdrecipe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package helper
import (
"io"
"github.com/a112121788/nodebook/src/core/shared/types"
)
type cmdBuilderFunc = func(types.Notebook) []string
type envBuilderFunc = func(types.Notebook, map[string]string) map[string]string
type mountsBuilderFunc = func(types.Notebook, []types.ContainerMount) []types.ContainerMount
func StdRecipe(
key, name, language, mainfile, cmmode, dockerImage string,
dockerCmd, localCmd cmdBuilderFunc,
addEnv envBuilderFunc,
addMounts mountsBuilderFunc,
) types.Recipe {
return types.MakeRecipeReal(
key, // key
name, // name
language, // language
mainfile, // mainfile
cmmode, // cmmode
"/src/recipes/"+key, // dir
func(notebook types.Notebook, docker bool, writeStdOut, writeStdErr, writeInfo io.Writer, env map[string]string) types.ExecHandler { // exec
if env == nil {
env = map[string]string{}
}
if addEnv != nil {
env = addEnv(notebook, env)
}
mounts := []types.ContainerMount{
types.ContainerMount{
From: notebook.GetAbsdir(),
To: "/code",
Mode: "rw",
},
}
if addMounts != nil {
mounts = addMounts(notebook, mounts)
}
if docker {
return stdExecDocker(types.ContainerInfo{
Image: dockerImage,
Cmd: dockerCmd(notebook),
Cwd: "/code",
Mounts: mounts,
Env: env,
}, writeStdOut, writeStdErr, writeInfo)
}
return stdExecLocal(types.ProcessInfo{
Cmd: localCmd(notebook),
Cwd: notebook.GetAbsdir(),
Env: env,
}, writeStdOut, writeStdErr, writeInfo)
},
func(recipe types.Recipe, notebookspath, name string) error { // init
return defaultInitNotebook(recipe, notebookspath, name)
},
)
}