-
Notifications
You must be signed in to change notification settings - Fork 2
/
Taskfile.yml
499 lines (441 loc) · 16 KB
/
Taskfile.yml
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
version: 3
vars:
ImagePrefix: "ghcr.io/kloudlite/operator"
dockerRegistry: registry.kloudlite.io
KlControllerGen: "./bin/kl-controller-gen"
KlTemplatizer: "go run cmd/template/main.go"
tasks:
new-kind:
summary: |+
[example usage]
task new-kind Group=sample Kind=SampleKind
silent: true
preconditions:
- sh: '[ -n "{{.Group}}" ]'
msg: 'var Group must have a value'
- sh: '[ -n "{{.Kind}}" ]'
msg: 'var Kind must have a value'
cmds:
- operator-sdk create api --group {{.Group}} --version v1 --resource --controller=false --kind "{{.Kind}}"
new-webhook:
summary: |+
[example usage]
task new-webhook Group=sample Kind=SampleKind
silent: true
preconditions:
- sh: '[ -n "{{.Group}}" ]'
msg: 'var Group must have a value'
- sh: '[ -n "{{.Kind}}" ]'
msg: 'var Kind must have a value'
cmds:
# operator-sdk create webhook --group cache --version v1alpha1 --kind Memcached --defaulting --programmatic-validation
- operator-sdk create webhook --group {{.Group}} --version v1 --kind "{{.Kind}}" --defaulting --programmatic-validation --force
build:
env:
CGO_ENABLED: 0
GOOS: linux
vars:
BuiltAt:
sh: date | sed 's/\s/_/g'
preconditions:
- sh: '[ -n "{{.Out}}" ]'
msg: var Out must have a value
- sh: '[ -n "{{.CWD}}" ]'
msg: var CWD must have a value
dir: "{{.CWD}}"
cmds:
- go build -ldflags="-s -w -X github.com/kloudlite/operator/common.BuiltAt=\"{{.BuiltAt}}\"" -o {{.Out}}
setup:
dir: ./bin
cmds:
- curl -L0 https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.5.5/kustomize_v4.5.5_linux_amd64.tar.gz > kustomize.tar.gz
- tar xf kustomize.tar.gz && rm -rf kustomize.tar.gz
yaml:crds:
cmds:
# - make manifests
- |+
[ -f config/crd/bases/_.yaml ] && rm config/crd/bases/_.yaml
F={{.Filter}}
if [ -z "$F" ]; then
F="*"
fi
for file in $(ls config/crd/bases/$F.yaml)
do
cat $file
# actually, don't need it as all crds have --- at the start
# echo "---"
done
yaml:primary-crds:
cmds:
- |+
[ -f config/crd/bases/_.yaml ] && rm config/crd/bases/_.yaml
for file in $(ls config/crd/bases/crds.kloudlite.io_*.yaml); do
cat $file
done
# for file in $(ls config/crd/bases/clusters.kloudlite.io_*.yaml); do
# cat $file
# done
for file in $(ls config/crd/bases/networking.kloudlite.io_*.yaml); do
cat $file
done
# for file in $(ls config/crd/bases/distribution.kloudlite.io_*.yaml); do
# cat $file
# done
# for file in $(ls config/crd/bases/wireguard.kloudlite.io_*.yaml); do
# cat $file
# done
for file in $(ls config/crd/bases/mongodb.msvc.kloudlite.io_*.yaml); do
cat $file
done
for file in $(ls config/crd/bases/mysql.msvc.kloudlite.io_*.yaml); do
cat $file
done
for file in $(ls config/crd/bases/redis.msvc.kloudlite.io_*.yaml); do
cat $file
done
for file in $(ls config/crd/bases/postgres.msvc.kloudlite.io_*.yaml); do
cat $file
done
yaml:operator:
summary: |+
template args
- Namespace
- EnvName
- ImageTag
- ImagePullPolicy
- SvcAccountName
optional args:
- NodeSelctor
- Tolerations
need to be provided while applying this generated manifest
###
.securityContext.capabilities.drop=["ALL"] |
.securityContext.seccompProfile.type = "RuntimeDefault" |
preconditions:
- sh: '[ -n "{{.Name}}" ]'
msg: 'env Name must be set'
# - sh: '[ -n "{{.Dir}}" ]'
# msg: 'env var Dir must be set'
#
vars:
Name:
sh: ls ./operators | fzf --prompt "generate yaml for operator> "
Image: '{{ printf "%s/kloudlite/operators/{{.EnvName}}/%s:{{.ImageTag}}" .dockerRegistry .Name }}'
Namespace: '{{ printf "{{.Namespace}}" }}'
SvcAccountName: '{{ printf "{{.SvcAccountName}}" }}'
ImagePullPolicy: '{{ printf "{{.ImagePullPolicy}}" }}'
OverrideFile: "./operators/{{.Name}}/overrides.yml"
silent: true
env:
Name: "{{.Name}}"
Namespace: "{{.Namespace}}"
SvcAccountName: "{{.SvcAccountName}}"
Image: "{{.Image}}"
ImagePullPolicy: "{{.ImagePullPolicy}}"
cmds:
- |+
setArgs=""
[ -f "{{.OverrideFile}}" ] && {
setArgs=$(cat "{{.OverrideFile}}" | yq -r 'to_entries|map("--set \(.key)=###\(.value)###") | join(" ")' | sed "s/###/'/g" )
}
if [[ -z "{{.Dir}}" ]]; then
eval {{.KlTemplatizer}} < ./operators/deployment.yml.tpl $setArgs
else
outputName="{{.Dir}}/{{.Name}}.yml.tpl"
eval {{.KlTemplatizer}} < ./operators/deployment.yml.tpl $setArgs > $outputName
echo "saving to file: $outputName"
fi
# - |+
# export PATH="$PWD/bin:$PATH"
#
# kustomize build config/default | yq '
# select(.kind == "Deployment") |
# .metadata.name = "kl-{{.Name}}-operator" |
# .metadata.namespace = "{{.Namespace}}" |
# .metadata.labels."control-plane" = "{{.Name}}" |
# .spec.selector.matchLabels."control-plane" = "{{.Name}}" |
# .spec.template.metadata.labels."control-plane" = "{{.Name}}" |
# .spec.template.spec.serviceAccountName = "{{.SvcAccountName}}" |
# .spec.template.spec.containers = (
# .spec.template.spec.containers | map_values(
# if .name == "manager" then
# .image = "{{.Image}}" |
# .imagePullPolicy = "{{.ImagePullPolicy}}" |
# .resources.limits = {} |
# .resources.limits.memory = "200Mi" |
# .resources.requests.cpu = "64m" |
# .resources.requests.memory = "96Mi" |
# .securityContext.allowPrivilegeEscalation = false
# elif .name == "kube-rbac-proxy" then
# .resources.limits = {} |
# .resources.requests.cpu = "5m" |
# .resources.requests.memory = "10Mi" |
# .securityContext.allowPrivilegeEscalation = false
# else . end
# )
# )
# ' -y
#
yaml:operators:
silent: true
preconditions:
- sh: '[ -n "{{.Dir}}" ]'
msg: 'Dir must be set'
cmds:
- |+
outputDir=$(mktemp -d)
#echo "outputDir: $outputDir"
for dir in $(ls -d ./operators/*/)
do
# [ "$dir" != "msvc-neo4j" ] && task yaml:operator Name="$(basename $dir)" Dir="$outputDir"
# [ "$dir" != "msvc-neo4j" ] && task yaml:operator Name="$(basename $dir)"
task yaml:operator Name="$(basename $dir)" Dir="{{.Dir}}"
done
gobuild:operator:
preconditions:
- sh: '[ -n "{{.Name}}" ]'
msg: "var Name must have a value"
- sh: '[ -d "./operators/{{.Name}}" ]'
msg: 'directory operators/{{.Name}} must exist'
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
cmds:
- |+
pushd "./operators/{{.Name}}" 1> /dev/null
go build -o /tmp/{{.Name}} ./main.go
popd 1> /dev/null
local-build:operator:
preconditions:
- sh: '[ -d "./operators/{{.Name}}" ]'
msg: 'directory operators/{{.Name}} or cmd/{{.Name}} must exist'
- sh: '[ -n "{{.Tag}}" ]'
msg: 'var Tag must have a value'
interactive: false
vars:
DirName:
sh: ls ./operators | fzf --prompt "build operator> "
Image: "{{.ImagePrefix}}/{{.DirName}}:{{.Tag}}"
BuildInfo:
# sh: echo "built by $USER on $GOOS at $(date -Is)"
sh: date -Is
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
cmds:
- |+
pushd "./operators/{{.DirName}}" > /dev/null 2>&1
tdir=$(mktemp -d)
binpath="manager"
task build Out="$tdir/$binpath" CWD="$PWD"
# go build -ldflags="-s -w -X 'github.com/kloudlite/operator/pkg/common.BuiltAt={{.BuildInfo}}'" -o "$tdir/$binpath" .
podman buildx build -f Containerfile.local -t {{.Image}} . --build-context local-builder="$tdir" --build-arg binpath="$binpath"
podman push {{.Image}}
local-build:cmd:
preconditions:
- sh: '[ -d "./cmd/{{.Name}}" ]'
msg: 'directory cmd/{{.Name}} must exist'
- sh: '[ -n "{{.Tag}}" ]'
msg: 'var Tag must have a value'
interactive: false
vars:
DirName:
sh: ls ./cmd | fzf --prompt "build operator> "
Image: "{{.ImagePrefix}}/{{.DirName}}:{{.Tag}}"
BuildInfo:
# sh: echo "built by $USER on $GOOS at $(date -Is)"
sh: date -Is
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
cmds:
- |+
pushd "./cmd/{{.DirName}}" > /dev/null 2>&1
tdir=$(mktemp -d)
binpath="manager"
task build Out="$tdir/$binpath" CWD="$PWD"
podman buildx build -f Containerfile.local -t {{.Image}} . --build-context local-builder="$tdir" --build-arg binpath="$binpath"
# podman push {{.Image}}
build:operator:
preconditions:
- sh: '[ -n "{{.Name}}" ]'
msg: "var Name must have a value"
- sh: '[ -d "./operators/{{.Name}}" ]'
msg: 'directory operators/{{.Name}} must exist'
- sh: '[ -n "{{.EnvName}}" ]'
msg: 'var EnvName must have a value'
- sh: '[ -n "{{.Tag}}" ]'
msg: 'var Tag must have a value'
vars:
Image: "{{.dockerRegistry}}/kloudlite/operators/{{.EnvName}}/{{.Name}}:{{.Tag}}"
silent: true
cmds:
- |+
#pushd "./operators/{{.Name}}" 1> /dev/null
# docker buildx build -t {{.Image}} . --build-context project="../.." --build-arg name="{{.Name}}"
# docker push {{.Image}}
depot build -t {{.Image}} --build-arg name="{{.Name}}" -f operators/{{.Name}}/Dockerfile .
depot push {{.Image}}
popd 1> /dev/null
pre:
run: once
cmds:
- go mod tidy
- make manifests
- make generate
- |+
[ -f config/crd/bases/_.yaml ] && rm config/crd/bases/_.yaml
- kubectl apply -f config/crd/bases
new:operator:
preconditions:
- sh: test -n '{{.name}}'
msg: "var name must have a value"
- sh: test ! -d './operators/{{.name}}'
msg: 'directory ./operators/{{.name}} must not exist'
cmds:
- mkdir -p ./operators/{{.name}}
new:controller:
summary: |+
example:
task new:controller -- --api-group mongodb.msvc.kloudlite.io --debug --kind Database --kind-plural databases --package database --kind-pkg mongodbMsvcv1
{{.KLOP}} controller create --api-group crds.kloudlite.io --kind Project --kind-pkg crdsv1 --kind-plural projects --package controllers --debug
silent: true
vars:
KLOP:
sh: echo "$PWD/cmd/{{.KlControllerGen}}"
cmds:
# - eval {{.KlControllerGen}} controller create {{.CLI_ARGS}}
- go run $PWD/cmd/main.go controller create {{.CLI_ARGS}}
new:msvc-controller:
summary: |+
example:
task new:msvc-controller -- --api-group mongodb.msvc.kloudlite.io --debug --kind Database --kind-plural databases --package database --kind-pkg mongodbMsvcv1
{{.KLOP}} msvc-controller create --api-group crds.kloudlite.io --kind Project --kind-pkg crdsv1 --kind-plural projects --package controllers --debug
#
silent: true
cmds:
- eval {{.KlControllerGen}} msvc-controller create {{.CLI_ARGS}}
new:mres-controller:
summary: |+
example:
task new:msvc-controller -- --api-group mongodb.msvc.kloudlite.io --debug --kind Database --kind-plural databases --package database --kind-pkg mongodbMsvcv1
{{.KLOP}} msvc-controller create --api-group crds.kloudlite.io --kind Project --kind-pkg crdsv1 --kind-plural projects --package controllers --debug
#
silent: true
cmds:
- eval {{.KlControllerGen}} mres-controller create {{.CLI_ARGS}}
install:cmd:
cmds:
- go build -o "{{.KlControllerGen}}" ./cmd/main.go
install:templatizer:
cmds:
- go build -o "{{.KlTemplatizer}}" ./cmd/template/main.go
build:webhook-worker:
preconditions:
- sh: '[ -n "{{.EnvName}}" ]'
msg: 'var EnvName must have a value'
- sh: '[ -n "{{.Tag}}" ]'
msg: 'var Tag must have a value'
vars:
Name: webhook-worker
Image: "{{.dockerRegistry}}/kloudlite/workers/{{.EnvName}}/registry-webhook-worker:{{.Tag}}"
dir: ./webhook-worker
cmds:
- docker buildx build -t {{.Image}} . --build-context project=".." --build-arg name="{{.Name}}"
- docker push {{.Image}}
build:http-lb:
dir: ./http-lb
preconditions:
- sh: '[ -n "{{.EnvName}}" ]'
msg: 'var EnvName must have a value'
- sh: '[ -n "{{.Tag}}" ]'
msg: 'var Tag must have a value'
vars:
Image: "{{.dockerRegistry}}/kloudlite/{{.EnvName}}/lb:{{.Tag}}"
cmds:
- docker buildx build -t {{.Image}} .
- docker push {{.Image}}
run:operator:
vars:
Dir:
sh: ls | fzf
dir: "./operators/{{.Dir}}"
silent: true
interactive: true
cmds:
- |+
set -a
source .secrets/env
set +a
CGO_ENABLED=0 go build -o /tmp/{{.Dir}}
# /tmp/{{.Dir}} --dev
# dlv debug -l 127.0.0.1:31117 ./main.go -- --dev
# dlv exec -l 127.0.0.1:31117 --headless /tmp/{{.Dir}} -- --dev
/tmp/{{.Dir}} --dev {{.CLI_ARGS}}
run:webhook-worker:
dir: "./webhook-worker"
silent: true
interactive: true
vars:
Name: webhook-worker
cmds:
- |+
set -a
source .secrets/env
set +a
CGO_ENABLED=0 go build -o /tmp/{{.Name}}
# /tmp/{{.Dir}} --dev
# dlv debug -l 127.0.0.1:31117 ./main.go -- --dev
dlv exec -l 127.0.0.1:31117 --headless /tmp/{{.Name}} -- --dev
run:env-route-switcher:
dir: ./apps/env-route-switcher
dotenv:
- ./.secrets/env
cmds:
- go run ./main.go --dev --addr=localhost:8081
build:workspace-route-switcher:
dir: ./apps/workspace-route-switcher
preconditions:
- sh: '[ -n "{{.Tag}}" ]'
msg: 'var Tag must have a value'
vars:
App: "workspace-route-switcher"
Image: "{{.ImagePrefix}}/{{.App}}:{{.Tag}}"
dotenv:
- ./.secrets/env
interactive: true
silent: true
cmds:
- |
lineNumbers=$(cat Dockerfile | grep -i '^FROM' -n | tail +2 | awk -F: '{print $1}')
startLineNo=$(echo "$lineNumbers" | head -n+1)
finalLineNo=$(echo "$lineNumbers" | tail -1)
tDir=$(mktemp -d)
echo "temp dir: $tDir"
nDockerfile=$(cat Dockerfile | tail --lines=+$startLineNo | grep -i --invert-match 'from=builder')
echo "$nDockerfile" | sed "1 i # syntax=docker/dockerfile:1.4" > $tDir/Dockerfile.base
#lineNo=$(cat Dockerfile | grep -i '^FROM' -n | tail -1 | awk -F: '{print $1}')
echo "[Debug]: $tDir/Dockerfile.base"
lastStage=$(cat $tDir/Dockerfile.base | grep -i '^FROM' -n | tail -1 | awk -F: '{print $1}')
cat $tDir/Dockerfile.base | sed "$(( $lastStage + 1 )) i COPY --from=local-builder ./{{.App}} ./{{.App}}" > $tDir/Dockerfile
cat $tDir/Dockerfile
CGO_ENABLED=0 go build -v -o $tDir/{{.App}} .
docker buildx build -f $tDir/Dockerfile -t {{.Image}} . --build-context local-builder=${tDir}
docker push {{.Image}}
rm -rf $tDir
#popd 1> /dev/null
msvc:grpc-interfaces:
dir: ./operators/
grpc-interfaces:
dir: ./grpc-interfaces
summary: |+
add these lines at top of every grpc file
```proto
syntax = "proto3";
option go_package = "github.com/kloudlite/operator/grpc/<proto-file-name>";
```
cmds:
- protoc --go_out=. --go-grpc_out=. --go_opt=paths=import --go-grpc_opt=paths=import ./*.proto