-
Notifications
You must be signed in to change notification settings - Fork 4
/
all.go
172 lines (137 loc) · 3.94 KB
/
all.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package probes
import (
"os"
"time"
"github.com/cirocosta/slirunner/runnable"
)
func NewLogin(target, username, password, concourseUrl string) runnable.Runnable {
var (
config = Config{
Target: target,
Username: username,
Password: password,
ConcourseUrl: concourseUrl,
}
timeout = 60 * time.Second
)
return runnable.NewWithLogging("login",
runnable.NewWithMetrics("login",
runnable.NewWithTimeout(
runnable.NewShellCommand(FormatProbe(`
fly -t {{ .Target }} login -u {{ .Username }} -p {{ .Password }} -c {{ .ConcourseUrl }}
`, config), os.Stderr),
timeout,
),
),
)
}
func NewSync(target string) runnable.Runnable {
var (
config = Config{Target: target}
timeout = 4 * time.Minute
)
return runnable.NewWithLogging("sync",
runnable.NewWithMetrics("sync",
runnable.NewWithTimeout(
runnable.NewShellCommand(FormatProbe(`
fly -t {{ .Target }} sync
`, config), os.Stderr),
timeout,
),
),
)
}
func NewCreateAndRunNewPipeline(target, prefix string) runnable.Runnable {
var (
config = Config{
Target: target,
Pipeline: prefix + "create-and-run-new-pipeline",
}
timeout = 60 * time.Second
)
return runnable.NewWithLogging("create-and-run-new-pipeline",
runnable.NewWithMetrics("create-and-run-new-pipeline",
runnable.NewWithTimeout(
runnable.NewShellCommand(FormatProbe(`
set -o errexit
set -o xtrace
fly -t {{ .Target }} destroy-pipeline -n -p {{ .Pipeline }} || true
fly -t {{ .Target }} set-pipeline -n -p {{ .Pipeline }} -c <(echo '`+pipelineContents+`')
fly -t {{ .Target }} unpause-pipeline -p {{ .Pipeline }}
wait_for_build () {
fly -t {{ .Target }} builds -j {{ .Pipeline }}/auto-triggering | \
grep -v pending | \
wc -l
}
until [ "$(wait_for_build)" -gt 0 ]; do
echo 'waiting for job to automatically trigger...'
sleep 1
done
fly -t {{ .Target }} watch -j {{ .Pipeline }}/auto-triggering
fly -t {{ .Target }} destroy-pipeline -n -p {{ .Pipeline }}
`, config), os.Stderr),
timeout,
),
),
)
}
func NewHijackFailingBuild(target, prefix string) runnable.Runnable {
var (
config = Config{
Target: target,
Pipeline: prefix + "hijack-failing-build",
}
timeout = 60 * time.Second
)
return runnable.NewWithLogging("hijack-failing-build",
runnable.NewWithMetrics("hijack-failing-build",
runnable.NewWithTimeout(
runnable.NewShellCommand(FormatProbe(`
set -o errexit
set -o xtrace
fly -t {{ .Target }} set-pipeline -n -p {{ .Pipeline }} -c <(echo '`+pipelineContents+`')
fly -t {{ .Target }} unpause-pipeline -p {{ .Pipeline }}
job_name={{ .Pipeline }}/failing
fly -t {{ .Target }} trigger-job -j "$job_name" -w || true
build=$(fly -t {{ .Target }} builds -j "$job_name" | head -1 | awk '{print $3}')
fly -t {{ .Target }} hijack -j "$job_name" -b $build echo Hello World
`, config), os.Stderr),
timeout,
),
),
)
}
func NewRunExistingPipeline(target, prefix string) runnable.Runnable {
var (
config = Config{
Target: target,
Pipeline: prefix + "run-existing-pipeline",
}
timeout = 60 * time.Second
)
return runnable.NewWithLogging("run-existing-pipeline",
runnable.NewWithMetrics("run-existing-pipeline",
runnable.NewWithTimeout(
runnable.NewShellCommand(FormatProbe(`
set -o xtrace
set -o errexit
fly -t {{ .Target }} set-pipeline -n -p {{ .Pipeline }} -c <(echo '`+pipelineContents+`')
fly -t {{ .Target }} unpause-pipeline -p {{ .Pipeline }}
fly -t {{ .Target }} trigger-job -w -j "{{ .Pipeline }}/simple-job"
`, config), os.Stderr),
timeout,
),
),
)
}
func NewAll(target, username, password, concourseUrl, prefix string) runnable.Runnable {
return runnable.NewSequentially([]runnable.Runnable{
NewLogin(target, username, password, concourseUrl),
NewSync(target),
runnable.NewConcurrently([]runnable.Runnable{
NewCreateAndRunNewPipeline(target, prefix),
NewHijackFailingBuild(target, prefix),
NewRunExistingPipeline(target, prefix),
}),
})
}