-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.go
116 lines (94 loc) · 3.77 KB
/
test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"os"
"github.com/dgruber/drmaa2interface"
"github.com/dgruber/wfl"
"github.com/dgruber/wfl/pkg/context/docker"
)
// Compiles all test applications
// ------------------------------
//
// - with local go compiler
// - inside a Docker container (golang:latest needs to be pulled before)
// works on darwin / linux
var exitCode int
func createProcBuild() (map[string]string, drmaa2interface.JobTemplate, *wfl.Job) {
testApps := map[string]string{
"simple": "../examples/simple/simple.go",
"touchy": "../examples/touchy/touchy.go",
"cloudfoundry": "../examples/cloudfoundry/cloudfoundry.go",
"docker": "../examples/docker/docker.go",
"template": "../examples/template/template.go",
"parallel": "../examples/parallel/parallel.go",
"notifier": "../examples/notifier/notifier.go",
"shell": "../examples/shell/shell.go",
"builderPattern": "../examples/builderPattern/builderPattern.go",
"singularity": "../examples/singularity/singularity.go",
}
jtemplate := drmaa2interface.JobTemplate{
RemoteCommand: "go",
Args: []string{"build"},
OutputPath: "/dev/stdout",
ErrorPath: "/dev/stderr",
}
job := wfl.NewJob(wfl.NewWorkflow(wfl.NewProcessContext()))
return testApps, jtemplate, job
}
func createDockerBuild(image string) (map[string]string, drmaa2interface.JobTemplate, *wfl.Job) {
testApps := map[string]string{
"simple": "/go/src/github.com/dgruber/wfl/examples/simple/simple.go",
"touchy": "/go/src/github.com/dgruber/wfl/examples/touchy/touchy.go",
"cloudfoundry": "/go/src/github.com/dgruber/wfl/examples/cloudfoundry/cloudfoundry.go",
"docker": "/go/src/github.com/dgruber/wfl/examples/docker/docker.go",
"template": "/go/src/github.com/dgruber/wfl/examples/template/template.go",
"parallel": "/go/src/github.com/dgruber/wfl/examples/parallel/parallel.go",
"shell": "/go/src/github.com/dgruber/wfl/examples/shell/shell.go",
"builderPattern": "/go/src/github.com/dgruber/wfl/examples/builderPattern/builderPattern.go",
"singularity": "/go/src/github.com/dgruber/wfl/examples/singularity/singularity.go",
}
goPath := os.Getenv("GOPATH")
jtemplate := drmaa2interface.JobTemplate{
RemoteCommand: "go",
Args: []string{"build"},
JobCategory: image,
StageInFiles: map[string]string{
goPath + "/src/github.com/dgruber/drmaa2interface": "/go/src/github.com/dgruber/drmaa2interface",
goPath + "/src/github.com/dgruber/wfl": "/go/src/github.com/dgruber/wfl"},
}
ctx := docker.NewDockerContextByCfg(docker.Config{DefaultDockerImage: image})
if ctx.HasError() {
fmt.Printf("Docker context not supported: %s\n", ctx.Error())
testApps = nil
}
wf := wfl.NewWorkflow(ctx)
if wf.HasError() {
fmt.Printf("Docker workflow not supported: %s\n", ctx.Error())
testApps = nil
}
job := wfl.NewJob(wf)
return testApps, jtemplate, job
}
func executeWorkflow(testApps map[string]string, jtemplate drmaa2interface.JobTemplate, job *wfl.Job) {
orignalArgs := jtemplate.Args
for app, path := range testApps {
jtemplate.Args = append(orignalArgs, path)
job.RunT(jtemplate).Do(func(j drmaa2interface.Job) {
fmt.Printf("Building %s (%s)\n", app, j.GetID())
}).OnSuccess(func(j drmaa2interface.Job) {
fmt.Printf("%s build successfully\n", app)
}).OnFailure(func(j drmaa2interface.Job) {
fmt.Printf("failed building %s\n", app)
exitCode = 1
}).OnError(func(err error) {
fmt.Printf("error: %s\n", err)
})
}
}
func main() {
fmt.Println("Building examples in local processes using local go compiler")
executeWorkflow(createProcBuild())
fmt.Println("Building examples in golang:latest Docker containers")
executeWorkflow(createDockerBuild("golang:latest"))
os.Exit(exitCode)
}