-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
427 lines (367 loc) · 12.3 KB
/
Taskfile.yml
File metadata and controls
427 lines (367 loc) · 12.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
version: "3"
vars:
BINARY_NAME: mini-ledger
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo "unknown"
BUILD_TIME:
sh: date -u '+%Y-%m-%d_%H:%M:%S'
LDFLAGS: '-ldflags "-X main.Version={{.VERSION}} -X main.Commit={{.COMMIT}} -X main.BuildTime={{.BUILD_TIME}} -w -s"'
# Docker/Registry settings
DOCKER_REGISTRY: '{{.DOCKER_REGISTRY | default "ghcr.io/willejs"}}'
LOCAL_REGISTRY: '{{.LOCAL_REGISTRY | default "localhost:5050"}}'
IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}'
# OCI artifact settings
OCI_REGISTRY: "localhost:5050"
OCI_ARTIFACT: "oci://{{.OCI_REGISTRY}}/platform-k8s"
OCI_TAG: '{{.OCI_TAG | default "development"}}'
tasks:
default:
desc: Show available tasks
cmds:
- task --list
# === Prerequisites Check ===
check:
desc: Check all prerequisites are installed
silent: false
cmds:
- |
echo "🔍 Checking prerequisites..."
echo ""
missing=0
# Check Go
if command -v go &> /dev/null; then
echo "✅ Go $(go version | awk '{print $3}')"
else
echo "❌ Go - MISSING (install: brew install go)"
missing=$((missing + 1))
fi
# Check Docker
if command -v docker &> /dev/null; then
echo "✅ Docker $(docker --version | awk '{print $3}' | tr -d ',')"
else
echo "❌ Docker - MISSING (install: brew install docker)"
missing=$((missing + 1))
fi
# Check kubectl
if command -v kubectl &> /dev/null; then
echo "✅ kubectl $(kubectl version --client --short 2>/dev/null | awk '{print $3}' || echo 'installed')"
else
echo "❌ kubectl - MISSING (install: brew install kubectl)"
missing=$((missing + 1))
fi
# Check kind
if command -v kind &> /dev/null; then
echo "✅ kind $(kind version | awk '{print $2}')"
else
echo "❌ kind - MISSING (install: brew install kind)"
missing=$((missing + 1))
fi
# Check ctlptl
if command -v ctlptl &> /dev/null; then
echo "✅ ctlptl $(ctlptl version 2>/dev/null | head -1 | awk '{print $2}' || echo 'installed')"
else
echo "❌ ctlptl - MISSING (install: brew install tilt-dev/tap/ctlptl)"
missing=$((missing + 1))
fi
# Check Tilt
if command -v tilt &> /dev/null; then
echo "✅ Tilt $(tilt version 2>/dev/null | head -1 | awk '{print $2}' || echo 'installed')"
else
echo "❌ Tilt - MISSING (install: brew install tilt-dev/tap/tilt)"
missing=$((missing + 1))
fi
# Check Helm
if command -v helm &> /dev/null; then
echo "✅ Helm $(helm version --short 2>/dev/null | awk '{print $1}' || echo 'installed')"
else
echo "❌ Helm - MISSING (install: brew install helm)"
missing=$((missing + 1))
fi
# Check Flux CLI
if command -v flux &> /dev/null; then
echo "✅ Flux CLI $(flux version --client 2>/dev/null | grep 'flux:' | awk '{print $2}' || echo 'installed')"
else
echo "❌ Flux CLI - MISSING (install: brew install fluxcd/tap/flux)"
missing=$((missing + 1))
fi
# Check jq (used in Tiltfile)
if command -v jq &> /dev/null; then
echo "✅ jq $(jq --version)"
else
echo "❌ jq - MISSING (install: brew install jq)"
missing=$((missing + 1))
fi
# Check golangci-lint (optional but recommended)
if command -v golangci-lint &> /dev/null; then
echo "✅ golangci-lint $(golangci-lint version --format short 2>/dev/null || echo 'installed')"
else
echo "⚠️ golangci-lint - OPTIONAL (install: brew install golangci-lint)"
fi
# Check oapi-codegen (optional)
if command -v oapi-codegen &> /dev/null; then
echo "✅ oapi-codegen $(oapi-codegen --version 2>/dev/null || echo 'installed')"
else
echo "⚠️ oapi-codegen - OPTIONAL (install: go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest)"
fi
echo ""
if [ $missing -eq 0 ]; then
echo "✅ All required prerequisites are installed!"
exit 0
else
echo "❌ $missing required tool(s) missing. Please install them before continuing."
echo ""
echo "Quick install (macOS):"
echo " brew install go docker kubectl kind helm jq tilt-dev/tap/tilt tilt-dev/tap/ctlptl fluxcd/tap/flux"
echo ""
echo "Optional tools:"
echo " brew install golangci-lint"
echo " go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest"
exit 1
fi
# === Code Generation ===
generate:
desc: Generate OpenAPI code from spec
cmds:
- echo "Generating OpenAPI code..."
- oapi-codegen --config=api/openapi/oapi-codegen.yaml api/openapi/ledger.openapi.yaml
sources:
- api/openapi/**/*.yaml
generates:
- internal/adapter/http/openapi_*.go
proto:
desc: Generate protobuf code
cmds:
- echo "Generating protobuf files..."
- protoc --go_out=. --go_opt=paths=source_relative
--go-grpc_out=. --go-grpc_opt=paths=source_relative
api/proto/ledger/v1/ledger.proto
sources:
- api/proto/**/*.proto
# === Build ===
build:
desc: Build all binaries
deps: [build:ledger, build:projector]
build:ledger:
desc: Build ledger service binary
cmds:
- echo "Building ledger service..."
- CGO_ENABLED=0 go build {{.LDFLAGS}} -o bin/ledger ./cmd/ledger
sources:
- cmd/ledger/**/*.go
- internal/**/*.go
- pkg/**/*.go
- go.{mod,sum}
generates:
- bin/ledger
build:projector:
desc: Build projector service binary
cmds:
- echo "Building projector service..."
- CGO_ENABLED=0 go build {{.LDFLAGS}} -o bin/projector ./cmd/projector
sources:
- cmd/projector/**/*.go
- internal/**/*.go
- pkg/**/*.go
- go.{mod,sum}
generates:
- bin/projector
# === Docker ===
docker:build:
desc: Build Docker image for mini-ledger
vars:
REGISTRY: "{{.REGISTRY | default .LOCAL_REGISTRY}}"
TAG: "{{.TAG | default .IMAGE_TAG}}"
cmds:
- echo "Building Docker image {{.REGISTRY}}/mini-ledger:{{.TAG}}..."
- docker build -t {{.REGISTRY}}/mini-ledger:{{.TAG}} .
sources:
- Dockerfile
- cmd/**/*.go
- internal/**/*.go
- pkg/**/*.go
- migrations/**/*.sql
- go.{mod,sum}
docker:push:
desc: Push Docker image
vars:
REGISTRY: "{{.REGISTRY | default .LOCAL_REGISTRY}}"
TAG: "{{.TAG | default .IMAGE_TAG}}"
deps: [docker:build]
cmds:
- echo "Pushing {{.REGISTRY}}/mini-ledger:{{.TAG}}..."
- docker push {{.REGISTRY}}/mini-ledger:{{.TAG}}
docker:e2e:build:
desc: Build E2E test Docker image
vars:
REGISTRY: "{{.REGISTRY | default .LOCAL_REGISTRY}}"
TAG: "{{.TAG | default .IMAGE_TAG}}"
cmds:
- echo "Building E2E test image {{.REGISTRY}}/mini-ledger-e2e:{{.TAG}}..."
- docker build -f Dockerfile.e2e -t {{.REGISTRY}}/mini-ledger-e2e:{{.TAG}} .
sources:
- Dockerfile.e2e
- test/**/*.go
- internal/**/*.go
- pkg/**/*.go
- go.{mod,sum}
docker:e2e:push:
desc: Push E2E test Docker image
vars:
REGISTRY: "{{.REGISTRY | default .LOCAL_REGISTRY}}"
TAG: "{{.TAG | default .IMAGE_TAG}}"
deps: [docker:e2e:build]
cmds:
- echo "Pushing {{.REGISTRY}}/mini-ledger-e2e:{{.TAG}}..."
- docker push {{.REGISTRY}}/mini-ledger-e2e:{{.TAG}}
# === Testing ===
test:
desc: Run all tests with coverage
cmds:
- echo "Running tests..."
- go test -v -race -coverprofile=coverage.out ./...
test:short:
desc: Run short tests (unit tests only)
cmds:
- echo "Running short tests..."
- go test -v -short ./...
test:integration:
desc: Run integration tests
cmds:
- echo "Running integration tests..."
- go test -v -tags=integration ./...
test:e2e:
desc: Run E2E tests against running service
cmds:
- echo "Running E2E tests..."
- go test -v -run TestE2E ./test/e2e
test:e2e:k8s:
desc: Run E2E tests in Kubernetes
cmds:
- echo "🧪 Running E2E tests in Kubernetes..."
- kubectl delete job mini-ledger-e2e -n mini-ledger --ignore-not-found=true
- kubectl apply -k deploy/components/test
- |
echo "⏳ Waiting for test job to complete..."
if kubectl wait --for=condition=complete --timeout=300s job/mini-ledger-e2e -n mini-ledger 2>/dev/null; then
echo "✅ Tests passed!"
kubectl logs -n mini-ledger job/mini-ledger-e2e --tail=-1
elif kubectl wait --for=condition=failed --timeout=5s job/mini-ledger-e2e -n mini-ledger 2>/dev/null; then
echo "❌ Tests failed!"
kubectl logs -n mini-ledger job/mini-ledger-e2e --tail=-1
exit 1
else
echo "❌ Test job timeout or error"
kubectl logs -n mini-ledger job/mini-ledger-e2e --tail=-1 2>/dev/null || echo "No logs available"
exit 1
fi
test:coverage:
desc: Generate HTML coverage report
cmds:
- echo "Generating coverage report..."
- go test -coverprofile=coverage.out ./...
- go tool cover -html=coverage.out -o coverage.html
- echo "Coverage report generated at coverage.html"
# === Linting ===
lint:
desc: Run golangci-lint
cmds:
- echo "Running linter..."
- golangci-lint run ./...
lint:fix:
desc: Run linter with auto-fix
cmds:
- echo "Running linter with auto-fix..."
- golangci-lint run --fix ./...
# === Local Development ===
run:ledger:
desc: Build and run ledger service
deps: [build:ledger]
cmds:
- echo "Running ledger service..."
- ./bin/ledger
run:projector:
desc: Build and run projector service
deps: [build:projector]
cmds:
- echo "Running projector service..."
- ./bin/projector
# === Kubernetes / GitOps ===
k8s:up:
desc: Create Kind cluster and start Tilt
deps: [check]
cmds:
- echo "Creating Kind cluster with registry..."
- ctlptl apply -f ctlptl.yaml
- echo "Starting Tilt (bootstraps Flux + GitOps)..."
- tilt up
k8s:down:
desc: Stop Tilt
cmds:
- echo "Stopping Tilt..."
- tilt down
k8s:delete:
desc: Delete Kind cluster and registry
cmds:
- echo "Deleting Kind cluster..."
- ctlptl delete -f ctlptl.yaml || true
flux:push:
desc: Push deploy manifests as OCI artifact to registry
cmds:
- echo "Pushing OCI artifact to {{.OCI_ARTIFACT}}:{{.OCI_TAG}}..."
- |
flux push artifact {{.OCI_ARTIFACT}}:{{.OCI_TAG}} \
--path=./deploy \
--source=local \
--revision="$(git rev-parse --short HEAD 2>/dev/null || echo 'dev')"
sources:
- deploy/**/*.yaml
flux:reconcile:
desc: Force Flux to reconcile all resources
cmds:
- echo "Reconciling Flux resources..."
- flux reconcile source oci platform-k8s
- flux reconcile kustomization platform-dependencies platform services
flux:status:
desc: Show Flux status
cmds:
- echo "=== Flux Sources ==="
- flux get sources oci -A
- echo ""
- echo "=== Flux Kustomizations ==="
- flux get kustomizations -A
- echo ""
- echo "=== Helm Releases ==="
- flux get helmreleases -A
# === Database ===
migrate:create:
desc: Create a new migration file
cmds:
- |
echo "Enter migration name:"
read name
migrate create -ext sql -dir ./migrations -seq "$name"
# === Dependencies ===
deps:
desc: Download Go dependencies
cmds:
- echo "Downloading dependencies..."
- go mod download
deps:tidy:
desc: Tidy Go dependencies
cmds:
- echo "Tidying dependencies..."
- go mod tidy
deps:verify:
desc: Verify Go dependencies
cmds:
- echo "Verifying dependencies..."
- go mod verify
# === Cleanup ===
clean:
desc: Clean build artifacts
cmds:
- echo "Cleaning build artifacts..."
- rm -rf bin/
- rm -f coverage.out coverage.html