-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
454 lines (411 loc) · 14.3 KB
/
Taskfile.yml
File metadata and controls
454 lines (411 loc) · 14.3 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
version: "3"
# Incremental build pipeline for incident-commander. Each stage tracks its
# own sources + generates, so `task build` re-runs only the stages whose
# inputs changed since the last successful run. Checksums live in .task/.
#
# Stages (topologically):
# tailwind-asset → controller-gen → generate → gen-schemas → manifests
# → fmt → ginkgo → ui:install → ui:build → go:build
#
# The Makefile's `make build` still works for CI and parity with existing
# scripts; this Taskfile is the fast local path.
vars:
APP_NAME: incident-commander
REGISTRY: '{{.REGISTRY | default "docker.lab"}}'
IMAGE: "{{.REGISTRY}}/{{.APP_NAME}}"
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "dev"
# Build locations
BIN_DIR: "{{.ROOT_DIR}}/.bin"
BINARY: "{{.BIN_DIR}}/{{.APP_NAME}}"
TAILWIND_VERSION: 3.4.17
TAILWIND_JS: auth/oidc/static/tailwind.min.js
CONTROLLER_GEN_VERSION: v0.19.0
PGRST_VERSION: v14.1
CONTROLLER_GEN: "{{.BIN_DIR}}/controller-gen"
VERSION_TAG:
sh: git describe --abbrev=0 --tags --exact-match 2>/dev/null || echo latest
BUILD_DATE:
sh: date "+%Y-%m-%d %H:%M:%S"
tasks:
default:
desc: Show available tasks
cmds:
- task --list
build:
desc: Build the full incident-commander binary with embedded UI
deps:
- go:build
clean:
desc: Remove build artifacts and Task checksums
cmds:
- rm -rf .task .bin/{{.APP_NAME}} ui/frontend/dist ui/frontend/node_modules
- rm -f {{.TAILWIND_JS}}
# ────────────── Downloaded + vendored assets ──────────────
tailwind-asset:
desc: Download the vendored Tailwind script used by the OIDC static page
cmds:
- curl -sL "https://cdn.tailwindcss.com/{{.TAILWIND_VERSION}}" -o {{.TAILWIND_JS}}
generates:
- "{{.TAILWIND_JS}}"
status:
- test -s {{.TAILWIND_JS}}
# ────────────── Code generation ──────────────
controller-gen:
desc: Install controller-gen into .bin if missing or wrong version
cmds:
- mkdir -p {{.BIN_DIR}}
- GOBIN={{.BIN_DIR}} go install sigs.k8s.io/controller-tools/cmd/controller-gen@{{.CONTROLLER_GEN_VERSION}}
generates:
- "{{.CONTROLLER_GEN}}"
status:
- test -x {{.CONTROLLER_GEN}}
- '{{.CONTROLLER_GEN}} --version 2>/dev/null | grep -q "{{.CONTROLLER_GEN_VERSION}}"'
generate:
desc: Run controller-gen object codegen (DeepCopy etc.) for CRD types
deps: [controller-gen]
cmds:
- '{{.CONTROLLER_GEN}} object paths="./api/..." paths="./logs/..."'
sources:
- api/**/*.go
- logs/**/*.go
gen-schemas:
desc: Generate JSON schemas for all CRDs (hack/generate-schemas)
deps: [generate]
cmds:
- |
set -e
cp go.mod hack/generate-schemas/go.mod
cd hack/generate-schemas
go mod edit -module=github.com/flanksource/incident-commander/hack/generate-schemas
go mod edit -require=github.com/flanksource/incident-commander@v1.0.0
go mod edit -replace=github.com/flanksource/incident-commander=../../
if grep -v "^//" ../../go.mod | grep -q "replace.*github.com/flanksource/duty.*=>"; then
go mod edit -replace=github.com/flanksource/duty=../../../duty
fi
if grep -v "^//" ../../go.mod | grep -q "replace.*github.com/flanksource/clicky.*=>"; then
go mod edit -replace=github.com/flanksource/clicky=../../../clicky
fi
go mod tidy
go run ./main.go
sources:
- go.mod
- go.sum
- api/**/*.go
- hack/generate-schemas/main.go
generates:
- config/schemas/*.schema.json
manifests:
desc: Generate CRD manifests
deps: [controller-gen, generate]
cmds:
- '{{.CONTROLLER_GEN}} crd paths="./api/..." output:crd:artifacts:config=config/crds'
sources:
- api/**/*.go
generates:
- config/crds/*.yaml
fmt:
desc: Run gofmt across the module
cmds:
- go fmt ./...
sources:
- "**/*.go"
- exclude: ui/frontend/**
- exclude: .bin/**
- exclude: node_modules/**
ginkgo:
desc: Install ginkgo v2 into the module
cmds:
- go install github.com/onsi/ginkgo/v2/ginkgo
sources:
- go.mod
- go.sum
status:
- command -v ginkgo >/dev/null 2>&1
# ────────────── Frontend ──────────────
ui:install:
desc: Install ui/frontend dependencies and update lockfile when package metadata changes
dir: ui/frontend
cmds:
- CI=true pnpm install --no-frozen-lockfile --prefer-offline
sources:
- package.json
- pnpm-lock.yaml
- pnpm-workspace.yaml
status:
# `.modules.yaml` is only written after a successful install — a stale
# `node_modules/` containing only `.pnpm/` (broken install) won't pass.
- test -f node_modules/.modules.yaml
- test node_modules/.modules.yaml -nt pnpm-lock.yaml
- test node_modules/.modules.yaml -nt package.json
ui:build:
desc: Build the embedded UI bundle (tsc --noEmit + vite) into ui/frontend/dist
dir: ui/frontend
deps: [ui:install]
cmds:
- pnpm run build
sources:
- src/**/*.ts
- src/**/*.tsx
- src/**/*.css
- index.html
- package.json
- pnpm-lock.yaml
- tsconfig.json
- vite.config.ts
# Clicky-ui is linked via pnpm workspace; rebuild when its dist changes.
- ../../../clicky-ui/packages/ui/dist/index.mjs
- ../../../clicky-ui/packages/ui/src/styles/**/*.css
generates:
- dist/index.html
- dist/assets/**
ui:test:
desc: Run frontend unit tests (vitest)
dir: ui/frontend
deps: [ui:install]
cmds:
- pnpm test
sources:
- src/**/*.ts
- src/**/*.tsx
# ────────────── Go build ──────────────
ui:checksum:
desc: Regenerate ui/bundle_checksum.go (sha256 of the embedded bundle)
deps: [ui:build]
cmds:
- go generate ./ui/...
sources:
- ui/frontend/dist/index.html
- ui/frontend/dist/assets/**
- ui/internal/gen-checksum/main.go
generates:
- ui/bundle_checksum.go
go:build-fast:
desc: Build the Go binary without the UI bundle (for fast iteration on Go code)
deps:
- ui:build
- ui:checksum
cmds:
- mkdir -p {{.BIN_DIR}}
- >-
go build -o {{.BINARY}} -ldflags "-X \"main.version={{.VERSION_TAG}} built at {{.BUILD_DATE}}\"" main.go
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- "{{.BINARY}}"
go:build:
desc: Build the Go binary with the embedded UI bundle + tailwind asset
deps:
- tailwind-asset
- manifests
- gen-schemas
- fmt
- ginkgo
- ui:build
- ui:checksum
cmds:
- mkdir -p {{.BIN_DIR}}
- >-
go build -o {{.BINARY}} -ldflags "-X \"main.version={{.VERSION_TAG}} built at {{.BUILD_DATE}}\"" main.go
sources:
- "**/*.go"
- go.mod
- go.sum
- ui/frontend/dist/index.html
- ui/frontend/dist/assets/**
- ui/bundle_checksum.go
- exclude: ui/frontend/node_modules/**
- exclude: .bin/**
- exclude: .task/**
generates:
- "{{.BINARY}}"
# ────────────── Plugins ──────────────
plugin:ui:install:
desc: Install pnpm deps for a plugin UI workspace (PLUGIN=<name>)
requires:
vars: [PLUGIN]
dir: "{{.PLUGIN}}/ui-src"
cmds:
- CI=true pnpm install --no-frozen-lockfile --prefer-offline
sources:
- package.json
- pnpm-lock.yaml
- pnpm-workspace.yaml
status:
# `.modules.yaml` only exists after a successful install — guards
# against a half-populated node_modules/ that contains only `.pnpm/`.
- test -f node_modules/.modules.yaml
- test node_modules/.modules.yaml -nt package.json
plugin:ui:build:
desc: Build a plugin UI bundle into <plugin>/ui (PLUGIN=<name>)
requires:
vars: [PLUGIN]
dir: "{{.PLUGIN}}/ui-src"
deps:
- task: plugin:ui:install
vars: { PLUGIN: "{{.PLUGIN}}" }
env:
PLUGIN_VERSION: "{{.VERSION}}"
PLUGIN_BUILD_DATE: "{{.BUILD_DATE}}"
cmds:
- pnpm run build
sources:
- src/**/*.ts
- src/**/*.tsx
- src/**/*.css
- index.html
- package.json
- pnpm-lock.yaml
- pnpm-workspace.yaml
- tsconfig.json
- vite.config.ts
# Rebuild when clicky-ui dist or its style tokens change.
- ../../../../clicky-ui/packages/ui/dist/index.mjs
- ../../../../clicky-ui/packages/ui/src/styles/**/*.css
generates:
- ../ui/index.html
plugin:generate:
desc: Regenerate ui_checksum.go for a plugin (PLUGIN=<name>)
requires:
vars: [PLUGIN]
deps:
- task: plugin:ui:build
vars: { PLUGIN: "{{.PLUGIN}}" }
cmds:
- cd {{.PLUGIN}} && go generate ./...
sources:
- "{{.PLUGIN}}/ui/**"
- "{{.PLUGIN}}/internal/gen-checksum/main.go"
generates:
- "{{.PLUGIN}}/ui_checksum.go"
plugin:build:
desc: Build and install a plugin binary into $MISSION_CONTROL_PLUGIN_PATH (PLUGIN=<name>)
requires:
vars: [PLUGIN]
deps:
- task: plugin:generate
vars: { PLUGIN: "{{.PLUGIN}}" }
vars:
PLUGIN_PATH:
sh: echo "${MISSION_CONTROL_PLUGIN_PATH:-$HOME/.mission-control/plugins}"
TARGET_GOOS: '{{.TARGET_GOOS | default ""}}'
TARGET_GOARCH: '{{.TARGET_GOARCH | default ""}}'
cmds:
- mkdir -p {{.PLUGIN_PATH}}
- |
set -euo pipefail
goos="{{.TARGET_GOOS}}"
goarch="{{.TARGET_GOARCH}}"
env_args=(CGO_ENABLED=0)
if [ -n "$goos" ]; then env_args+=(GOOS="$goos"); fi
if [ -n "$goarch" ]; then env_args+=(GOARCH="$goarch"); fi
(cd {{.PLUGIN}} && env "${env_args[@]}" go build -o {{.PLUGIN_PATH}}/{{.PLUGIN}} -ldflags "-X 'main.Version={{.VERSION}}' -X 'main.BuildDate={{.BUILD_DATE}}'" .)
- echo "Installed {{.PLUGIN_PATH}}/{{.PLUGIN}} version={{.VERSION}} built={{.BUILD_DATE}}"
sources:
- "{{.PLUGIN}}/**/*.go"
- "{{.PLUGIN}}/ui/**"
- "{{.PLUGIN}}/ui_checksum.go"
- "{{.PLUGIN}}/go.mod"
- "{{.PLUGIN}}/go.sum"
generates:
- "{{.PLUGIN_PATH}}/{{.PLUGIN}}"
build:plugin:arthas:
desc: Build and install the arthas plugin
cmds:
- task: plugin:build
vars: { PLUGIN: arthas }
build:plugin:golang:
desc: Build and install the golang plugin
cmds:
- task: plugin:build
vars: { PLUGIN: golang }
build:plugin:inspektor-gadget:
desc: Build and install the inspektor-gadget plugin
cmds:
- task: plugin:build
vars: { PLUGIN: inspektor-gadget }
build:plugin:kubernetes-logs:
desc: Build and install the kubernetes-logs plugin
cmds:
- task: plugin:build
vars: { PLUGIN: kubernetes-logs }
build:plugin:postgres:
desc: Build and install the postgres plugin
cmds:
- task: plugin:build
vars: { PLUGIN: postgres }
build:plugin:sql-server:
desc: Build and install the sql-server plugin
cmds:
- task: plugin:build
vars: { PLUGIN: sql-server }
# ────────────── Developer loops ──────────────
run:
desc: Build + run `serve --ui` on port 8080
deps: [build]
cmds:
- "{{.BINARY}} serve --ui {{.CLI_ARGS}}"
clicky-ui:build:
desc: Rebuild the @flanksource/clicky-ui package only (not the whole clicky-ui monorepo)
dir: "{{.ROOT_DIR}}/../clicky-ui/packages/ui"
cmds:
- pnpm build
sources:
- src/**/*.ts
- src/**/*.tsx
- src/**/*.css
- package.json
- tsconfig.json
generates:
- dist/index.mjs
- dist/index.d.mts
env:
CI: "true"
dev:
desc: |
Rebuild clicky-ui + incident-commander UI + the Go binary, then start
`serve --ui --dev` with a local htpasswd. The Go server proxies /ui to
Vite so frontend changes are served from Vite watch mode instead of the
embedded bundle.
deps: [clicky-ui:build, ui:build, go:build-fast]
env:
PGRST_VERSION: any
cmds:
# secret is hardcoded for dev purposes and is save to
- "{{.BINARY}} serve --htpasswd-file .htpasswd --disable-operators -vv --postgrest-uri http://localhost:0 --ui --dev {{.CLI_ARGS}}"
test:
desc: Run Ginkgo tests (skips e2e)
deps: [ginkgo]
cmds:
- >-
ginkgo -r --skip-package=tests/e2e --keep-going --junit-report junit-report.xml --github-output --output-dir test-reports --succinct --label-filter='!ignore_local'
# ────────────── Kubernetes lab deploy (existing tasks) ──────────────
image:lab:
desc: "Build and push the incident-commander image to the lab registry. Defaults REGISTRY=docker.lab; override with REGISTRY=docker.example.com."
cmds:
- docker buildx build --platform linux/amd64 --push . -f Dockerfile -t {{.IMAGE}}:{{.VERSION}} -t {{.IMAGE}}:latest
deploy:lab:
desc: "Build, push, and patch the running incident-commander deployment in the current kubectl context. Defaults REGISTRY=docker.lab."
deps: [image:lab]
vars:
CURRENT_NAMESPACE:
sh: kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null || echo "default"
DEPLOYMENT:
sh: |
ns={{.CURRENT_NAMESPACE | default "default"}}
name=$(kubectl -n "$ns" get deploy \
-l app.kubernetes.io/name={{.APP_NAME}} \
-o jsonpath='{.items[0].metadata.name}' 2>/dev/null)
if [ -z "$name" ]; then
name=$(kubectl -n "$ns" get deploy \
-o jsonpath='{.items[?(@.metadata.name=="{{.APP_NAME}}")].metadata.name}' 2>/dev/null)
fi
echo "${name:-{{.APP_NAME}}}"
cmds:
- echo "Patching deploy/{{.DEPLOYMENT}} in namespace {{.CURRENT_NAMESPACE}} -> {{.IMAGE}}:{{.VERSION}}"
- >-
kubectl -n {{.CURRENT_NAMESPACE}} set image deploy/{{.DEPLOYMENT}} {{.APP_NAME}}={{.IMAGE}}:{{.VERSION}}
- kubectl -n {{.CURRENT_NAMESPACE}} rollout restart deploy/{{.DEPLOYMENT}}
- kubectl -n {{.CURRENT_NAMESPACE}} rollout status deploy/{{.DEPLOYMENT}} --timeout=300s