This repository was archived by the owner on May 9, 2026. It is now read-only.
forked from agntcy/oasf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
407 lines (369 loc) · 12.3 KB
/
Copy pathTaskfile.yml
File metadata and controls
407 lines (369 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
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
version: "3"
## Load config from dotenv file
dotenv:
- '{{ .ROOT_DIR }}/.env'
## Collection of config params
vars:
## Image config
IMAGE_REPO: '{{ .IMAGE_REPO | default "ghcr.io/agntcy" }}'
IMAGE_TAG: '{{ .IMAGE_TAG }}'
## Dependency config
BIN_DIR: '{{ .ROOT_DIR }}/bin'
HELM_VERSION: '3.16.3'
HELM_BIN: '{{ .BIN_DIR }}/helm-{{.HELM_VERSION}}'
KUBECTL_VERSION: '1.31.3'
KUBECTL_BIN: '{{ .BIN_DIR }}/kubectl-{{.KUBECTL_VERSION}}'
KIND_VERSION: '0.25.0'
KIND_BIN: '{{ .BIN_DIR }}/kind-{{.KIND_VERSION}}'
PROTOC_VERSION: '27.1'
PROTOC_BIN: '{{ .BIN_DIR }}/protoc-{{.PROTOC_VERSION}}'
BUFBUILD_VERSION: '1.50.1'
BUFBUILD_BIN: '{{ .BIN_DIR }}/bufbuild-{{.BUFBUILD_VERSION}}'
## Set refresh interval for observable tasks like hot-reload
interval: 500ms
tasks:
##
## General
##
default:
cmds:
- task -l
build:
desc: Build project artifacts
cmds:
- task: build:charts
- task: build:server
build:charts:
desc: Build helm charts
deps:
- deps:helm
vars:
HELM_ALL_CHART_PATHS:
sh: find . -name Chart.yaml -exec dirname {} \;
cmds:
- for: {var: HELM_ALL_CHART_PATHS}
cmd: 'cd {{ .ITEM }} && {{ .HELM_BIN }} dependency update'
build:server:
desc: Build OASF server container image
vars:
BAKE_OPTS: '{{ .BAKE_OPTS | default (printf "--set *.platform=linux/%s" ARCH) }}'
cmds:
- docker buildx bake -f docker-bake.hcl oasf-server {{.BAKE_OPTS}}
up:
desc: Deploy services in an ephemeral kind cluster
preconditions:
- which yq
deps:
- deps:helm
- deps:kubectl
- deps:kind
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "test-oasf-cluster" }}'
KIND_CREATE_OPTS: '{{ .KIND_CREATE_OPTS | default "" }}'
KIND_CONFIG_PATH: '/tmp/{{.KIND_CLUSTER_NAME}}'
# Deployment args
HELM_NAMESPACE: '{{ .HELM_NAMESPACE | default "default" }}'
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/oasf'
HELM_VALUES_PATH: '{{ .HELM_VALUES_PATH | default (printf "%s/install/charts/oasf/values-test.yaml" .ROOT_DIR) }}'
LOG_LEVEL: '{{ .LOG_LEVEL | default "" }}'
RELEASE_NAME: 'oasf'
cmds:
# Clean up previous deployment
- task: down
# Create volume config to share between Kind and host
- |
cat <<EOF > {{.KIND_CONFIG_PATH}}
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
extraMounts:
- hostPath: {{ .ROOT_DIR }}/schema
containerPath: /schema
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 30080
hostPort: 8080
protocol: TCP
EOF
# Create ephemeral cluster
- '{{ .KIND_BIN }} create cluster {{ .KIND_CREATE_OPTS }} --name {{ .KIND_CLUSTER_NAME }} --config {{.KIND_CONFIG_PATH}}'
- '{{ .KIND_BIN }} export kubeconfig --name {{ .KIND_CLUSTER_NAME }}'
# Check cluster status
- '{{ .KUBECTL_BIN }} cluster-info'
# Extract images from values-test.yaml and load them into kind
- |
{{- if .IMAGE_TAG }}
{{ .KIND_BIN }} load docker-image "{{ .IMAGE_REPO }}/oasf-server:{{ .IMAGE_TAG }}" --name {{ .KIND_CLUSTER_NAME }}
{{- else }}
images=$(yq eval '.image.versions[].server' {{ .HELM_VALUES_PATH }})
echo "Images to load: $images"
echo "$images" | while read image; do
{{ .KIND_BIN }} load docker-image "{{ .IMAGE_REPO }}/oasf-server:$image" --name {{ .KIND_CLUSTER_NAME }}
done
{{- end }}
# Deploy chart
- |
{{ .HELM_BIN }} upgrade {{.RELEASE_NAME}} \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set image.repository="{{ .IMAGE_REPO }}/oasf-server" \
{{- if .LOG_LEVEL }}
--set env.LOG_LEVEL={{.LOG_LEVEL}} \
{{- end }}
{{- if .IMAGE_TAG }}
--set image.versions[0].server={{.IMAGE_TAG}} \
{{- end }}
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
# Wait for the ingress controller deployment to be available
- |
echo "Waiting for Deployment {{.RELEASE_NAME}}-ingress-controller in namespace {{.HELM_NAMESPACE}} to become available..."
if ! {{ .KUBECTL_BIN }} wait deployment/{{.RELEASE_NAME}}-ingress-controller \
--for=condition=Available \
-n {{ .HELM_NAMESPACE }} \
--timeout=120s; then
echo "Error: Deployment {{.RELEASE_NAME}}-ingress-controller did not become available within 120 seconds."
exit 1
fi
echo
echo "Deployment is available at http://localhost:8080."
reload:
desc: Hot reload schema changes after deployment
watch: true
deps:
- deps:kubectl
sources:
- 'schema/**/*'
vars:
LABEL_SELECTOR: 'default-schema=true'
preconditions:
- '{{ .KUBECTL_BIN }} get po -l {{.LABEL_SELECTOR}}'
cmds:
- |
POD_NAME=$({{ .KUBECTL_BIN }} get pods -l {{.LABEL_SELECTOR}} -o jsonpath="{.items[0].metadata.name}")
{{.KUBECTL_BIN}} exec $POD_NAME -- ./bin/schema_server rpc "Schema.reload()"
- echo "Reloaded schema! Use CTRL + C to exit."
down:
desc: Stop services and remove ephemeral kind cluster
deps:
- deps:kind
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "test-oasf-cluster" }}'
cmds:
- '{{ .KIND_BIN }} delete cluster --name {{ .KIND_CLUSTER_NAME }}'
test:
desc: Run all test suites
cmds:
- task: test:schema
- task: test:proto
- task: test:server
test:e2e:
desc: Deploy to an ephemeral kind cluster and verify the server starts healthy
cmds:
- defer: {task: down}
- task: up
- cmd: curl --retry 10 --retry-delay 3 --retry-connrefused --fail --silent http://localhost:8080/ > /dev/null
test:schema:
desc: Validate schema JSON files against their metaschemas
preconditions:
- which go
dir: '{{ .ROOT_DIR }}/schema/test'
cmds:
- cmd: echo "Validating schema files against metaschemas..."
- cmd: go test -v -count=1 ./...
test:proto:
desc: Test if protobuf files are in sync with the JSON schema
preconditions:
- which go
dir: '{{ .ROOT_DIR }}/proto/test'
cmds:
- cmd: echo "Checking proto ↔ JSON schema sync..."
- cmd: go test -v -count=1 ./...
test:server:
desc: Test server code (includes schema integrity, API, and unit tests)
preconditions:
- which mix
dir: '{{ .ROOT_DIR }}/server'
cmds:
- cmd: echo "Running OASF server test suite..."
- cmd: mix test
lint:
desc: Run all linters
cmds:
- task: lint:proto
- task: lint:charts
lint:proto:
desc: Run Proto linters
deps:
- task: deps:protoc
- task: deps:bufbuild
dir: ./proto
cmds:
- '{{.BUFBUILD_BIN}} dep update'
- '{{.BUFBUILD_BIN}} format --diff --exit-code'
- '{{.BUFBUILD_BIN}} lint'
lint:charts:
desc: Run Helm linters
deps:
- deps:helm
vars:
HELM_ALL_CHART_PATHS:
sh: find . -name Chart.yaml -exec dirname {} \;
cmds:
- for: {var: HELM_ALL_CHART_PATHS}
cmd: 'cd {{ .ITEM }} && {{ .HELM_BIN }} lint'
fmt:
desc: Run formatters
cmds:
- task: fmt:proto
- task: fmt:schema
- task: fmt:elixir
fmt:proto:
desc: Run Proto formatters
deps:
- task: deps:protoc
- task: deps:bufbuild
dir: ./proto
cmds:
- '{{.BUFBUILD_BIN}} dep update'
- '{{.BUFBUILD_BIN}} format --output ./'
fmt:schema:
desc: Run Schema formatters
preconditions:
- which jq
dir: ./schema
cmds:
- cmd: echo "Formatting all JSON files with jq..."
- cmd: |
find . -name "*.json" -type f | while read file; do
echo "Formatting $file..."
jq --indent 2 . "$file" > "$file.tmp" && mv "$file.tmp" "$file"
done
- cmd: echo "Formatting dictionary file with custom jq rules..."
- cmd: |
jq '.attributes |= (to_entries | sort_by(.key) | from_entries) | .types.attributes |= (to_entries | sort_by(.key) | from_entries)' dictionary.json > sorted.dictionary.json
mv sorted.dictionary.json dictionary.json
fmt:elixir:
desc: Run Elixir formatter on server/
dir: ./server
cmds:
- |
if ! command -v mix >/dev/null 2>&1; then
echo "mix not found, skipping Elixir formatting."
exit 0
fi
mix format
##
## Dependencies
##
deps:
desc: Install project dependencies
cmds:
- task: deps:helm
- task: deps:kubectl
- task: deps:kind
- task: deps:protoc
- task: deps:bufbuild
deps:bin-dir:
desc: Create bin directory
internal: true
run: once
cmd: mkdir -p {{.BIN_DIR}}
status:
- test -d {{.BIN_DIR}}
deps:helm:
desc: Ensure supported Helm version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which curl
- which tar
cmds:
- cmd: echo "Downloading Helm v{{.HELM_VERSION}}..."
- cmd: curl -sSfL 'https://get.helm.sh/helm-v{{.HELM_VERSION}}-{{OS}}-{{ARCH}}.tar.gz' --output - | tar xzvOf - '{{OS}}-{{ARCH}}/helm' > {{.HELM_BIN}}
- cmd: chmod +x {{.HELM_BIN}}
status:
- test -x {{.HELM_BIN}}
deps:kubectl:
desc: Ensure supported kubectl version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which curl
cmds:
- cmd: echo "Downloading Kubectl v{{.KUBECTL_VERSION}}..."
- cmd: curl -L "https://dl.k8s.io/release/v{{.KUBECTL_VERSION}}/bin/{{OS}}/{{ARCH}}/kubectl" -o {{.KUBECTL_BIN}}
- cmd: chmod +x {{.KUBECTL_BIN}}
status:
- test -x {{.KUBECTL_BIN}}
deps:kind:
desc: Ensure supported kind version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which go
cmds:
- cmd: echo "Downloading Kind v{{.KIND_VERSION}}..."
- cmd: GOBIN={{.BIN_DIR}} go install sigs.k8s.io/kind@v{{.KIND_VERSION}}
- cmd: mv {{.BIN_DIR}}/kind {{.KIND_BIN}}
status:
- test -x {{.KIND_BIN}}
deps:protoc:
desc: Ensure supported Protoc version and plugins are installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which go
- which curl
- which unzip
vars:
ARCH_TYPE: '{{ if eq ARCH "arm64" }}aarch_64{{ else if eq ARCH "amd64" }}x86_64{{else if eq ARCH "s390x"}}x390_64{{ else }}{{ARCH}}{{ end }}'
OS_VARIANT: '{{ if eq OS "darwin" }}osx-universal_binary{{ else if eq OS "windows" }}win64{{else}}linux-{{.ARCH_TYPE}}{{ end }}'
cmds:
- cmd: echo "Downloading Protoc v{{.PROTOC_VERSION}}..."
- cmd: |
curl -sL https://github.com/protocolbuffers/protobuf/releases/download/v{{.PROTOC_VERSION}}/protoc-{{.PROTOC_VERSION}}-{{.OS_VARIANT}}.zip -o {{.BIN_DIR}}/tmp.zip
unzip -j {{.BIN_DIR}}/tmp.zip "bin/protoc" -d {{.BIN_DIR}}
mv {{.BIN_DIR}}/protoc {{.PROTOC_BIN}}
rm {{.BIN_DIR}}/tmp.zip
- cmd: chmod +x {{.PROTOC_BIN}}
- cmd: echo "Downloading go plugins for protoc..."
- cmd: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
- cmd: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
- cmd: go install github.com/NathanBaulch/protoc-gen-cobra@latest
status:
- test -x {{.PROTOC_BIN}}
deps:bufbuild:
desc: Ensure supported bufbuild version is installed
internal: true
deps:
- deps:bin-dir
preconditions:
- which curl
vars:
ARCH_TYPE: '{{ if eq ARCH "amd64" }}x86_64{{ else }}{{ARCH}}{{ end }}'
cmds:
- cmd: echo "Downloading BufBuild v{{.BUFBUILD_VERSION}}..."
- cmd: |
curl -L "https://github.com/bufbuild/buf/releases/download/v{{.BUFBUILD_VERSION}}/buf-{{OS}}-{{.ARCH_TYPE}}" -o {{.BUFBUILD_BIN}}
- cmd: chmod +x {{.BUFBUILD_BIN}}
status:
- test -x {{.BUFBUILD_BIN}}