-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
641 lines (577 loc) · 18 KB
/
Copy pathTaskfile.yml
File metadata and controls
641 lines (577 loc) · 18 KB
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
---
version: '3'
silent: true
run: once
failfast: true
dotenv: ['.env']
vars:
STANDARDLOOP_TASKFILES_VERSION: "v0.0.5"
CLUSTERS_FOLDER: kind
CLUSTERS:
sh: find ./{{.CLUSTERS_FOLDER}} -maxdepth 1 -type f
API_TAG: 0.0.7
HELM_RELEASE_TIMEOUT: "180s"
SUPPORTED_DOCKER_ENGINES: [colima, rancher]
SUPPORTED_K8S_ENGINES: [kind]
includes:
color: https://raw.githubusercontent.com/standardloop/taskfiles/refs/tags/{{.STANDARDLOOP_TASKFILES_VERSION}}/color.yml
rancher: https://raw.githubusercontent.com/standardloop/taskfiles/refs/tags/{{.STANDARDLOOP_TASKFILES_VERSION}}/rancher.yml
colima: https://raw.githubusercontent.com/standardloop/taskfiles/refs/tags/{{.STANDARDLOOP_TASKFILES_VERSION}}/colima.yml
tasks:
default:
aliases: [all, playground]
silent: true
prompt: "This will lanuch a cluster with infrastructure and deploy an app, are you ready for this?"
cmds:
- task: app
pre-commit:
cmds:
- pre-commit run --all
clean:
aliases: [delete]
ignore_error: true
silent: true
cmds:
- task: tilt:clean
- task: kind:clean
# - task: compose:clean
- task: docker-engine:clean
print:
cmds:
- env
- task: color:test
# DOCKER ENGINE START
docker-engine:test:
requires:
vars:
- name: DOCKER_ENGINE
preconditions:
- sh: |
{{range .SUPPORTED_DOCKER_ENGINES -}}
if [ "{{.}}" = "{{$.DOCKER_ENGINE}}" ]; then exit 0; fi
{{end -}}
exit 1
msg: |
Invalid engine "{{.DOCKER_ENGINE}}".
Supported engines are: {{join ", " .SUPPORTED_DOCKER_ENGINES}}
cmds:
- echo {{.DOCKER_ENGINE}}
docker-engine:start:
aliases: [docker-engine:run]
requires:
vars:
- name: DOCKER_ENGINE
preconditions:
- sh: |
{{range .SUPPORTED_DOCKER_ENGINES -}}
if [ "{{.}}" = "{{$.DOCKER_ENGINE}}" ]; then exit 0; fi
{{end -}}
exit 1
msg: |
Invalid engine "{{.DOCKER_ENGINE}}".
Supported engines are: {{join ", " .SUPPORTED_DOCKER_ENGINES}}
cmds:
- if: '{{eq .DOCKER_ENGINE "colima"}}'
task: colima:start
vars:
FLAGS: "--network-address --cpu {{.DOCKER_ENGINE_CPUS}} --memory {{.DOCKER_ENGINE_MEMORY}}"
- if: '{{eq .DOCKER_ENGINE "rancher"}}'
task: rancher:start
vars:
FLAGS: "--virtual-machine.number-cpus {{.DOCKER_ENGINE_CPUS}} --virtual-machine.memory-in-gb {{.DOCKER_ENGINE_MEMORY}}"
status:
- '{{if eq .DOCKER_ENGINE "colima"}} colima status > /dev/null 2>&1 {{else}} true {{end}}'
- '{{if eq .DOCKER_ENGINE "rancher"}} rdctl list-settings > /dev/null 2>&1 {{else}} true {{end}}'
- docker info > /dev/null 2>&1
docker-engine:clean:
runs: once
requires:
vars:
- name: DOCKER_ENGINE
preconditions:
- sh: |
{{range .SUPPORTED_DOCKER_ENGINES -}}
if [ "{{.}}" = "{{$.DOCKER_ENGINE}}" ]; then exit 0; fi
{{end -}}
exit 1
msg: |
Invalid engine "{{.DOCKER_ENGINE}}".
Supported engines are: {{join ", " .SUPPORTED_DOCKER_ENGINES}}
cmds:
- if: '{{eq .DOCKER_ENGINE "colima"}}'
task: colima:clean
vars:
FLAGS: "-f"
- if: '{{eq .DOCKER_ENGINE "rancher"}}'
task: rancher:clean
# DOCKER ENGINE END
# # COMPOSE START
# compose:start:
# silent: true
# preconditions:
# - docker info > /dev/null 2>&1
# deps:
# - docker-engine:start
# cmds:
# - docker compose up -d
# compose:clean:
# silent: true
# cmds:
# - |
# if docker info > /dev/null 2>&1; then
# docker compose down
# else
# echo "{{.TEXT_GRAY}}docker is not running so no compose to clean right now{{.TEXT_RESET}}"
# fi
# # COMPOSE END
# HELPER START
wait-for-crd:
internal: true
silent: true
run: always
cmds:
- |
attempts=30
while ! kubectl wait --for condition=established --timeout=60s crd {{.CRD}} > /dev/null 2>&1
do
echo "{{.TEXT_YELLOW}}Waiting for {{.CRD}} to be ready....{{.TEXT_RESET}}"
sleep 5
let attempts=$attempts-1
if [ $attempts -eq 0 ]
then
echo "{{.TEXT_RED}}{{.CRD}} never got ready!{{.TEXT_RESET}}"
exit 1
fi
done
echo "{{.TEXT_GREEN}}{{.CRD}} came up!{{.TEXT_RESET}}"
status:
- kubectl wait --for condition=established --timeout=60s crd {{.CRD}} > /dev/null 2>&1
# HELPER END
# KIND START
kind:
silent: true
aliases: ["cluster"]
deps:
- docker-engine:start
cmds:
- task: kind:cloud-provider:run
# kind:print:
# silent: true
# cmds:
# - |
# {{range .CLUSTERS | splitArgs}}
# # echo "{{.}}"
# cat "{{.}}" | yq .name
# {{end}}
kind:create:
silent: true
deps:
- docker-engine:start
cmds:
- ./kind/local-registry-setup.sh
- kind create cluster --config=kind/slke-1.yaml
- ./kind/local-registry-finish.sh
status:
- kubectl cluster-info --context kind-slke-1
# kind:create:
# silent: true
# deps:
# - docker-engine:start
# cmds:
# - |
# {{range .CLUSTERS | splitArgs}}
# cluster_name=$(yq '.name' {{.}})
# if ! kubectl cluster-info --context kind-${cluster_name} > /dev/null 2>&1
# then
# kind create cluster --config={{.}}
# else
# echo "$cluster_name already created"
# fi
# {{end}}
# status:
# - |
# {{range .CLUSTERS | splitArgs}}
# cluster_name=$(yq '.name' {{.}})
# kubectl cluster-info --context kind-${cluster_name}
# {{end}}
kind:clean:
silent: true
deps:
- kind:cloud-provider:clean
cmds:
- |
if docker info > /dev/null 2>&1; then
kind delete clusters --all
else
echo "{{.TEXT_GRAY}}docker is not running so no clusters to clean right now{{.TEXT_RESET}}"
fi
kind:cloud-provider:run:
silent: true
deps:
- kind:create
interactive: true
cmds:
- echo "{{.TEXT_YELLOW}}sudo needed for cloud-provider-kind{{.TEXT_RESET}}"
- sudo -v
- bash -c 'nohup sudo cloud-provider-kind --gateway-channel standard >/dev/null 2>&1 &'
- echo "{{.TEXT_GREEN}}main pid -> $(pgrep sudo cloud-provider-kind){{.TEXT_RESET}}"
- task: kind:cloud-provider:run:check-complete
status:
- pgrep sudo cloud-provider-kind
kind:cloud-provider:run:check-complete:
internal: true
parallel: true
deps:
- task: wait-for-crd
vars: { CRD: "httproutes.gateway.networking.k8s.io" }
- task: wait-for-crd
vars: { CRD: "gateways.gateway.networking.k8s.io" }
- task: wait-for-crd
vars: { CRD: "gatewayclasses.gateway.networking.k8s.io" }
kind:cloud-provider:clean:
silent: true
interactive: true
cmds:
- |
if pgrep sudo cloud-provider-kind > /dev/null 2>&1; then
echo "{{.TEXT_YELLOW}}sudo needed for cloud-provider-kind{{.TEXT_RESET}}"
sudo -v
sudo pkill cloud-provider-kind
echo "{{.TEXT_GREEN}}killed cloud-provider-kind{{.TEXT_RESET}}"
else
echo "{{.TEXT_GRAY}}cloud-provider-kind is not running{{.TEXT_RESET}}"
fi
kind:cloud-provider:restart:
interactive: true
cmds:
- task: kind:cloud-provider:clean
- task: kind:cloud-provider:run
# KIND END
# INFRA START
infra:
aliases: [infrastructure]
deps:
- infra:istio:install
- infra:metrics-server:install
- infra:kube-prom-stack:install
# - infra:headlamp:install
- infra:homer:install
# - infra:grafana:install
- infra:argo-rollouts:install
# - infra:kiali:install
infra:clean:
deps:
- task: infra:metrics-server:clean
- task: infra:istio:clean
- task: infra:kube-prom-stack:clean
- task: infra:argo-rollouts:clean
- task: infra:headlamp:clean
- task: infra:homer:clean
- task: infra:grafana:clean
- task: infra:kiali:clean
## FLUX START
infra:flux:install:
deps:
- kind
cmds:
- flux install --components=source-controller,helm-controller
status:
- |
flux check --components=source-controller,helm-controller
infra:flux:clean:
aliases: [infra:flux:uninstall, infra:flux:delete]
interactive: true
cmds:
- flux uninstall
## FLUX END
## SOURCES START
infra:sources:install:
deps:
- infra:flux:install
cmds:
- kubectl apply -k deploy/infrastructure/sources
status:
- kubectl diff -k deploy/infrastructure/sources
## SOURCES END
## METRICS_SERVER START
infra:metrics-server:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/metrics-server
status:
- kubectl diff -k deploy/infrastructure/metrics-server
infra:metrics-server:clean:
cmds:
- kubectl delete -k deploy/infrastructure/metrics-server
## METRICS_SERVER END
## ISTIO START
infra:istio:install:
deps:
- infra:sources:install
cmds:
- task: infra:istio:base:install
- task: infra:istio:gateway:install
# - task: infra:istio:update-etc-hosts
infra:istio:base:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/istio/base
- kubectl wait helmrelease/istio-base --for=condition=Ready --timeout={{.HELM_RELEASE_TIMEOUT}} -n istio-system
- kubectl wait helmrelease/istiod --for=condition=Ready --timeout={{.HELM_RELEASE_TIMEOUT}} -n istio-system
status:
- kubectl diff -k deploy/infrastructure/istio/base
infra:istio:gateway:install:
deps:
- infra:flux:install
- infra:sources:install
- infra:istio:base:install
- task: wait-for-crd
vars: { CRD: "gateways.gateway.networking.k8s.io" }
- task: wait-for-crd
vars: { CRD: "gatewayclasses.gateway.networking.k8s.io" }
- task: wait-for-crd
vars: { CRD: "httproutes.gateway.networking.k8s.io" }
- task: wait-for-crd
vars: { CRD: "gateways.networking.istio.io" }
- task: wait-for-crd
vars: { CRD: "envoyfilters.networking.istio.io" }
- task: wait-for-crd
vars: { CRD: "virtualservices.networking.istio.io" }
cmds:
- kubectl apply -k deploy/infrastructure/istio/gateway
- kubectl wait helmrelease/istio-gateway --for=condition=Ready --timeout={{.HELM_RELEASE_TIMEOUT}} -n istio-gateway
status:
- kubectl diff -k deploy/infrastructure/istio/gateway
infra:istio:update-etc-hosts:
prompt: Do you want to update /etc/hosts ?
silent: true
deps:
- infra:istio:install
cmds:
- |
if [[ -n "{{.LOAD_BALANCER_IP}}" ]]; then
echo {{.LOAD_BALANCER_IP}}
sudo -v
echo "{{.LOAD_BALANCER_IP}} playground.local" | sudo tee -a /etc/hosts
else
echo "{{.TEXT_RED}}Couldn't find IP address{{.TEXT_RESET}}"
fi
status:
- cat /etc/hosts | grep {{.LOAD_BALANCER_IP}}
vars:
LOAD_BALANCER_IP:
sh: kubectl get gateway/playground-local-gateway -n istio-gateway | awk '{print $3}' | awk NR==2 # yamllint disable-line rule:line-length
## ISTIO END
## KIALI START
infra:kiali:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- task: infra:kiali:operator:install
- task: infra:kiali:instance:install
infra:kiali:operator:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/kiali/operator
status:
- kubectl diff -k deploy/infrastructure/kiali/operator
infra:kiali:operator:clean:
cmds:
- kubectl delete -k deploy/infrastructure/kiali/operator
infra:kiali:instance:install:
deps:
- infra:flux:install
- infra:sources:install
- infra:kiali:operator:install
- task: wait-for-crd
vars: { CRD: "kialis.kiali.io" }
cmds:
- kubectl apply -k deploy/infrastructure/kiali/instance
status:
- kubectl diff -k deploy/infrastructure/kiali/instance
infra:kiali:instance:clean:
cmds:
- kubectl delete -k deploy/infrastructure/kiali/instance
infra:kiali:clean:
cmds:
- task: infra:kiali:instance:clean
- task: infra:kiali:operator:clean
## KIALI END
## KUBE_PROM_STACK START
infra:kube-prom-stack:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- task: infra:kube-prom-stack:chart:install
- task: infra:kube-prom-stack:scrapers:install
infra:kube-prom-stack:chart:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/kube-prom-stack
status:
- kubectl diff -k deploy/infrastructure/kube-prom-stack
infra:kube-prom-stack:scrapers:install:
deps:
- infra:flux:install
- infra:sources:install
- infra:kube-prom-stack:chart:install
- task: wait-for-crd
vars: { CRD: "podmonitors.monitoring.coreos.com" }
- task: wait-for-crd
vars: { CRD: "servicemonitors.monitoring.coreos.com" }
cmds:
- kubectl apply -k deploy/infrastructure/kube-prom-stack/scrapers
status:
- kubectl diff -k deploy/infrastructure/kube-prom-stack/scrapers
infra:kube-prom-stack:clean:
cmds:
- kubectl delete -k deploy/infrastructure/kube-prom-stack/scrapers
- kubectl delete -k deploy/infrastructure/kube-prom-stack
## KUBE_PROM_STACK END
## ARGO_ROLLOUTS START
infra:argo-rollouts:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/argo-rollouts
status:
- kubectl diff -k deploy/infrastructure/argo-rollouts
infra:argo-rollouts:clean:
cmds:
- kubectl delete -k deploy/infrastructure/argo-rollouts
## ARGO_ROLLOUTS END
## HEADLAMP START
infra:headlamp:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/headlamp
# - kubectl -n kube-system create serviceaccount headlamp-admin # wip
status:
- kubectl diff -k deploy/infrastructure/headlamp
infra:headlamp:token:
deps:
- infra:headlamp:install
cmds:
- kubectl create clusterrolebinding headlamp-playground-admin --serviceaccount=kube-system:headlamp-admin --clusterrole=cluster-admin
- kubectl create token headlamp-admin -n kube-system | pbcopy
infra:headlamp:clean:
cmds:
- kubectl delete -k deploy/infrastructure/headlamp
## HEADLAMP END
## GRAFANA START
infra:grafana:install:
cmds:
- task: infra:grafana:operator:install
- task: infra:grafana:instance:install
- task: infra:grafana:dashboards:install
infra:grafana:clean:
cmds:
- task: infra:grafana:dashboards:clean
- task: infra:grafana:instance:clean
- task: infra:grafana:operator:clean
### GRAFANA OPERATOR START
infra:grafana:operator:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/grafana/operator
status:
- kubectl diff -k deploy/infrastructure/grafana/operator
infra:grafana:operator:clean:
cmds:
- kubectl delete -k deploy/infrastructure/grafana/operator
### GRAFANA INSTANCE START
infra:grafana:instance:install:
deps:
- infra:flux:install
- infra:sources:install
- infra:grafana:operator:install
- task: wait-for-crd
vars: { CRD: "grafanas.grafana.integreatly.org" }
- task: wait-for-crd
vars: { CRD: "grafanadatasources.grafana.integreatly.org" }
cmds:
- kubectl apply -k deploy/infrastructure/grafana/instance
status:
- kubectl diff -k deploy/infrastructure/grafana/instance
infra:grafana:instance:clean:
cmds:
- kubectl delete -k deploy/infrastructure/grafana/instance
### GRAFANA INSTANCE END
### GRAFANA DASHBOARDS START
infra:grafana:dashboards:install:
deps:
- infra:flux:install
- infra:sources:install
- infra:grafana:operator:install
- task: wait-for-crd
vars: { CRD: "grafanadashboards.grafana.integreatly.org" }
vars:
NAMESPACE: grafana
cmds:
- |
helm upgrade --install grafana-dashboards deploy/infrastructure/grafana/dashboards \
-f deploy/infrastructure/grafana/dashboards/values.yaml \
-f deploy/infrastructure/grafana/dashboards/env/playground.values.yaml \
--namespace {{.NAMESPACE}}
status:
- |
helm template deploy/infrastructure/grafana/dashboards --name-template=grafana-dashboards \
--namespace {{.NAMESPACE}} \
--is-upgrade \
--no-hooks \
-f deploy/infrastructure/grafana/dashboards/values.yaml \
-f deploy/infrastructure/grafana/dashboards/env/playground.values.yaml | kubectl diff -f - -n {{.NAMESPACE}}
infra:grafana:dashboards:clean:
cmds:
- helm delete grafana-dashboards -n grafana
### GRAFANA DASHBOARDS END
## GRAFANA END
## HOMER START
infra:homer:install:
deps:
- infra:flux:install
- infra:sources:install
cmds:
- kubectl apply -k deploy/infrastructure/homer
- open "http://home.playground.local"
status:
- kubectl diff -k deploy/infrastructure/homer
infra:homer:clean:
cmds:
- kubectl delete -k deploy/infrastructure/homer
## HOMER END
# INFRA END
# APP START
tilt:
aliases: ["app"]
deps:
- infra
preconditions:
- tilt verify-install
cmds:
- task: wait-for-crd
vars: { CRD: "servicemonitors.monitoring.coreos.com" }
- task: wait-for-crd
vars: { CRD: "envoyfilters.networking.istio.io" }
- task: wait-for-crd
vars: { CRD: "virtualservices.networking.istio.io" }
- tilt ci
tilt:clean:
cmds:
- tilt down
# APP END