-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathABTaskFile
383 lines (325 loc) · 12.7 KB
/
ABTaskFile
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: build_tasks
description: Choria Build Tasks
commands:
- name: dependencies
type: parent
description: Manage dependencies
aliases: [d]
commands:
- name: update
description: Update dependencies
type: exec
aliases: [up]
dir: "{{ AppDir }}"
flags:
- name: verbose
description: Log verbosely
short: v
bool: true
- name: proxy
description: Enable using go proxy
bool: true
default: "true"
script: |
. "{{ BashHelperPath }}"
ab_announce Updating all dependencies
echo
{{ if eq .Flags.proxy false }}
export GOPROXY=direct
ab_say Disabling go mod proxy
{{ end }}
go get -u -n -a -t {{- if .Flags.verbose }} -d -x {{ end }} ./...
ab_say Running go mod tidy
go mod tidy
- name: generate
type: parent
aliases: [gen]
description: Performs 'go generate' tasks
commands:
- name: all
description: Generates all files
type: exec
dir: "{{ AppDir }}"
command: go generate
- name: plugins
description: Generate plugin files
type: exec
dir: "{{ AppDir }}"
flags:
- name: clean
description: Removes existing plugin stubs
bool: true
script: |
. "{{ BashHelperPath }}"
{{ if .Flags.clean }}
ab_announce Deleting existing plugin stubs
rm -f plugin_*_*.go
{{ end }}
go generate -run plugin
- name: config
description: Generate configuration related files
type: exec
dir: "{{ AppDir }}"
command: go generate -run config
- name: clients
description: Generate rpc clients related files
type: exec
dir: "{{ AppDir }}"
command: go generate -run client
- name: imocks
description: Generate inter/imocks related files
type: exec
dir: "{{ AppDir }}"
script: |
set -e
. "{{ BashHelperPath }}"
ab_say "Generating imocks"
go generate -run imocks
ab_say "Generating broker mocks"
cd ./broker/network
mockgen -write_generate_directive -source network.go -destination network_mock_test.go -package network
cd -
ab_say "Generating config mocks"
cd ./config
mockgen -write_generate_directive -source mutators.go -package config -destination mutator_mock_test.go
cd -
ab_say "Generating puppetsec mocks"
cd ./providers/security/puppetsec
mockgen -write_generate_directive -source puppet_security.go -package puppetsec -destination resolver_mock_test.go
cd -
ab_say "Generating discovery client mocks"
cd ./providers/discovery/broadcast
mockgen -write_generate_directive -source broadcast.go -package broadcast -destination choria_client_mock_test.go
cd -
ab_say "Generating mcorpc mocks"
cd ./providers/agent/mcorpc
mockgen -write_generate_directive -package mcorpc -destination server_info_source_mock_test.go github.com/choria-io/go-choria/server/agents ServerInfoSource
cd -
ab_say "Generating external rpc provider mocks"
cd ./providers/agent/mcorpc/external
mockgen -write_generate_directive -destination server_info_source_mock_test.go -package external github.com/choria-io/go-choria/server/agents ServerInfoSource
cd -
ab_say "Generating rpc client mocks"
cd ./providers/agent/mcorpc/client
mockgen -write_generate_directive -destination choria_client_mock_test.go -source client.go -package client
cd -
ab_say "Generating ruby rpc provider mocks"
cd ./providers/agent/mcorpc/ruby
mockgen -write_generate_directive -destination agentmanager_mock_test.go -package ruby github.com/choria-io/go-choria/server AgentManager
cd -
ab_say "Generating proftarget mocks"
cd ./providers/provtarget
mockgen -write_generate_directive -package provtarget -destination target_resolver_mock_test.go -source provtarget.go
cd -
ab_say "Generating message mocks"
cd ./message
mockgen -write_generate_directive -package message -destination protocol_mock_test.go -source ../protocol/protocol.go
cd -
ab_say "Generating server discovery mocks"
cd ./server/discovery
mockgen -write_generate_directive -package discovery -destination server_info_mock_test.go -source discovery.go
cd -
ab_say "Generating server mocks"
cd ./server
mockgen -write_generate_directive -package server -destination agentmanager_mock_test.go -source agents/agents.go
cd -
ab_say "Generating protocol mocks"
cd ./protocol
mockgen -write_generate_directive -package protocol -destination server_info_mock_test.go -source filter.go
mockgen -write_generate_directive -package protocol -destination protocol_mock_test.go -source protocol.go
cd -
ab_say "Generating autonomous agent mocks"
cd ./aagent/machine
mockgen -write_generate_directive -package machine -destination notifications_mock_test.go -source notifications.go
mockgen -write_generate_directive -package machine -destination machine_mock_test.go -source machine.go
cd -
ab_say "Generating KV Watcher Mocks"
mockgen -write_generate_directive -package kvwatcher -destination aagent/watchers/kvwatcher/kv_mock_test.go github.com/nats-io/nats.go KeyValue,KeyValueEntry
ab_say "Generating Watchers Mocks"
cd ./aagent/watchers
mockgen -write_generate_directive -package watchers -destination machine_mock_test.go github.com/choria-io/go-choria/aagent/watchers Machine
cd -
- name: test
type: parent
aliases: [t]
description: Perform various tests
commands:
- name: unit
type: exec
description: Run ginkgo unit tests
aliases: [u]
arguments:
- name: dir
description: Directory to test
default: .
flags:
- name: update
description: Updates the ginkgo runtime
bool: true
script: |
set -e
. "{{ BashHelperPath }}"
{{ if .Flags.update }}
ab_say Updating ginkgo binary
go install github.com/onsi/ginkgo/v2/ginkgo
{{ end }}
ginkgo -r --skip Integration {{ .Arguments.dir | escape }}
- name: integration
type: exec
dir: "{{ AppDir }}"
aliases: [i]
description: Run ginkgo integration tests
command: ginkgo -r integration
- name: lint
type: exec
dir: "{{ AppDir }}"
flags:
- name: vet
description: Perform go vet
bool: true
default: true
- name: staticcheck
description: Perform staticcheck
bool: true
default: true
- name: update
description: Updates lint dependencies
bool: true
script: |
set -e
. "{{ BashHelperPath }}"
{{ if .Flags.update }}
ab_say Updating linting tools
go install github.com/client9/misspell/cmd/misspell@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
{{ else }}
echo ">>> Run with --update to install required commands"
echo
{{ end }}
ab_say Formatting source files
go fmt ./...
ab_say Tidying go mod
go mod tidy
ab_say Checking spelling
find . -type f -name "*.go" | xargs misspell -error -locale US -i flavour
find docs/content -type f -name "*.md" | xargs misspell -error -locale US
{{ if .Flags.vet }}
ab_say Performing go vet
go vet ./...
{{ end }}
{{ if .Flags.staticcheck }}
ab_say Running staticcheck
staticcheck ./...
{{ end }}
- name: docs
type: parent
description: Documentation related commands
commands:
- name: serve
description: Serves documentation locally
type: exec
dir: "{{ AppDir }}"
flags:
- name: port
description: The port to listen on
default: "8081"
command: hugo serve -p {{ .Flags.port }} -s docs
- name: build
type: parent
aliases: [b]
description: Code build steps
commands:
- name: binary
description: Build a basic test binary
type: exec
dir: "{{ AppDir }}"
aliases: [bin]
banner: |
>>>
>>> Building 'go-choria' locally
>>>
>>> Target: {{ if .Flags.target }}{{ .Flags.target }}{{else}}host{{end}}
>>> provisioning.jwt: {{ .Flags.provisioning }}
>>> Default Collective: {{.Flags.collective}}
>>>
flags:
- name: target
description: Target platform to build for
enum: ["linux/amd64", "linux/arm64"]
short: T
- name: provisioning
description: Path to the default provisioning.jwt
default: /etc/choria/provisioning.jwt
- name: collective
description: Sets the default collective
default: mcollective
- name: verbose
description: Logs packages being build
bool: true
short: v
script: |
set -e
. "{{ BashHelperPath }}"
{{ if eq .Flags.target "linux/amd64" }}
export GOOS=linux
export GOARCH=amd64
{{ else if eq .Flags.target "linux/arm64" }}
export GOOS=linux
export GOARCH=arm64
{{ end }}
{{ if .Flags.verbose }}
ab_say Packages being build
{{ end }}
go build \
{{ if .Flags.verbose }}-v{{ end }} \
-ldflags="-s -w \
-X 'github.com/choria-io/go-choria/build.Version=0.98.0.$(date +%s)' \
-X 'github.com/choria-io/go-choria/build.DefaultCollectives={{.Flags.collective}}' \
{{ if .Flags.provisioning }}-X 'github.com/choria-io/go-choria/build.ProvisionJWTFile={{ .Flags.provisioning }}'{{ end }} \
" -o go-choria
ab_say Build completed
echo
ls -l go-choria
echo
file go-choria
echo
- name: release-docker
description: Builds release docker container
type: exec
dir: "{{ AppDir }}"
aliases: [rd]
flags:
- name: repo
description: YUM Repository to use
default: https://yum.eu.choria.io/release/el/release.repo
- name: push
description: Push the built images
default: false
bool: true
script: |
set -e
. "{{ BashHelperPath }}"
ab_announce Building release docker container using {{ .Flags.repo }}
TAG=$(git tag --points-at HEAD|sed -e s/^v//)
if [ -z "${TAG}" ]
then
ab_panic HEAD is not a tag
fi
docker build \
--pull \
--no-cache \
--build-arg REPO={{ .Flags.repo | escape }} \
--tag "choria/choria:${TAG}" \
--tag "choria/choria:latest" \
--tag "registry.choria.io/choria/choria:${TAG}" \
--tag "registry.choria.io/choria/choria:latest" \
.
{{ if .Flags.push }}
ab_say Pushing built containers
docker push "choria/choria:${TAG}"
docker push "choria/choria:latest"
docker push "registry.choria.io/choria/choria:${TAG}"
docker push "registry.choria.io/choria/choria:latest"
{{ else }}
ab_say Skipping container push
{{ end }}