Repository navigation
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
370 lines (336 loc) · 13.9 KB
/
Copy pathTaskfile.yaml
File metadata and controls
370 lines (336 loc) · 13.9 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
---
version: 3
includes:
git:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/git/git.yaml
lint:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/git/linting.yaml
go:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/go/lint.yaml
dagger:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/dagger/modules.yaml
image:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/docker/copy.yaml
goBuild:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/go/build.yaml
release:
taskfile: https://raw.githubusercontent.com/stuttgart-things/tasks/refs/heads/main/go/release-workflow.yaml
vars:
PROJECT:
sh: basename $(pwd)
ORGA_NAME: stuttgart-things
GO_MODULE: github.com/{{ .ORGA_NAME }}/{{ .PROJECT }}
DAGGER_MODULE_DIR: ./dagger
SOURCE_CODE_DIR: "."
LINT_REPORT_PATH: /tmp/lint-report-{{ .PROJECT }}.txt
TEST_REPORT_PATH: /tmp/test-report-{{ .PROJECT }}.txt
TARGET_IMAGE_REPO: ghcr.io/{{ .ORGA_NAME }}/{{ .PROJECT }}
DAGGER_KCL_MODULE: github.com/stuttgart-things/dagger/kcl@v0.82.0
KCL_SOURCE_DIR: kcl
KCL_PROFILE_FILE: tests/kcl-deploy-profile.yaml
RENDERED_OUTPUT_PATH: /tmp/rendered-{{ .PROJECT }}.yaml
KUSTOMIZE_BASE_EXPORT_PATH: /tmp/kustomize-base-{{ .PROJECT }}
KUSTOMIZE_OCI_REPO: ghcr.io/{{ .ORGA_NAME }}/{{ .PROJECT }}-kustomize
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null | grep -v '^$' || echo dev
COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo unknown
DATE:
sh: date -u '+%Y-%m-%dT%H:%M:%SZ'
LDFLAGS: -X main.version={{.VERSION}} -X main.commit={{.COMMIT}} -X main.date={{.DATE}}
tasks:
lint:
desc: Run Go lint via Dagger module
cmds:
- |
dagger call -m {{ .DAGGER_MODULE_DIR }} lint \
--src "{{ .SOURCE_CODE_DIR }}" \
export --path={{ .LINT_REPORT_PATH }} \
--progress plain
test:
desc: Run Go unit tests (race detector) via Dagger — same call as CI
cmds:
- |
dagger call -m {{ .DAGGER_MODULE_DIR }} test \
--src "{{ .SOURCE_CODE_DIR }}" \
--progress plain
build-test-binary:
desc: Build and test binary via Dagger
cmds:
- |
dagger call -m {{ .DAGGER_MODULE_DIR }} \
build-and-test-binary \
--source "{{ .SOURCE_CODE_DIR }}" \
export --path={{ .TEST_REPORT_PATH }} \
--progress plain -vv
build-output-binary:
desc: Build clusterscope binary
cmds:
- |
dagger call -m {{ .DAGGER_MODULE_DIR }} build \
--src "{{ .SOURCE_CODE_DIR }}" \
--bin-name="{{ .PROJECT }}" \
--progress plain -vv \
export --path=/tmp/go/build
build-scan-image-ko:
desc: Build, push and scan container image with ko
cmds:
- |
RANDOM_TAG=$(openssl rand -hex 6)
REPO_NAME="ttl.sh/{{ .PROJECT }}-${RANDOM_TAG}"
IMAGE_REF=$(dagger call -m {{ .DAGGER_MODULE_DIR }} build-image \
--src "{{ .SOURCE_CODE_DIR }}" \
--repo "$REPO_NAME" \
--push="true" \
--progress plain)
dagger call -m {{ .DAGGER_MODULE_DIR }} scan-image \
--image-ref "$IMAGE_REF" \
--severity "HIGH,CRITICAL" \
--progress plain \
export --path=/tmp/trivy-scan-{{ .PROJECT }}.json
run-local:
desc: Run clusterscope locally against a cluster directory
vars:
DIR: '{{ .DIR | default "./clusters" }}'
TECH: '{{ .TECH | default "flux" }}'
OUT: '{{ .OUT | default "/tmp/clusterscope-out.html" }}'
cmds:
- go run -ldflags '{{.LDFLAGS}}' ./cmd/clusterscope -dir {{ .DIR }} -tech {{ .TECH }} -out {{ .OUT }}
- echo "Output written to {{ .OUT }}"
run-serve:
desc: Run clusterscope in serve mode (HTTP dashboard)
vars:
DIR: '{{ .DIR | default "./clusters" }}'
PORT: '{{ .PORT | default "8080" }}'
cmds:
- go run -ldflags '{{.LDFLAGS}}' ./cmd/clusterscope -dir {{ .DIR }} -serve :{{ .PORT }}
ui-serve:
desc: Serve multi-cluster UI locally (live dashboard, auto-reload on changes)
vars:
ROOT: '{{ .ROOT | default "/tmp/test-clusters" }}'
PORT: '{{ .PORT | default "8080" }}'
cmds:
- echo "Starting clusterscope dashboard at http://localhost:{{ .PORT }} (root={{ .ROOT }})"
- go run -ldflags '{{.LDFLAGS}}' ./cmd/clusterscope -serve :{{ .PORT }} -root {{ .ROOT }}
ui-serve-live:
desc: Serve multi-cluster UI with live kubectl status enrichment
vars:
ROOT: '{{ .ROOT | default "/tmp/test-clusters" }}'
PORT: '{{ .PORT | default "8080" }}'
KUBECONFIG: '{{ .KUBECONFIG | default "" }}'
REFRESH: '{{ .REFRESH | default "30" }}'
cmds:
- echo "Starting clusterscope LIVE dashboard at http://localhost:{{ .PORT }} (root={{ .ROOT }})"
- >
go run -ldflags '{{.LDFLAGS}}' ./cmd/clusterscope
-serve :{{ .PORT }}
-root {{ .ROOT }}
-live
{{ if .KUBECONFIG }}-kubeconfig {{ .KUBECONFIG }}{{ end }}
-refresh {{ .REFRESH }}
ui-static:
desc: Generate static multi-cluster HTML dashboard locally
vars:
ROOT: '{{ .ROOT | default "/tmp/test-clusters" }}'
OUT: '{{ .OUT | default "/tmp/clusterscope-ui" }}'
cmds:
- go run -ldflags '{{.LDFLAGS}}' ./cmd/clusterscope -root {{ .ROOT }} -out {{ .OUT }}
- echo "Dashboard generated at {{ .OUT }}/index.html"
- 'echo "Open with: xdg-open {{ .OUT }}/index.html"'
pdf-export:
desc: Export a cluster profile as PDF via headless Chrome (server must be running)
vars:
CLUSTER: '{{ .CLUSTER | default "" }}'
PORT: '{{ .PORT | default "8080" }}'
OUT: '{{ .OUT | default "/tmp/clusterscope-{{.CLUSTER}}.pdf" }}'
preconditions:
- sh: '[ -n "{{.CLUSTER}}" ]'
msg: "CLUSTER is required (e.g. task pdf-export CLUSTER=my-cluster PORT=9090)"
cmds:
- echo "Exporting PDF for cluster '{{.CLUSTER}}' from http://localhost:{{.PORT}}/pdf/{{.CLUSTER}}"
- curl -sf http://localhost:{{.PORT}}/pdf/{{.CLUSTER}} -o {{.OUT}}
- echo "PDF saved to {{.OUT}}"
docs-serve:
desc: Serve MkDocs documentation locally
cmds:
- pip install mkdocs-material --quiet
- mkdocs serve
docs-build:
desc: Build MkDocs documentation to site/
cmds:
- pip install mkdocs-material --quiet
- mkdocs build
deploy:
desc: Deploy clusterscope to Kubernetes via KCL (profile file configurable)
vars:
PROFILE: '{{ .PROFILE | default "tests/kcl-deploy-profile.yaml" }}'
KUBECONFIG_PATH: '{{ .KUBECONFIG_PATH | default (env "KUBECONFIG") }}'
cmds:
- |
echo "Deploying clusterscope via KCL..."
echo " Profile : {{ .PROFILE }}"
echo " Kubeconfig: {{ .KUBECONFIG_PATH }}"
kcl run kcl/ -Y {{ .PROFILE }} | python3 -c "
import sys, yaml
data = yaml.safe_load(sys.stdin)
for m in data.get('manifests', []):
print('---')
print(yaml.dump(m, default_flow_style=False))
" | kubectl --kubeconfig "{{ .KUBECONFIG_PATH }}" apply -f -
echo "Deploy complete."
undeploy:
desc: Remove clusterscope deployment from Kubernetes
vars:
PROFILE: '{{ .PROFILE | default "tests/kcl-deploy-profile.yaml" }}'
KUBECONFIG_PATH: '{{ .KUBECONFIG_PATH | default (env "KUBECONFIG") }}'
cmds:
- |
echo "Removing clusterscope deployment..."
kcl run kcl/ -Y {{ .PROFILE }} | python3 -c "
import sys, yaml
data = yaml.safe_load(sys.stdin)
for m in data.get('manifests', []):
print('---')
print(yaml.dump(m, default_flow_style=False))
" | kubectl --kubeconfig "{{ .KUBECONFIG_PATH }}" delete --ignore-not-found -f -
echo "Undeploy complete."
deploy-kustomize:
desc: Deploy clusterscope via OCI Kustomize artifact + overlay
vars:
OCI_REPO: '{{ .OCI_REPO | default "ghcr.io/stuttgart-things/clusterscope-kustomize" }}'
OCI_TAG: '{{ .OCI_TAG | default "v0.6.0" }}'
OVERLAY: '{{ .OVERLAY | default "tests/kustomize-overlay" }}'
KUBECONFIG_PATH: '{{ .KUBECONFIG_PATH | default (env "KUBECONFIG") }}'
cmds:
- |
echo "Pulling OCI base {{ .OCI_REPO }}:{{ .OCI_TAG }}..."
rm -rf {{ .OVERLAY }}/base
mkdir -p {{ .OVERLAY }}/base
oras pull "{{ .OCI_REPO }}:{{ .OCI_TAG }}" -o "{{ .OVERLAY }}/base"
echo "Applying overlay..."
kubectl --kubeconfig "{{ .KUBECONFIG_PATH }}" apply -k "{{ .OVERLAY }}/"
echo "Deploy complete."
undeploy-kustomize:
desc: Remove clusterscope deployment deployed via Kustomize overlay
vars:
OCI_REPO: '{{ .OCI_REPO | default "ghcr.io/stuttgart-things/clusterscope-kustomize" }}'
OCI_TAG: '{{ .OCI_TAG | default "v0.6.0" }}'
OVERLAY: '{{ .OVERLAY | default "tests/kustomize-overlay" }}'
KUBECONFIG_PATH: '{{ .KUBECONFIG_PATH | default (env "KUBECONFIG") }}'
cmds:
- |
echo "Removing clusterscope deployment..."
if [ ! -d "{{ .OVERLAY }}/base" ]; then
mkdir -p {{ .OVERLAY }}/base
oras pull "{{ .OCI_REPO }}:{{ .OCI_TAG }}" -o "{{ .OVERLAY }}/base"
fi
kubectl --kubeconfig "{{ .KUBECONFIG_PATH }}" delete -k "{{ .OVERLAY }}/" --ignore-not-found
rm -rf {{ .OVERLAY }}/base
echo "Undeploy complete."
trigger-release:
desc: Re-run the publish build (image, kustomize, binaries) at a release tag (default: latest tag)
# Releases are cut by merging the release-please PR; this only republishes.
vars:
TAG:
sh: git describe --tags --abbrev=0
cmds:
- |
echo "Publishing {{ .TAG }}..."
gh workflow run build-scan-image.yaml --ref "{{ .TAG }}"
sleep 3
RUN_ID=$(gh run list --workflow=build-scan-image.yaml --branch "{{ .TAG }}" --limit=1 --json databaseId --jq '.[0].databaseId')
echo "Run: https://github.com/stuttgart-things/clusterscope/actions/runs/${RUN_ID}"
gh run watch "${RUN_ID}"
# === KCL Manifest Rendering ===
render-manifests:
desc: Render Kubernetes manifests using KCL via Dagger (interactive)
vars:
SOURCE:
sh: 'gum input --placeholder "Source directory" --value "{{ .KCL_SOURCE_DIR }}" --header "KCL SOURCE DIRECTORY"'
PROFILE:
sh: 'gum input --placeholder "Profile file path" --value "{{ .KCL_PROFILE_FILE }}" --header "PARAMETERS FILE"'
DESTINATION:
sh: 'gum input --placeholder "Output path" --value "{{ .RENDERED_OUTPUT_PATH }}" --header "OUTPUT PATH"'
cmds:
- |
echo "Rendering manifests with KCL..."
echo "Source: {{ .SOURCE }}"
echo "Profile: {{ .PROFILE }}"
echo "Output: {{ .DESTINATION }}"
dagger call -m {{ .DAGGER_KCL_MODULE }} run \
--source "{{ .SOURCE }}" \
--parameters-file="{{ .PROFILE }}" \
export --path="{{ .DESTINATION }}"
echo "Manifests rendered: {{ .DESTINATION }}"
if [ -f "{{ .DESTINATION }}" ]; then
head -n 20 "{{ .DESTINATION }}"
echo "... (cat {{ .DESTINATION }} for full file)"
fi
render-manifests-quick:
desc: Render Kubernetes manifests (non-interactive, uses defaults)
vars:
SOURCE: '{{ .SOURCE | default .KCL_SOURCE_DIR }}'
PROFILE: '{{ .PROFILE | default .KCL_PROFILE_FILE }}'
DESTINATION: '{{ .DESTINATION | default .RENDERED_OUTPUT_PATH }}'
cmds:
- |
dagger call -m {{ .DAGGER_KCL_MODULE }} run \
--source "{{ .SOURCE }}" \
--parameters-file="{{ .PROFILE }}" \
export --path="{{ .DESTINATION }}"
echo "Manifests rendered: {{ .DESTINATION }}"
render-kustomize-base:
desc: Render kustomize base from KCL deployment manifests
vars:
SOURCE: '{{ .SOURCE | default .KCL_SOURCE_DIR }}'
PROFILE: '{{ .PROFILE | default .KCL_PROFILE_FILE }}'
DESTINATION: '{{ .DESTINATION | default .KUSTOMIZE_BASE_EXPORT_PATH }}'
cmds:
- |
echo "Rendering kustomize base with KCL..."
dagger call -m {{ .DAGGER_KCL_MODULE }} render-kustomize-base \
--source "{{ .SOURCE }}" \
--parameters-file="{{ .PROFILE }}" \
export --path="{{ .DESTINATION }}" \
--progress plain
echo "Kustomize base rendered: {{ .DESTINATION }}"
ls -la "{{ .DESTINATION }}/"
push-kustomize-base:
desc: Render and push kustomize base as OCI artifact
vars:
SOURCE: '{{ .SOURCE | default .KCL_SOURCE_DIR }}'
PROFILE: '{{ .PROFILE | default .KCL_PROFILE_FILE }}'
TAG:
sh: 'gum input --placeholder "Enter version tag (e.g., v1.0.0)" --header "OCI TAG"'
cmds:
- |
echo "Pushing kustomize base as OCI artifact..."
echo "Target: {{ .KUSTOMIZE_OCI_REPO }}:{{ .TAG }}"
dagger call -m {{ .DAGGER_KCL_MODULE }} push-kustomize-base \
--source "{{ .SOURCE }}" \
--parameters-file="{{ .PROFILE }}" \
--address "{{ .KUSTOMIZE_OCI_REPO }}" \
--tag "{{ .TAG }}" \
--user env:GITHUB_USER \
--password env:GITHUB_TOKEN \
--progress plain
echo "OCI artifact pushed: {{ .KUSTOMIZE_OCI_REPO }}:{{ .TAG }}"
# === Release ===
release-local:
desc: Full release pipeline (local, interactive)
cmds:
- task: release:release-local
vars:
KCL_SOURCE_DIR: "{{ .KCL_SOURCE_DIR }}"
KCL_PROFILE_FILE: "{{ .KCL_PROFILE_FILE }}"
KUSTOMIZE_OCI_REPO: "{{ .KUSTOMIZE_OCI_REPO }}"
TARGET_IMAGE_REPO: "{{ .TARGET_IMAGE_REPO }}"
release-github:
desc: Full release pipeline (non-interactive, for CI)
cmds:
- task: release:release-github
vars:
KCL_SOURCE_DIR: "{{ .KCL_SOURCE_DIR }}"
KCL_PROFILE_FILE: "{{ .KCL_PROFILE_FILE }}"
KUSTOMIZE_OCI_REPO: "{{ .KUSTOMIZE_OCI_REPO }}"
TARGET_IMAGE_REPO: "{{ .TARGET_IMAGE_REPO }}"