-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
283 lines (256 loc) · 7.5 KB
/
Copy pathTaskfile.yml
File metadata and controls
283 lines (256 loc) · 7.5 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
---
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:
- prek run --all-files
clean:
aliases: [delete]
ignore_error: true
silent: true
cmds:
- task: tilt:clean
- task: infra: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: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: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:create
infra:create:
deps:
- kind:cloud-provider:run
cmds:
- tofu init --upgrade
- tofu apply --auto-approve
home: open "http://home.playground.local"
infra:clean:
cmds:
- tofu destroy --auto-approve
# 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