-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTaskfile.yml
More file actions
321 lines (286 loc) · 10 KB
/
Taskfile.yml
File metadata and controls
321 lines (286 loc) · 10 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
version: '3'
vars:
CONTAINER_RUNTIME:
sh: |
if command -v podman >/dev/null 2>&1; then
echo "podman"
else
echo "docker"
fi
REPO: '{{.REPO | default "ghcr.io/stacklok/toolhive-registry-server"}}'
tasks:
docs:
desc: Regenerate the registry API documentation
vars:
SWAG_OUTPUT_DIR: '{{.SWAG_OUTPUT_DIR | default "docs/thv-registry-api"}}'
cmds:
- rm -rf docs/cli/*
- go run cmd/help/main.go --dir docs/cli
# NOTE: check out .swaggo file in the root of the project
# NOTE: We suppress the output to avoid "go/build" messages, it might
# drop messages we care about.
- |
swag init -q -g cmd/thv-registry-api/docs.go \
--v3.1 --output {{.SWAG_OUTPUT_DIR}} \
--parseDependencyLevel 1 2>/dev/null
helm-docs:
desc: Generate Helm chart documentation
cmds:
- command -v helm-docs >/dev/null 2>&1 || go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
- helm-docs --chart-search-root=deploy/charts
install-sqlc:
desc: Install the sqlc tool for generating database code
cmds:
- go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
install-swagger:
desc: Install the swag tool for OpenAPI/Swagger generation
cmds:
- go install github.com/swaggo/swag/v2/cmd/swag@latest
install-mock:
desc: Install the mockgen tool for mock generation
status:
- which mockgen
cmds:
- go install go.uber.org/mock/mockgen@latest
install-codegen:
desc: Install tools needed for code generation
deps:
- install-mock
- install-sqlc
install-gotestfmt:
desc: Install the gotestfmt tool for test output formatting
cmds:
- go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
install-golangci-lint:
desc: Install the golangci-lint tool for linting
status:
- which golangci-lint
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
install-deadcode:
desc: Install the deadcode tool for checking for unused code
cmds:
- go install golang.org/x/tools/cmd/deadcode@latest
install-ko:
desc: Install the ko tool for building container images
cmds:
- go install github.com/google/ko@latest
install-dev-deps:
desc: Install the development dependencies
deps:
- install-gotestfmt
- install-codegen
- install-swagger
- install-golangci-lint
- install-deadcode
- install-ko
gen:
desc: Run code generation tasks
deps:
- task: install-codegen
silent: true
cmds:
- go generate ./...
- sqlc generate
deadcode:
desc: Run deadcode tool for checking for unused code
deps:
- task: install-deadcode
silent: true
cmds:
- cmd: |
output=$(deadcode -test ./...)
if test -z "$output"; then
echo "✅ No unused code found"
else
echo "❌ Unused code found"
echo $output
exit 1
fi
silent: true
lint:
desc: Run linting tools
deps:
- task: gen
silent: true
- task: install-golangci-lint
silent: true
- task: install-deadcode
silent: true
- task: deadcode
cmds:
- golangci-lint run --allow-parallel-runners ./...
- go vet ./...
lint-fix:
desc: Run linting tools, and apply fixes.
deps:
- task: gen
silent: true
- task: install-golangci-lint
silent: true
- task: install-deadcode
silent: true
- task: deadcode
cmds:
- golangci-lint run --allow-parallel-runners --fix ./...
build:
desc: Build the registry API binary
cmds:
- go build -o bin/thv-registry-api ./cmd/thv-registry-api
build-image:
desc: Build the registry API image with ko
deps:
- task: install-ko
silent: true
env:
KO_DOCKER_REPO: '{{.REPO}}'
cmds:
- ko build --local -B ./cmd/thv-registry-api
build-image-ubi:
desc: Build the registry API image with UBI base image
vars:
COMMIT:
sh: git rev-parse --short HEAD || echo "unknown"
BUILD_DATE: '{{dateInZone "2006-01-02T15:04:05Z" (now) "UTC"}}'
SHA:
sh: git rev-parse HEAD || echo "unknown"
PLATFORM:
sh: echo "${PLATFORM:-linux/$(go env GOARCH)}"
cmds:
- |
{{.CONTAINER_RUNTIME}} build --platform={{.PLATFORM}} --load \
-t {{.REPO}}:{{.SHA}}-ubi \
--build-arg VERSION={{.SHA}}-ubi \
--build-arg COMMIT={{.COMMIT}} \
--build-arg BUILD_DATE={{.BUILD_DATE}} \
--label name="toolhive-registry-api" \
--label vendor="Stacklok" \
--label maintainer="Stacklok" .
test:
desc: Run registry API tests
deps:
- task: install-gotestfmt
silent: true
cmds:
# We have to use ldflags to avoid the LC_DYSYMTAB linker warning.
- go test -count 1 -ldflags=-extldflags=-Wl,-w -race -json ./... | gotestfmt -hide "all"
test-coverage:
desc: Run registry API tests with coverage
deps:
- task: install-gotestfmt
silent: true
cmds:
# We have to use ldflags to avoid the LC_DYSYMTAB linker warning.
- go test -count 1 -ldflags=-extldflags=-Wl,-w -race -json -coverprofile=coverage.out ./... | gotestfmt -hide "all"
- go tool cover -func=coverage.out
- echo "Generating HTML coverage report in coverage.html"
- go tool cover -html=coverage.out -o coverage.html
all:
desc: Run linting, tests, and build
deps: [lint, test-coverage, build]
migrate-up:
desc: Run database migrations (requires CONFIG variable)
cmds:
- |
if [ -z "{{.CONFIG}}" ]; then
echo "Error: CONFIG variable is required. Usage: task migrate-up CONFIG=path/to/config.yaml"
exit 1
fi
go run ./cmd/thv-registry-api migrate up --config {{.CONFIG}} --yes
migrate-down:
desc: Revert database migrations (requires CONFIG and NUM_STEPS variables)
cmds:
- |
if [ -z "{{.CONFIG}}" ]; then
echo "Error: CONFIG variable is required. Usage: task migrate-down CONFIG=path/to/config.yaml NUM_STEPS=1"
exit 1
fi
if [ -z "{{.NUM_STEPS}}" ]; then
echo "Error: NUM_STEPS variable is required for safety. Usage: task migrate-down CONFIG=path/to/config.yaml NUM_STEPS=1"
exit 1
fi
go run ./cmd/thv-registry-api migrate down --config {{.CONFIG}} --num-steps {{.NUM_STEPS}} --yes
docker-up:
desc: Start docker compose with fresh state (rebuilds image, clears all volumes)
cmds:
- echo "Stopping and removing all containers and volumes..."
- docker compose down -v
- echo "Building fresh image and starting services..."
- docker compose up --build
docker-up-detached:
desc: Start docker compose in detached mode with fresh state
cmds:
- echo "Stopping and removing all containers and volumes..."
- docker compose down -v
- echo "Building fresh image and starting services in background..."
- docker compose up --build -d
- echo "Services started. View logs with task docker-logs"
docker-down:
desc: Stop docker compose and remove all containers and volumes
cmds:
- docker compose down -v
docker-logs:
desc: View docker compose logs (use FOLLOW=true for tail -f behavior)
cmds:
- |
if [ "{{.FOLLOW}}" = "true" ]; then
docker compose logs -f
else
docker compose logs
fi
# =============================================================================
# Kind Cluster Tasks
# =============================================================================
kind-setup:
desc: Create a kind cluster for local development
vars:
CLUSTER_NAME: '{{.CLUSTER_NAME | default "thv-registry"}}'
cmds:
- |
if kind get clusters 2>/dev/null | grep -q "^{{.CLUSTER_NAME}}$"; then
echo "Cluster '{{.CLUSTER_NAME}}' already exists"
else
kind create cluster --name {{.CLUSTER_NAME}}
fi
- kind get kubeconfig --name {{.CLUSTER_NAME}} > kconfig.yaml
kind-destroy:
desc: Delete the kind cluster
vars:
CLUSTER_NAME: '{{.CLUSTER_NAME | default "thv-registry"}}'
cmds:
- kind delete cluster --name {{.CLUSTER_NAME}}
- rm -f kconfig.yaml
registry-server-install-latest:
desc: Install latest built registry server image from Github to the K8s cluster
cmds:
- helm upgrade --install toolhive-registry-server deploy/charts/toolhive-registry-server --namespace toolhive-system --create-namespace --kubeconfig kconfig.yaml
registry-server-install-local:
desc: Build the ToolHive Registry Server image locally and install it to the K8s cluster.
vars:
CLUSTER_NAME: '{{.CLUSTER_NAME | default "thv-registry"}}'
REGISTRY_SERVER_IMAGE:
sh: KO_DOCKER_REPO=kind.local ko build --local -B ./cmd/thv-registry-api | tail -n 1
cmds:
- echo "Loading toolhive-registry-server image {{.REGISTRY_SERVER_IMAGE}} into kind..."
- kind load docker-image {{.REGISTRY_SERVER_IMAGE}} --name {{.CLUSTER_NAME}}
- |
helm upgrade --install toolhive-registry-server deploy/charts/toolhive-registry-server \
--namespace toolhive-system \
--create-namespace \
--kubeconfig kconfig.yaml \
--set image.registryServerUrl={{.REGISTRY_SERVER_IMAGE}} \
--set image.pullPolicy=Never
kind-with-registry-server*:
desc: Create kind cluster and deploy registry server
vars:
REGISTRY_SERVER_INSTALL: '{{index .MATCH 0 | trimPrefix "-" | default "latest"}}'
cmds:
- task: kind-setup
- task: registry-server-install-{{.REGISTRY_SERVER_INSTALL}}
registry-server-uninstall:
desc: Uninstall registry server from kind
vars:
CLUSTER_NAME: '{{.CLUSTER_NAME | default "thv-registry"}}'
NAMESPACE: '{{.NAMESPACE | default "thv-registry"}}'
cmds:
- helm uninstall toolhive-registry-server --namespace {{.NAMESPACE}} --kubeconfig kconfig.yaml