forked from agntcy/dir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
1482 lines (1348 loc) · 50.3 KB
/
Taskfile.yml
File metadata and controls
1482 lines (1348 loc) · 50.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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
version: '3'
vars:
## Version
RELEASE_VERSION:
sh: grep 'version:' versions.yaml | awk '{print $2}'
RELEASE_VERSION_LDFLAG: "-X 'github.com/agntcy/dir/api/version.Version={{ .RELEASE_VERSION }}'"
COMMIT_SHA:
sh: git rev-parse --short HEAD
COMMIT_SHA_LDFLAG: "-X 'github.com/agntcy/dir/api/version.CommitHash={{ .COMMIT_SHA }}'"
VERSION_LDFLAGS: '{{ .RELEASE_VERSION_LDFLAG }} {{ .COMMIT_SHA_LDFLAG }}'
## Image config
IMAGE_REPO: '{{ .IMAGE_REPO | default "ghcr.io/agntcy" }}'
IMAGE_TAG: '{{ .IMAGE_TAG | default .COMMIT_SHA }}'
IMAGE_BAKE_ENV: 'IMAGE_REPO={{.IMAGE_REPO}} IMAGE_TAG={{.IMAGE_TAG}}'
IMAGE_BAKE_OPTS: '{{ .IMAGE_BAKE_OPTS | default "" }}'
BAKE_ENV: '{{ .IMAGE_BAKE_ENV }} EXTRA_LDFLAGS="{{.VERSION_LDFLAGS}}"'
## Dependency config
BIN_DIR: '{{ .ROOT_DIR }}/bin'
DIRCTL_BIN: '{{ .BIN_DIR}}/dirctl'
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}}'
GO_VERSION: '1.24.5'
MULTIMOD_VERSION: '0.17.0'
MULTIMOD_BIN: '{{ .BIN_DIR }}/multimod-{{.MULTIMOD_VERSION}}'
GOLANGCI_LINT_VERSION: '1.64.7'
GOLANGCI_LINT_BIN: '{{ .BIN_DIR }}/golangci-lint-{{.GOLANGCI_LINT_VERSION}}'
LICENSEI_VERSION: '0.9.0'
LICENSEI_BIN: '{{ .BIN_DIR }}/licensei-{{.LICENSEI_VERSION}}'
UV_VERSION: '0.6.1'
UV_BIN: '{{ .BIN_DIR }}/uv-{{.UV_VERSION}}'
UV_PUBLISH_TOKEN: '{{ .UV_PUBLISH_TOKEN | default "" }}'
COSIGN_VERSION: '2.5.3'
COSIGN_BIN: '{{ .BIN_DIR }}/cosign-{{.COSIGN_VERSION}}'
HUB_API_VERSION: 'main'
HUB_REPO_URL: 'https://github.com/cisco-eti/phoenix-saas-be.git'
ZOT_VERSION: '2.1.8'
tasks:
##
## General
##
default:
cmds:
- task -l
gen:
desc: Generate code for all components
cmds:
- task: api:gen
- task: helm:gen
check:
desc: Checks for all code violations
cmds:
- task: lint
- task: license
build:
desc: Build images for all components
deps:
- task: deps:tidy
- task: gen
vars:
GOARCH: '{{ .GOARCH | default ARCH }}'
cmds:
- '{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/{{.GOARCH}}'
build:all:
desc: Build images for all components for multiple platforms
cmds:
- '{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/amd64,linux/arm64'
pull:
desc: Pull images for all components
cmds:
- |
images=$({{.BAKE_ENV}} docker buildx bake default --print | jq -r '.target | with_entries(.value |= .tags[0]) | to_entries[] | .value')
echo "$images" | while read image; do
echo "Pulling image: $image"
docker pull $image
done
push:
desc: Build and push images for all components
prompt:
- Are you sure you want to push the images to remote registry?
cmds:
- '{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set=*.output=type=registry'
release:verify:
desc: Verify release readiness
deps:
- task: deps:multimod-bin
cmds:
- '{{ .MULTIMOD_BIN }} verify'
release:prepare:
desc: Prepare release
deps:
- task: deps:multimod-bin
cmds:
- '{{ .MULTIMOD_BIN }} prerelease --all-module-sets --skip-go-mod-tidy=true --commit-to-different-branch=false'
##
## API
##
api:gen:
desc: Generates API stubs
dir: ./proto
deps:
- task: deps:protoc
- task: deps:bufbuild
# NOTE(ramizpolic): This allows Taskfile YAML parsing to accept '{' as a starting command token.
# In translation, this is interpreted as a regular multi-line shell script.
cmd: |
{{.BUFBUILD_BIN}} dep update
{{.BUFBUILD_BIN}} generate
api:clean:
desc: Clean generated API stubs
deps:
- api:clean:go
api:clean:go:
desc: Clean generated golang API stubs
dir: ./api
cmds:
- find . \( -name "*.pb.go" \) -type f -delete
api:test:
desc: Unit test API code
vars:
EXTRA_ARGS: '{{ .EXTRA_ARGS | default "" }}'
cmds:
- EXTRA_ARGS="{{.EXTRA_ARGS}}" task api:test:go
api:test:go:
desc: Unit test Go API code
vars:
EXTRA_ARGS: '{{ .EXTRA_ARGS | default "" }}'
dir: ./api
cmds:
- go -C . test ./... {{.EXTRA_ARGS}}
##
## CLI
##
cli:compile:
desc: Compile CLI binaries
dir: ./cli
vars:
GOOS: '{{ .GOOS | default OS }}'
GOARCH: '{{ .GOARCH | default ARCH }}'
BINARY_NAME: '{{ .BINARY_NAME | default "dirctl" }}'
OUT_BINARY: '{{ if eq OS "windows" }}{{ .ROOT_DIR }}\\bin\\{{ .BINARY_NAME }}.exe{{ else }}{{ .ROOT_DIR }}/bin/{{ .BINARY_NAME }}{{ end }}'
LDFLAGS: '-s -w -extldflags -static {{ .VERSION_LDFLAGS }}'
cmds:
- CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -ldflags="{{ .LDFLAGS }}" -o "{{.OUT_BINARY}}" cli.go
cli:compile:all:
desc: Compile CLI client binaries for multiple platforms
aliases: [compile]
cmds:
- for:
matrix:
OS: ['linux', 'darwin', 'windows']
ARCH: ['amd64', 'arm64']
cmd: |
# Skip unsupported combinations (e.g., Windows ARM64)
if [ "{{.ITEM.OS}}" = "windows" ] && [ "{{.ITEM.ARCH}}" = "arm64" ]; then
echo "Skipping unsupported platform: {{.ITEM.OS}}/{{.ITEM.ARCH}}"
else
GOOS={{.ITEM.OS}} GOARCH={{.ITEM.ARCH}} BINARY_NAME=dirctl-{{.ITEM.OS}}-{{.ITEM.ARCH}} task cli:compile
fi
cli:test:
desc: Unit test CLI code
dir: ./cli
cmds:
- go -C . test ./... {{.EXTRA_ARGS}}
##
## Client SDK
##
client:test:
desc: Unit test Client code
vars:
EXTRA_ARGS: '{{ .EXTRA_ARGS | default "" }}'
cmds:
- EXTRA_ARGS="{{.EXTRA_ARGS}}" task client:test:go
client:test:go:
desc: Unit test Go Client code
dir: ./client
vars:
EXTRA_ARGS: '{{ .EXTRA_ARGS | default "" }}'
cmds:
- go -C . test ./... {{.EXTRA_ARGS}}
sdk:deps:common:
desc: Common dependencies for SDKs
cmds:
- task: deps:cosign
- task: cli:compile
- task: sdk:deps:javascript
sdk:deps:cicd:iodc-token-generation:
desc: Get Fulcio OIDC token for CICD
requires:
vars: [CLIENT_ID]
cmds:
- |
OIDC_TOKEN=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sigstore" | jq -r '.value')
CLIENT_ID="{{.CLIENT_ID}}"
PROVIDER_URL="https://token.actions.githubusercontent.com"
echo "OIDC_PROVIDER_URL=${PROVIDER_URL}"
echo "CLIENT_ID=${CLIENT_ID}"
echo "OIDC_TOKEN=${OIDC_TOKEN}"
sdk:build:all:
desc: Build all client SDK package
cmds:
- task: sdk:build:javascript
- task: sdk:build:python
sdk:build:python:
desc: Build python client SDK package
dir: ./sdk/dir-py
deps:
- task: deps:uv
cmds:
- '{{.UV_BIN}} build'
sdk:build:javascript:
desc: Build javascript client SDK package
dir: ./sdk/dir-js
cmds:
- npm run build
sdk:test-env:create:
desc: Create Kubernetes cluster test environment
cmds:
- task: deploy:kubernetes:network
vars:
PUBLICATION_SCHEDULER_INTERVAL: 1s
- task: deploy:kubernetes:network:port-forward
sdk:test-env:delete:
desc: Delete Kubernetes cluster test environment
cmds:
- task: deploy:kubernetes:network:port-forward:cleanup
- task: deploy:kubernetes:network:cleanup
sdk:test-env:spiffe:load-test-image:
desc: Load the SDK tests into KinD
cmds:
- '{{.BAKE_ENV}} docker buildx bake sdks-test {{.IMAGE_BAKE_OPTS}}'
- '{{.KUBECTL_BIN}} config use-context kind-dir.example'
- '{{.KIND_BIN}} load docker-image ghcr.io/agntcy/sdks-test:{{.IMAGE_TAG}} --name dir.example'
sdk:test:all:spiffe:
desc: Test all client SDK pacakges with spiffe
dir: ./e2e/sdk
cmds:
- '{{.KUBECTL_BIN}} config use-context kind-dir.example'
- '{{.HELM_BIN}} uninstall sdk-tests --wait --keep-history --ignore-not-found > /dev/null || true'
- '{{.HELM_BIN}} install --replace --timeout 1m --wait --wait-for-jobs sdk-tests ./chart -f chart/values.yaml --set image.tag={{.IMAGE_TAG}} > /dev/null || true'
- |
status=$({{.KUBECTL_BIN}} get job sdks-test -o jsonpath='{.status.conditions[0].type}')
status_value=$({{.KUBECTL_BIN}} get job sdks-test -o jsonpath='{.status.conditions[0].status}')
if [[ "$status" == "SuccessCriteriaMet" ]] && [[ "$status_value" == "True" ]]; then
echo "SDKs test are finished successfully! ✅"
exit 0
fi
if [[ "$status" == "FailureTarget" ]] && [[ "$status_value" == "True" ]]; then
{{.KUBECTL_BIN}} logs jobs/sdks-test
echo "SDKs test are failed! ❎"
exit 1
fi
echo "Unknown error happend, check logs! ⚠️"
exit 1
sdk:test:all:
desc: Test all client SDK packages
ignore_error: true
cmds:
- task: sdk:test:javascript
- task: sdk:test:python
sdk:test:python:
desc: Test python client SDK package
dir: ./sdk/dir-py
deps:
- task: deps:uv
env:
DIRECTORY_CLIENT_SERVER_ADDRESS: '0.0.0.0:8890'
DIRECTORY_SERVER_PEER1_ADDRESS: '0.0.0.0:8891'
DIRECTORY_SERVER_PEER2_ADDRESS: '0.0.0.0:8892'
KIND_CLUSTER_NAME: 'sdk-py-test'
cmds:
- task: sdk:test-env:create
- defer: { task: sdk:test-env:delete }
- |
export DIRCTL_PATH="$(printf "%s" "${DIRCTL_PATH:-{{ .DIRCTL_BIN }}}")"
export COSIGN_PATH="$(printf "%s" "${COSIGN_PATH:-{{ .COSIGN_BIN }}}")"
'{{.UV_BIN}}' run pytest
sdk:test:javascript:
desc: Test javascript client SDK package
dir: ./sdk/dir-js
env:
DIRECTORY_CLIENT_SERVER_ADDRESS: '0.0.0.0:8890'
DIRECTORY_SERVER_PEER1_ADDRESS: '0.0.0.0:8891'
DIRECTORY_SERVER_PEER2_ADDRESS: '0.0.0.0:8892'
KIND_CLUSTER_NAME: 'sdk-js-test'
cmds:
- task: sdk:test-env:create
- defer: { task: sdk:test-env:delete }
- |
export DIRCTL_PATH="$(printf "%s" "${DIRCTL_PATH:-{{ .DIRCTL_BIN }}}")"
export COSIGN_PATH="$(printf "%s" "${COSIGN_PATH:-{{ .COSIGN_BIN }}}")"
npm run test
sdk:deps:javascript:
desc: Install deps for javascript SDK package
dir: ./sdk/dir-js
cmds:
- npm install
sdk:release:all:
desc: Release all client SDK package
env:
UV_PUBLISH_TOKEN: '{{ .UV_PUBLISH_TOKEN }}'
NODE_AUTH_TOKEN: '{{ .NODE_AUTH_TOKEN }}'
cmds:
- task: sdk:release:javascript
- task: sdk:release:python
sdk:release:python:
desc: Release python client SDK package
dir: ./sdk/dir-py
env:
UV_PUBLISH_TOKEN: '{{ .UV_PUBLISH_TOKEN }}'
deps:
- task: deps:uv
cmds:
- '{{.UV_BIN}} publish'
sdk:release:javascript:
desc: Release javascript client SDK package
dir: ./sdk/dir-js
env:
NODE_AUTH_TOKEN: '{{ .NODE_AUTH_TOKEN }}'
cmds:
- npm publish --scope=@agntcy --access public
##
## Server
##
server:build:
desc: Build Directory server image
cmds:
- '{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} dir-apiserver'
server:start:
desc: Start Directory server
dir: server/cmd
env:
DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL: 1s
cmds:
- defer: { task: server:store:stop }
- task: server:store:start
- go run main.go
server:store:pull:
desc: Pull local OCI registry server docker image
vars:
IMAGE: '{{.IMAGE}}'
cmds:
- |
docker pull {{.IMAGE}}
server:store:start:
desc: Start local OCI registry server for storage
internal: true
vars:
IMAGE: ghcr.io/project-zot/zot-linux-{{ARCH}}:{{.ZOT_VERSION}}
deps:
- task: server:store:pull
vars:
IMAGE: '{{.IMAGE}}'
cmds:
- |
# mount config
cat > /tmp/config.json <<EOF
{
"distSpecVersion": "1.1.1",
"storage": {
"rootDirectory": "/tmp/zot"
},
"http": {
"address": "0.0.0.0",
"port": "5000"
},
"log": {
"level": "debug"
},
"extensions": {
"search": {
"enable": true
},
"trust": {
"enable": true,
"cosign": true,
"notation": false
}
}
}
EOF
# run docker with attached volume
docker run \
-it \
--rm -d -p 5000:5000 \
-v /tmp/config.json:/config.json:ro \
--name oci-registry {{.IMAGE}} serve /config.json
server:store:stop:
desc: Stop local OCI registry node
internal: true
cmds:
- docker stop oci-registry
server:test:
desc: Unit test Directory server code
dir: ./server
cmds:
- go -C . test ./... {{.EXTRA_ARGS}}
server:bench:
desc: Benchmark Directory server code
dir: ./server
cmds:
- go -C . test -run=^$ -bench=. ./...
##
## Deploy
##
deploy:kubernetes:setup-cluster:
desc: Create a kind cluster and load Docker images
deps:
- deps:helm
- deps:kubectl
- deps:kind
vars:
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "agntcy-cluster" }}'
KIND_CREATE_OPTS: '{{ .KIND_CREATE_OPTS | default "" }}'
cmds:
# Create ephemeral cluster
- '{{ .KIND_BIN }} create cluster {{ .KIND_CREATE_OPTS }} --name {{ .KIND_CLUSTER_NAME }}'
- '{{ .KIND_BIN }} export kubeconfig --name {{ .KIND_CLUSTER_NAME }}'
# Check cluster status
- '{{ .KUBECTL_BIN }} cluster-info'
# Import images
- |
images=$({{.BAKE_ENV}} docker buildx bake default --print | jq -r '.target | with_entries(.value |= .tags[0]) | to_entries[] | .value')
echo "$images" | while read image; do
{{ .KIND_BIN }} load docker-image $image --name {{ .KIND_CLUSTER_NAME }}
done
deploy:kubernetes:local:
aliases: [deploy:local]
desc: Deploy a local Directory server in Kubernetes
deps:
- deploy:kubernetes:setup-cluster
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "agntcy-cluster" }}'
KIND_CREATE_OPTS: '{{ .KIND_CREATE_OPTS | default "" }}'
# Helm args
HELM_NAMESPACE: '{{ .HELM_NAMESPACE | default "dir-server" }}'
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/dir'
HELM_VALUES_PATH: '{{ .ROOT_DIR }}/install/charts/dir/values.yaml'
cmds:
# TODO: make logic idempotent so that running functional tests does not change previous contexts
# Create zot configuration using helper task
- task: deploy:zot:config
vars:
ZOT_CONFIG_DIR: /opt/zot-config
# Deploy chart
- |
{{ .HELM_BIN }} dependency build {{ .HELM_CHART_PATH }}
{{ .HELM_BIN }} upgrade dir \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set apiserver.image.tag="{{ .IMAGE_TAG }}" \
{{ if .DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL }}--set apiserver.config.publication.scheduler_interval="{{ .DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL }}"{{ end }} \
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
deploy:kubernetes:context:
desc: Switch context to given Kubernetes cluster
vars:
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "agntcy-cluster" }}'
cmds:
- '{{ .KIND_BIN }} export kubeconfig --name {{ .KIND_CLUSTER_NAME }}'
deploy:kubernetes:dir:
desc: Deploy DIR helm chart
vars:
HELM_NAMESPACE: '{{ .HELM_NAMESPACE | default "dir-server" }}'
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/dir'
HELM_VALUES_PATH: '{{ .ROOT_DIR }}/install/charts/dir/values.yaml'
HELM_EXTRA_ARGS: '{{ .HELM_EXTRA_ARGS | default "" }}'
cmds:
- task: deploy:zot:config
vars:
ZOT_CONFIG_DIR: /opt/zot-config
- |
{{ .HELM_BIN }} upgrade --install dir \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set apiserver.image.tag="{{ .IMAGE_TAG }}" \
{{ if .DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL }}--set apiserver.config.publication.scheduler_interval="{{ .DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL }}"{{ end }} \
{{ .HELM_EXTRA_ARGS }} \
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
deploy:kubernetes:dirctl:
desc: Deploy DIRCTL helm chart
vars:
HELM_NAMESPACE: '{{ .HELM_NAMESPACE | default "dir-client" }}'
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/dirctl'
HELM_VALUES_PATH: '{{ .ROOT_DIR }}/install/charts/dirctl/values.yaml'
HELM_EXTRA_ARGS: '{{ .HELM_EXTRA_ARGS | default "" }}'
cmds:
- |
{{ .HELM_BIN }} upgrade --install dirctl \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set image.tag="{{ .IMAGE_TAG }}" \
{{ .HELM_EXTRA_ARGS }} \
--namespace {{ .HELM_NAMESPACE }} \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
deploy:kubernetes:spire:
desc: Deploy SPIRE helm chart
vars:
TRUST_DOMAIN: '{{ .TRUST_DOMAIN | default "example.org" }}'
SERVICE_TYPE: '{{ .SERVICE_TYPE | default "LoadBalancer" }}'
BUNDLE_PATH: '{{ .BUNDLE_PATH | default "/tmp/spire-bundle.spiffe" }}'
cmds:
- |
{{ .HELM_BIN }} upgrade --install spire-crds spire-crds \
--repo https://spiffe.github.io/helm-charts-hardened/ \
--namespace spire-crds \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
- |
{{ .HELM_BIN }} upgrade --install spire spire \
--repo https://spiffe.github.io/helm-charts-hardened/ \
--set global.spire.trustDomain="{{ .TRUST_DOMAIN }}" \
--set spire-server.service.type="{{ .SERVICE_TYPE }}" \
--set spire-server.federation.enabled="true" \
--set spire-server.controllerManager.watchClassless="true" \
--namespace spire \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
- |
{{ .KUBECTL_BIN }} get configmap -n spire spire-bundle -o json | jq '.data."bundle.spiffe"' -r > {{ .BUNDLE_PATH }}
deploy:kubernetes:local:port-forward:
aliases: [deploy:local:port-forward]
desc: Set up port-forwarding for the local deployment
vars:
# Helm args
HELM_NAMESPACE: '{{ .HELM_NAMESPACE | default "dir-server" }}'
cmds:
# Port-forward dependency services
- |
{{ .KUBECTL_BIN }} port-forward service/dir-apiserver 8888:8888 -n {{ .HELM_NAMESPACE }} &
# Delay to ensure services are online
- sleep 10
deploy:kubernetes:local:port-forward:cleanup:
aliases: [deploy:local:port-forward:cleanup]
desc: Cleanup port-forwarding processes
cmds:
# Kill any existing port-forward processes for the dir-apiserver service
- kill -9 $(ps aux | grep port-forward | grep dir-apiserver | awk '{print $2}') || true
deploy:kubernetes:local:cleanup:
aliases: [deploy:local:cleanup, deploy:kubernetes:cleanup]
desc: Cleanup Kubernetes environment for local deployment
deps:
- deps:kind
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "agntcy-cluster" }}'
cmds:
- '{{ .KIND_BIN }} delete cluster --name {{ .KIND_CLUSTER_NAME }}'
deploy:kubernetes:network:bootstrap:
internal: true
desc: Deploy a bootstrap Directory server in Kubernetes
deps:
- deploy:kubernetes:setup-cluster
- deps:dirctl-bin
vars:
# Helm args
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/dir'
HELM_VALUES_PATH: '{{ .ROOT_DIR }}/install/charts/dir/values.yaml'
cmds:
# Generate private key if it doesn't exist
- |
test -f /tmp/node.privkey || {{ .BIN_DIR }}/dirctl network init --output /tmp/node.privkey
# Generate the bootstrap peer ID and export it to the environment file
- |
bootstrap_peerid=$({{ .BIN_DIR }}/dirctl network info /tmp/node.privkey)
echo "PEER ID: ${bootstrap_peerid}"
echo BOOTSTRAP_PEER_ID="${bootstrap_peerid}" > .env
# Create zot configuration using helper task for bootstrap
- task: deploy:zot:config
vars:
ZOT_CONFIG_DIR: /opt/zot-config-bootstrap
# Deploy the bootstrap server using Helm
- |
{{ .HELM_BIN }} dependency build {{ .HELM_CHART_PATH }}
{{ .HELM_BIN }} upgrade agntcy-dir \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set apiserver.image.tag="{{ .IMAGE_TAG }}" \
{{ if .PUBLICATION_SCHEDULER_INTERVAL }}--set apiserver.config.publication.scheduler_interval="{{ .PUBLICATION_SCHEDULER_INTERVAL }}"{{ end }} \
--set apiserver.privKey="$(cat /tmp/node.privkey)" \
--set apiserver.config.routing.key_path="/etc/agntcy/dir/node.privkey" \
--set apiserver.config.routing.listen_address="/ip4/0.0.0.0/tcp/8999" \
--set apiserver.config.routing.directory_api_address="agntcy-dir-apiserver.bootstrap.svc.cluster.local:8888" \
--set apiserver.config.store.oci.registry_address="agntcy-dir-zot.bootstrap.svc.cluster.local:5000" \
--set-json 'apiserver.extraVolumes=[{"name":"zot-config-storage","hostPath":{"path":"/opt/zot-config-bootstrap","type":"DirectoryOrCreate"}}]' \
--set-json 'apiserver.zot.extraVolumes=[{"name":"zot-config-storage","hostPath":{"path":"/opt/zot-config-bootstrap","type":"DirectoryOrCreate"}}]' \
--namespace "bootstrap" \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
deploy:kubernetes:network:
aliases: [deploy:network]
desc: Deploy a network of Directory servers in Kubernetes (1 bootstrap + 3 peers)
vars:
HELM_CHART_PATH: '{{ .ROOT_DIR }}/install/charts/dir'
HELM_VALUES_PATH: '{{ .ROOT_DIR }}/install/charts/dir/values.yaml'
cmds:
# Deploy bootstrap with explicit var passing (not as dependency)
- task: deploy:kubernetes:network:bootstrap
vars:
PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL }}'
# Create zot configuration for each peer using helper task
- for:
matrix:
PEER: ['peer1', 'peer2', 'peer3']
task: deploy:zot:config
vars:
ZOT_CONFIG_DIR: /opt/zot-config-{{ .ITEM.PEER }}
# Deploy the peer servers using Helm
- for:
matrix:
PEER: ['peer1', 'peer2', 'peer3']
cmd: |
export $(cat .env)
{{ .HELM_BIN }} upgrade agntcy-dir \
{{ .HELM_CHART_PATH }} \
-f {{ .HELM_VALUES_PATH }} \
--set apiserver.image.tag="{{ .IMAGE_TAG }}" \
{{ if .PUBLICATION_SCHEDULER_INTERVAL }}--set apiserver.config.publication.scheduler_interval="{{ .PUBLICATION_SCHEDULER_INTERVAL }}"{{ end }} \
--set apiserver.config.store.oci.registry_address="agntcy-dir-zot.{{ .ITEM.PEER }}.svc.cluster.local:5000" \
--set apiserver.config.routing.bootstrap_peers[0]="/dns4/agntcy-dir-apiserver-routing.bootstrap.svc.cluster.local/tcp/8999/p2p/${BOOTSTRAP_PEER_ID}" \
--set apiserver.config.routing.directory_api_address="agntcy-dir-apiserver.{{ .ITEM.PEER }}.svc.cluster.local:8888" \
--set-json 'apiserver.extraVolumes=[{"name":"zot-config-storage","hostPath":{"path":"/opt/zot-config-{{ .ITEM.PEER }}","type":"DirectoryOrCreate"}}]' \
--set-json 'apiserver.zot.extraVolumes=[{"name":"zot-config-storage","hostPath":{"path":"/opt/zot-config-{{ .ITEM.PEER }}","type":"DirectoryOrCreate"}}]' \
--namespace "{{ .ITEM.PEER }}" \
--create-namespace \
--install \
--wait \
--wait-for-jobs \
--timeout "15m"
deploy:kubernetes:network:port-forward:
aliases: [deploy:network:port-forward]
desc: Set up port-forwarding for the peers
cmds:
# Port-forward dependency services
- '{{ .KUBECTL_BIN }} port-forward svc/agntcy-dir-apiserver -n peer1 8890:8888 &'
- '{{ .KUBECTL_BIN }} port-forward svc/agntcy-dir-apiserver -n peer2 8891:8888 &'
- '{{ .KUBECTL_BIN }} port-forward svc/agntcy-dir-apiserver -n peer3 8892:8888 &'
# Delay to ensure services are online
- sleep 10
deploy:kubernetes:network:port-forward:cleanup:
aliases: [deploy:network:port-forward:cleanup]
desc: Cleanup port-forwarding processes
cmds:
# Kill any existing port-forward processes for the agntcy-dir-apiserver service
- kill -9 $(ps aux | grep port-forward | grep agntcy-dir-apiserver | awk '{print $2}') || true
deploy:kubernetes:network:cleanup:
aliases: [deploy:network:cleanup]
desc: Cleanup Kubernetes environment for network deployment
vars:
# Kind args
KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "agntcy-cluster" }}'
cmds:
# Delete helm releases
- for:
matrix:
PEER: ['bootstrap', 'peer1', 'peer2', 'peer3']
cmd: |
{{ .HELM_BIN }} delete --namespace {{ .ITEM.PEER }} agntcy-dir
- '{{ .KIND_BIN }} delete cluster --name {{ .KIND_CLUSTER_NAME }}'
deploy:zot:config:
internal: true
desc: Create zot configuration directory and file
vars:
ZOT_CONFIG_DIR: '{{ .ZOT_CONFIG_DIR | default "/opt/zot-config" }}'
cmds:
# Create host directory for zot configuration hot reload
- |
if ! {{ .KUBECTL_BIN }} get nodes -o jsonpath='{.items[0].metadata.name}' | xargs -I {} \
docker exec {} mkdir -p {{ .ZOT_CONFIG_DIR }}; then
echo "Failed to create zot config directory: {{ .ZOT_CONFIG_DIR }}"
exit 1
fi
# Create zot configuration file with proper permissions
- |
if ! {{ .KUBECTL_BIN }} get nodes -o jsonpath='{.items[0].metadata.name}' | xargs -I {} \
docker exec {} sh -c 'cat > {{ .ZOT_CONFIG_DIR }}/config.json << "EOF"
{
"distSpecVersion": "1.1.1",
"storage": {
"rootDirectory": "/var/lib/registry"
},
"http": {
"address": "0.0.0.0",
"port": "5000"
},
"log": {
"level": "info"
},
"extensions": {
"search": {
"enable": true
},
"trust": {
"enable": true,
"cosign": true,
"notation": false
}
}
}
EOF
chmod 666 {{ .ZOT_CONFIG_DIR }}/config.json
chmod 777 {{ .ZOT_CONFIG_DIR }}'; then
echo "Failed to create zot config file: {{ .ZOT_CONFIG_DIR }}/config.json"
exit 1
fi
##
## Test
##
test:unit:
desc: Run unit tests on codebase
aliases: [test]
deps: # run in parallel
- cli:test
- api:test
- client:test
- server:test
cmds:
- echo "Success"
test:unit:cover:
desc: Run all unit tests with coverage and generate reports
deps:
- task: cli:test
vars:
EXTRA_ARGS: '-coverprofile {{.ROOT_DIR}}/coverage-dir-cli.out -json > {{.ROOT_DIR}}/test-report-dir-cli.json'
- task: api:test
vars:
EXTRA_ARGS: '-coverprofile {{.ROOT_DIR}}/coverage-dir-api.out -json > {{.ROOT_DIR}}/test-report-dir-api.json'
- task: client:test
vars:
EXTRA_ARGS: '-coverprofile {{.ROOT_DIR}}/coverage-dir-client.out -json > {{.ROOT_DIR}}/test-report-dir-client.json'
- task: server:test
vars:
EXTRA_ARGS: '-coverprofile {{.ROOT_DIR}}/coverage-dir-server.out -json > {{.ROOT_DIR}}/test-report-dir-server.json'
test:unit:coverage:html:
desc: Extended per-module coverage run with summaries & HTML (non-regression)
cmds:
- |
set -euo pipefail
echo "[coverage] Cleaning previous coverage artifacts"
rm -f coverage-*.out coverage-summary.txt test-report-*.json coverage-*.html || true
- |
set -euo pipefail
modules="api client server cli"
for m in $modules; do
if [ -d "$m" ]; then
echo "[coverage] Testing module: $m"
(
cd "$m"
if go test ./... -covermode=atomic -coverprofile "../coverage-$m.out" -json 2>&1 | tee "../test-report-$m.json" >/dev/null; then
echo "[coverage] Completed: $m"
else
status=$?
echo "[coverage][warn] Tests failed in $m (exit $status); continuing"
fi
if [ ! -s "../coverage-$m.out" ]; then
echo "mode: atomic" > "../coverage-$m.out"
fi
)
fi
done
- |
set -euo pipefail
echo "[coverage] Generating per-module summaries"
: > coverage-summary.txt
modules="api client server cli"
for m in $modules; do
if [ -f "coverage-$m.out" ]; then
if (cd "$m" && go tool cover -func=../coverage-$m.out > ../coverage-$m.func.txt 2>/dev/null); then
tail -n1 coverage-$m.func.txt | sed "s/^total:/[$m] total:/" >> coverage-summary.txt || true
else
echo "[$m] total: (error generating summary)" >> coverage-summary.txt
fi
fi
done
echo "[coverage] Summary:"; cat coverage-summary.txt
- |
set -euo pipefail
echo "[coverage] Generating HTML reports"
modules="api client server cli"
for m in $modules; do
if [ -f "coverage-$m.out" ] && [ -d "$m" ]; then
(cd "$m" && go tool cover -html=../coverage-$m.out -o ../coverage-$m.html || true)
fi
done
echo "[coverage] Generated HTML files:"; ls -1 coverage-*.html 2>/dev/null | sed 's/^/ - /' || echo " (none)"
bench:
desc: Run bench tests on codebase
cmds: # run in sequence
- task: server:bench
- echo "Done"
test:e2e:
desc: Run end-to-end tests for local deployment and network deployment
aliases: [e2e]
cmds:
- task: test:e2e:local
- task: test:e2e:network
test:e2e:local:cli:
desc: Run only local CLI tests (with dedicated infrastructure)
aliases: [e2e:local:cli]
vars:
PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL | default "1s" }}'
env:
DIRECTORY_E2E_DEPLOYMENT_MODE: 'local'
cmds:
- defer: { task: deploy:kubernetes:local:cleanup }
- defer: { task: deploy:kubernetes:local:port-forward:cleanup }
- task: deploy:kubernetes:local
vars:
DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL }}'
- task: deploy:kubernetes:local:port-forward
- 'go test -C ./e2e/local . -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 2h -timeout 2h -ginkgo.v'
test:e2e:client:
desc: Run only client library tests (with dedicated infrastructure)
aliases: [e2e:client]
vars:
PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL | default "1s" }}'
env:
DIRECTORY_E2E_DEPLOYMENT_MODE: 'local'
cmds:
- defer: { task: deploy:kubernetes:local:cleanup }
- defer: { task: deploy:kubernetes:local:port-forward:cleanup }
- task: deploy:kubernetes:local
vars:
DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL }}'
- task: deploy:kubernetes:local:port-forward
- 'go test -C ./e2e/client . -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 2h -timeout 2h -ginkgo.v'
test:e2e:local:
desc: Run end-to-end tests for local deployment (Client library + CLI tests)
aliases: [e2e:local]
vars:
PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL | default "1s" }}'
env:
DIRECTORY_E2E_DEPLOYMENT_MODE: 'local'
cmds:
- defer: { task: deploy:kubernetes:local:cleanup }
- defer: { task: deploy:kubernetes:local:port-forward:cleanup }
# Bootstrap infrastructure once for both test suites
- task: deploy:kubernetes:local
vars:
DIRECTORY_SERVER_PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL }}'
- task: deploy:kubernetes:local:port-forward
# Run client library tests first (faster feedback)
- 'go test -C ./e2e/client . -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 2h -timeout 2h -ginkgo.v'
# Run local CLI tests second (same infrastructure)
- 'go test -C ./e2e/local . -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 2h -timeout 2h -ginkgo.v'
test:e2e:network:
desc: Run end-to-end tests for network deployment (Multi-peer CLI tests)
aliases: [e2e:network]
vars:
PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL | default "1s" }}'
env:
DIRECTORY_E2E_DEPLOYMENT_MODE: 'network'
cmds:
- defer: { task: deploy:kubernetes:network:cleanup }
- defer: { task: deploy:kubernetes:network:port-forward:cleanup }
# Bootstrap
# NOTE: Run as a dedicated task instead of dependency, otherwise the port forwarding won't work
- task: deploy:kubernetes:network
vars:
PUBLICATION_SCHEDULER_INTERVAL: '{{ .PUBLICATION_SCHEDULER_INTERVAL }}'
- task: deploy:kubernetes:network:port-forward
# Run network tests with proper isolation and cleanup
- 'go test -C ./e2e/network . -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 2h -timeout 2h -ginkgo.v'
# TODO: move spire out from here
# TODO: change to Ingress services instead of LoadBalancer
test:spire:
desc: Test SPIRE federation setup between DIR and DIRCTL clusters
vars:
DIR_TRUST_DOMAIN: '{{ .DIR_TRUST_DOMAIN | default "dir.example" }}'
DIRCTL_TRUST_DOMAIN: '{{ .DIRCTL_TRUST_DOMAIN | default "dirctl.example" }}'
cmds:
# Setup DIR cluster
- task: deploy:kubernetes:setup-cluster
vars: