forked from OpenMined/PySyft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tox.ini
1251 lines (1102 loc) · 44.5 KB
/
tox.ini
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
[tox]
envlist =
dev.k8s.launch.datasite
dev.k8s.launch.gateway
dev.k8s.registry
dev.k8s.start
dev.k8s.deploy
dev.k8s.hotreload
dev.k8s.info
dev.k8s.cleanup
dev.k8s.destroy
dev.k8s.destroyall
lint
stack.test.integration
syft.docs
syft.jupyter
syft.publish
syft.test.security
syft.test.unit
syft.test.notebook
single_container.launch
single_container.destroy
stack.test.notebook
stack.test.integration.k8s
frontend.test.unit
frontend.test.e2e
frontend.generate.types
syft.build.helm
syft.package.helm
syft.test.helm
syft.test.helm.upgrade
syft.protocol.check
syftcli.test.unit
syftcli.publish
syftcli.build
seaweedfs.test.unit
backend.test.basecpu
e2e.test.notebook
migration.prepare
migration.test
skipsdist = True
[testenv]
basepython = python3
commands =
python --version
setenv =
UV_HTTP_TIMEOUT = 600
# Syft
[testenv:syft]
deps =
-e{toxinidir}/packages/syft[dev,data_science]
changedir = {toxinidir}/packages/syft
description = Syft
allowlist_externals =
bash
commands =
bash -c 'uv pip list || pip list'
# Syft Minimal - without dev+datascience packages
[testenv:syft-minimal]
deps =
-e{toxinidir}/packages/syft
changedir = {toxinidir}/packages/syft
description = Syft
allowlist_externals =
bash
commands =
bash -c 'uv pip list || pip list'
[testenv:syftcli]
deps =
-e{toxinidir}/packages/syftcli[dev]
changedir = {toxinidir}/packages/syftcli
description = Syft CLI
allowlist_externals =
bash
commands =
bash -c 'uv pip list || pip list'
[testenv:syft.publish]
changedir = {toxinidir}/packages/syft
description = Build and Publish Syft Wheel
deps =
build
commands =
python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)'
python -m build .
[testenv:syftcli.publish]
changedir = {toxinidir}/packages/syftcli
description = Build and Publish Syft CLI Wheel
deps =
build
allowlist_externals =
bash
commands =
bash -c 'rm -rf build/ dist/ syftcli.egg-info/'
python -m build .
[testenv:syftcli.build]
basepython = python3
changedir = {toxinidir}/packages/syftcli
description = Build SyftCLI Binary for each platform
deps =
-e{toxinidir}/packages/syftcli[build]
allowlist_externals =
bash
setenv =
SYFT_CLI_VERSION = {env:SYFT_CLI_VERSION}
commands =
python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)'
;Since we build universal binary for MacOS,we need to check the python is universal2 or not
bash -c 'if [[ "$OSTYPE" == "darwin"* ]]; then \
arch_info=$(lipo -info "$(which python3)"); \
echo "Arch: $arch_info"; \
if [[ "$arch_info" == *"Non-fat"* ]]; then \
echo "Building on MacOS Requires Universal2 python"; \
echo "Please install universal2 python from https://www.python.org/downloads/macos/"; \
exit 1; \
fi; \
fi'
;check the platform and build accordingly by naming the binary as syftcli plus the extension
; Check if SYFT_CLI_VERSION is set or choosing the current version available
bash -c 'if [ -z $SYFT_CLI_VERSION ]; then \
echo "SYFT_CLI_VERSION is not set"; \
SYFT_CLI_VERSION=$(python3 syftcli/version.py); \
echo "Setting SYFT_CLI_VERSION to $SYFT_CLI_VERSION"; \
else \
echo "SYFT_CLI_VERSION is already set to $SYFT_CLI_VERSION"; \
fi && \
echo "Building syftcli-$SYFT_CLI_VERSION for $OSTYPE" && \
if [[ "$OSTYPE" == "darwin"* ]]; then \
pyinstaller --clean --onefile --name syftcli-v$SYFT_CLI_VERSION-macos-universal2 --distpath ./dist/cli syftcli/cli.py --target-arch universal2; \
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then \
pyinstaller --clean --onefile --name syftcli-v$SYFT_CLI_VERSION-linux-x86_64 --distpath ./dist/cli syftcli/cli.py; \
else \
pyinstaller --clean --onefile --name syftcli-v$SYFT_CLI_VERSION-windows-x86_64 --distpath ./dist/cli syftcli/cli.py; \
fi'
[testenv:lint]
description = Linting
allowlist_externals =
bash
deps =
black[python2]
isort
pre-commit
commands =
black .
isort .
pre-commit run --all-files
[testenv:frontend.test.unit]
description = Frontend Unit Tests
allowlist_externals =
docker
bash
pnpm
passenv=HOME, USER
changedir = {toxinidir}/packages/grid/frontend
setenv =
DOCKER = {env:DOCKER:false}
commands =
bash -c "echo Running with DOCKER=$DOCKER; date"
bash -c 'if [[ "$DOCKER" == "false" ]]; then \
bash ./scripts/check_pnpm.sh; \
pnpm install; \
pnpm run test:unit; \
else \
docker build --target syft-ui-tests -t ui-test -f frontend.dockerfile .; \
docker run -t ui-test; \
fi'
[testenv:syft.docs]
description = Build Docs for Syft
changedir = {toxinidir}/docs
deps =
{[testenv:syft]deps}
-r {toxinidir}/docs/requirements.txt
allowlist_externals =
make
echo
cd
rm
ls
xargs
bash
commands =
python --version
bash -c "cd source/api_reference && ls | grep -v index.rst | xargs rm"
sphinx-apidoc -f -M -d 2 -o ./source/api_reference/ ../packages/syft/src/syft
make html
echo "Open: {toxinidir}/docs/build/html/index.html"
[testenv:syft.jupyter]
description = Jupyter Notebook with Editable Syft
deps =
{[testenv:syft]deps}
jupyter
jupyterlab
allowlist_externals =
bash
commands =
bash -c 'if [ -z "{posargs}" ]; then \
jupyter lab --ip 0.0.0.0; \
else \
jupyter lab --ip 0.0.0.0 --ServerApp.token={posargs}; \
fi'
[testenv:syft.protocol.check]
description = Syft Protocol Check
deps =
{[testenv:syft-minimal]deps}
changedir = {toxinidir}/packages/syft
allowlist_externals =
bash
setenv =
BUMP = {env:BUMP:False}
commands =
bash -c "echo Using BUMP=${BUMP}"
python -c 'import syft as sy; sy.check_or_stage_protocol()'
bash -c 'if [[ "$BUMP" != "False" ]]; then \
python -c "import syft as sy; sy.bump_protocol_version()"; \
fi'
[testenv:syft.test.security]
description = Security Checks for Syft
changedir = {toxinidir}/packages/syft
deps =
{[testenv:syft]deps}
commands =
bandit -r src
# restrictedpython 6.2
# Temporarily ignore pytorch vulnerability warning here
# https://data.safetycli.com/v/71670/97c
# TODO: Remove `-i 71670` once torch is updated
safety check -i 70612 -i 71670
[testenv:syft.test.unit]
description = Syft Unit Tests
deps =
{[testenv:syft]deps}
allowlist_externals =
bash
uv
changedir = {toxinidir}/packages/syft
setenv =
ENABLE_SIGNUP=False
commands =
bash -c 'ulimit -n 4096 || true'
pytest -n auto --dist loadgroup --durations=20 --disable-warnings
[testenv:syft.test.notebook]
description = Syft Notebook Tests
deps =
-e{toxinidir}/packages/syft[dev,data_science]
nbmake
changedir = {toxinidir}/notebooks
allowlist_externals =
bash
setenv =
ORCHESTRA_DEPLOYMENT_TYPE = {env:ORCHESTRA_DEPLOYMENT_TYPE:python}
DEV_MODE = {env:DEV_MODE:True}
TEST_NOTEBOOK_PATHS = {env:TEST_NOTEBOOK_PATHS:api/0.8,tutorials}
ENABLE_SIGNUP={env:ENABLE_SIGNUP:False}
BUMP_PROTOCOL={env:BUMP_PROTOCOL:False}
commands =
bash -c 'if [[ $BUMP_PROTOCOL == "True" ]]; then \
python -c "import syft as sy; sy.bump_protocol_version()"; \
fi;'
bash -c "echo Running with ORCHESTRA_DEPLOYMENT_TYPE=$ORCHESTRA_DEPLOYMENT_TYPE DEV_MODE=$DEV_MODE TEST_NOTEBOOK_PATHS=$TEST_NOTEBOOK_PATHS; ENABLE_SIGNUP=$ENABLE_SIGNUP; date"
bash -c "for subfolder in $(echo ${TEST_NOTEBOOK_PATHS} | tr ',' ' '); do \
if [[ $subfolder == *tutorials* ]]; then \
pytest -x --nbmake "$subfolder" \
-p no:randomly \
--ignore=tutorials/model-training \
--ignore=tutorials/version-upgrades \
-n $(python -c 'import multiprocessing; print(multiprocessing.cpu_count())') \
-vvvv && \
pytest -x --nbmake tutorials/model-training -p no:randomly -vvvv; \
else \
pytest -x --nbmake "$subfolder" -p no:randomly -k 'not 11-container-images-k8s.ipynb' -vvvv; \
fi \
done"
; pytest -x --nbmake api/0.8 -p no:randomly -vvvv
; pytest -x --nbmake api/0.9 -p no:randomly -vvvv
; pytest -x --nbmake tutorials -p no:randomly -vvvv
; pytest -x --nbmake tutorials/pandas-cookbook -p no:randomly -vvvv
[testenv:single_container.launch]
description = Launch a single backend container using the dockerfile
changedir = {toxinidir}/packages
setenv =
N_CONSUMERS = {env:N_CONSUMERS:1}
SERVER_NAME = {env:SERVER_NAME:test_datasite_sc}
SERVER_TYPE = {env:SERVER_TYPE:datasite}
SERVER_PORT = {env:SERVER_PORT:8080}
allowlist_externals =
bash
commands =
bash -c 'tox -e single_container.destroy'
bash -c 'docker build -f grid/backend/backend.dockerfile . -t openmined/syft-backend:local-dev'
bash -c 'docker run -d \
-e SERVER_NAME=${SERVER_NAME} \
-e SERVER_TYPE=${SERVER_TYPE} \
-e N_CONSUMERS=${N_CONSUMERS} \
-e SINGLE_CONTAINER_MODE=true \
-e CREATE_PRODUCER=true \
-e INMEMORY_WORKERS=true \
-p ${SERVER_PORT}:80 --add-host=host.docker.internal:host-gateway \
--name ${SERVER_NAME} openmined/syft-backend:local-dev'
[testenv:single_container.destroy]
description = Destroy the single backend container run using single_container.launch
changedir = {toxinidir}/packages
setenv =
SERVER_NAME = {env:SERVER_NAME:test_datasite_sc}
allowlist_externals =
bash
commands =
# Image is not cleaned up
bash -c 'docker stop ${SERVER_NAME} || true'
bash -c 'docker rm ${SERVER_NAME} || true'
[testenv:stack.test.notebook]
description = Stack Notebook Tests
deps =
{[testenv:syft]deps}
nbmake
changedir = {toxinidir}/notebooks
allowlist_externals =
bash
setenv =
ORCHESTRA_DEPLOYMENT_TYPE = {env:ORCHESTRA_DEPLOYMENT_TYPE:remote}
DEV_MODE = {env:DEV_MODE:True}
TEST_NOTEBOOK_PATHS = {env:TEST_NOTEBOOK_PATHS:api/0.8}
ENABLE_SIGNUP=True
SERVER_URL = {env:SERVER_URL:http://localhost}
SERVER_PORT = {env:SERVER_PORT:8080}
commands =
# Volume cleanup
bash -c 'docker volume rm -f $(docker volume ls -q --filter "label=orgs.openmined.syft") || true'
bash -c 'docker volume rm -f $(docker volume ls -q --filter "label=com.docker.volume.anonymous") || true'
bash -c 'docker network rm -f $(docker network ls -q --filter "label=orgs.openmined.syft") || true'
bash -c "echo Running with ORCHESTRA_DEPLOYMENT_TYPE=$ORCHESTRA_DEPLOYMENT_TYPE DEV_MODE=$DEV_MODE TEST_NOTEBOOK_PATHS=$TEST_NOTEBOOK_PATHS; date"
bash -c "for subfolder in $(echo ${TEST_NOTEBOOK_PATHS} | tr ',' ' ');\
do \
pytest -x --nbmake --nbmake-timeout=1000 "$subfolder" -p no:randomly -vvvv -k 'not 11-container-images-k8s.ipynb';\
done"
; pytest -x --nbmake --nbmake-timeout=1000 api/0.8 -p no:randomly -vvvv
; pytest -x --nbmake --nbmake-timeout=1000 api/0.9 -p no:randomly -vvvv
; pytest -x --nbmake --nbmake-timeout=1000 tutorials -p no:randomly -vvvv
; pytest -x --nbmake --nbmake-timeout=1000 tutorials/pandas-cookbook -p no:randomly -vvvv
bash -c 'docker volume rm -f $(docker volume ls -q --filter "label=orgs.openmined.syft") || true'
bash -c 'docker volume rm -f $(docker volume ls -q --filter "label=com.docker.volume.anonymous") || true'
bash -c 'docker network rm -f $(docker network ls -q --filter "label=orgs.openmined.syft") || true'
[testenv:frontend.generate.types]
description = Generate Types for Frontend
deps =
{[testenv:syft]deps}
allowlist_externals =
cd
bash
pnpm
changedir = {toxinidir}/packages/grid/frontend
passenv =
PNPM_HOME
commands =
bash -c ./scripts/check_pnpm.sh
pnpm add -g json-schema-to-typescript
; clear the old ones
bash -c 'rm -rf ./schema'
bash -c 'rm -rf ./src/types/generated'
; generate new ones
bash -c 'python3 -c "import syft as sy;sy.util.schema.generate_json_schemas()"'
bash -c "json2ts -i './schema/**/*.json' -o ./src/types/generated"
bash -c "python3 ./scripts/replace_imports.py ./src/types/generated"
[mypy]
python_version = 3.12
disable_error_code = attr-defined, valid-type, no-untyped-call, arg-type
[testenv:syft.test.integration]
description = Integration Tests for Syft Stack
basepython = python3
deps =
{[testenv:syft]deps}
changedir = {toxinidir}
passenv=HOME, USER
allowlist_externals =
bash
setenv =
PYTEST_MODULES = {env:PYTEST_MODULES:local_server}
ASSOCIATION_REQUEST_AUTO_APPROVAL = {env:ASSOCIATION_REQUEST_AUTO_APPROVAL:true}
PYTEST_FLAGS = {env:PYTEST_FLAGS:--ignore=tests/integration/local/job_test.py}
commands =
python -c 'import syft as sy; sy.stage_protocol_changes()'
# Run Integration Tests
bash -c '\
PYTEST_MODULES=($PYTEST_MODULES); \
for i in "${PYTEST_MODULES[@]}"; do \
echo "Starting test for $i"; date; \
pytest tests/integration -m $i -vvvv -p no:randomly -p no:benchmark -o log_cli=True --capture=no $PYTEST_FLAGS; \
return=$?; \
echo "Finished $i"; \
date; \
if [[ $return -ne 0 ]]; then \
exit $return; \
fi; \
done'
[testenv:stack.test.integration.k8s]
description = Integration Tests for Core Stack using K8s
basepython = python3
deps =
{[testenv:syft]deps}
changedir = {toxinidir}
passenv=HOME, USER, AZURE_BLOB_STORAGE_KEY
allowlist_externals =
devspace
kubectl
grep
sleep
bash
kubectx
k3d
echo
tox
setenv =
SERVER_PORT = {env:SERVER_PORT:9082}
GITHUB_CI = {env:GITHUB_CI:false}
PYTEST_MODULES = {env:PYTEST_MODULES:frontend network container_workload}
DATASITE_CLUSTER_NAME = {env:DATASITE_CLUSTER_NAME:test-datasite-1}
GATEWAY_CLUSTER_NAME = {env:GATEWAY_CLUSTER_NAME:test-gateway-1}
ASSOCIATION_REQUEST_AUTO_APPROVAL = {env:ASSOCIATION_REQUEST_AUTO_APPROVAL:true}
SYFT_BASE_IMAGE_REGISTRY = {env:SYFT_BASE_IMAGE_REGISTRY:k3d-registry.localhost:5800}
commands =
bash -c "echo Running with GITHUB_CI=$GITHUB_CI; date"
python -c 'import syft as sy; sy.stage_protocol_changes()'
k3d version
# Deleting Old Cluster
bash -c "k3d cluster delete ${DATASITE_CLUSTER_NAME} || true"
bash -c "k3d cluster delete ${GATEWAY_CLUSTER_NAME} || true"
# Deleting registry & volumes
bash -c "k3d registry delete k3d-registry.localhost || true"
bash -c "docker volume rm k3d-${DATASITE_CLUSTER_NAME}-images --force || true"
bash -c "docker volume rm k3d-${GATEWAY_CLUSTER_NAME}-images --force || true"
# Create registry
tox -e dev.k8s.registry
# Creating test-gateway-1 cluster on port 9081
bash -c '\
export CLUSTER_NAME=${GATEWAY_CLUSTER_NAME} CLUSTER_HTTP_PORT=9081 DEVSPACE_PROFILE=gateway && \
tox -e dev.k8s.start && \
tox -e dev.k8s.deploy'
# Creating test-datasite-1 cluster on port 9082
bash -c '\
export CLUSTER_NAME=${DATASITE_CLUSTER_NAME} CLUSTER_HTTP_PORT=9082 DEVSPACE_PROFILE=datasite-tunnel && \
tox -e dev.k8s.start && \
tox -e dev.k8s.deploy'
# free up build cache after build of images
bash -c 'if [[ "$GITHUB_CI" != "false" ]]; then \
docker image prune --all --force; \
docker builder prune --all --force; \
fi'
sleep 30
# wait for test gateway 1
bash packages/grid/scripts/wait_for.sh service mongo --context k3d-{env:GATEWAY_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service backend --context k3d-{env:GATEWAY_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service proxy --context k3d-{env:GATEWAY_CLUSTER_NAME} --namespace syft
# wait for test datasite 1
bash packages/grid/scripts/wait_for.sh service mongo --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service backend --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service proxy --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service seaweedfs --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service frontend --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash -c '(kubectl logs service/frontend --context k3d-${DATASITE_CLUSTER_NAME} --namespace syft -f &) | grep -q -E "Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/" || true'
# Checking logs generated & startup of test-datasite 1
bash -c '(kubectl logs service/backend --context k3d-${DATASITE_CLUSTER_NAME} --namespace syft -f &) | grep -q "Application startup complete" || true'
# Checking logs generated & startup of testgateway1
bash -c '(kubectl logs service/backend --context k3d-${GATEWAY_CLUSTER_NAME} --namespace syft -f &) | grep -q "Application startup complete" || true'
# Run Integration Tests
bash -c '\
PYTEST_MODULES=($PYTEST_MODULES); \
for i in "${PYTEST_MODULES[@]}"; do \
echo "Starting test for $i"; date; \
pytest tests/integration -m $i -vvvv -p no:randomly -p no:benchmark -o log_cli=True --capture=no; \
return=$?; \
echo "Finished $i"; \
date; \
if [[ $return -ne 0 ]]; then \
exit $return; \
fi; \
done'
# deleting clusters created
bash -c "CLUSTER_NAME=${DATASITE_CLUSTER_NAME} tox -e dev.k8s.destroy || true"
bash -c "CLUSTER_NAME=${GATEWAY_CLUSTER_NAME} tox -e dev.k8s.destroy || true"
bash -c "k3d registry delete k3d-registry.localhost || true"
bash -c "docker volume rm k3d-${DATASITE_CLUSTER_NAME}-images --force || true"
bash -c "docker volume rm k3d-${GATEWAY_CLUSTER_NAME}-images --force || true"
[testenv:stack.test.notebook.k8s]
description = Notebook Tests for Core Stack using K8s
basepython = python3
deps =
{[testenv:syft]deps}
nbmake
changedir = {toxinidir}
passenv=HOME, USER
allowlist_externals =
devspace
kubectl
grep
sleep
bash
k3d
echo
tox
setenv =
ORCHESTRA_DEPLOYMENT_TYPE = {env:ORCHESTRA_DEPLOYMENT_TYPE:remote}
GITHUB_CI = {env:GITHUB_CI:false}
SYFT_BASE_IMAGE_REGISTRY = {env:SYFT_BASE_IMAGE_REGISTRY:k3d-registry.localhost:5800}
DATASITE_CLUSTER_NAME = {env:DATASITE_CLUSTER_NAME:test-datasite-1}
SERVER_URL = {env:SERVER_URL:http://localhost}
SERVER_PORT = {env:SERVER_PORT:8080}
commands =
bash -c "echo Running with GITHUB_CI=$GITHUB_CI; date"
python -c 'import syft as sy; sy.stage_protocol_changes()'
k3d version
# Deleting Old Cluster
bash -c "k3d cluster delete ${DATASITE_CLUSTER_NAME} || true"
# Deleting registry & volumes
bash -c "k3d registry delete k3d-registry.localhost || true"
bash -c "docker volume rm k3d-${DATASITE_CLUSTER_NAME}-images --force || true"
# Create registry
tox -e dev.k8s.registry
# Creating test-datasite-1 cluster on port SERVER_PORT
bash -c '\
export CLUSTER_NAME=${DATASITE_CLUSTER_NAME} CLUSTER_HTTP_PORT=${SERVER_PORT} && \
tox -e dev.k8s.start && \
tox -e dev.k8s.deploy'
# free up build cache after build of images
bash -c 'if [[ "$GITHUB_CI" != "false" ]]; then \
docker image prune --all --force; \
docker builder prune --all --force; \
fi'
sleep 30
# wait for test-datasite-1
bash packages/grid/scripts/wait_for.sh service mongo --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service backend --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service proxy --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service seaweedfs --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash packages/grid/scripts/wait_for.sh service frontend --context k3d-{env:DATASITE_CLUSTER_NAME} --namespace syft
bash -c '(kubectl logs service/frontend --context k3d-${DATASITE_CLUSTER_NAME} --namespace syft -f &) | grep -q -E "Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/" || true'
# Checking logs generated & startup of test-datasite 1
bash -c '(kubectl logs service/backend --context k3d-${DATASITE_CLUSTER_NAME} --namespace syft -f &) | grep -q "Application startup complete" || true'
bash -c "pytest -x --nbmake notebooks/api/0.8 -p no:randomly -k 'not 10-container-images.ipynb' -vvvv --nbmake-timeout=1000"
# deleting clusters created
bash -c "CLUSTER_NAME=${DATASITE_CLUSTER_NAME} tox -e dev.k8s.destroy || true"
bash -c "k3d registry delete k3d-registry.localhost || true"
bash -c "docker volume rm k3d-${DATASITE_CLUSTER_NAME}-images --force || true"
[testenv:syft.build.helm]
description = Build Helm Chart for Kubernetes
changedir = {toxinidir}
passenv=HOME, USER
allowlist_externals =
bash
helm
commands =
bash -c 'cd packages/grid/helm && \
python3 generate_helm_notes.py ./syft/templates'
bash -c 'cd packages/grid/helm && \
helm lint syft'
[testenv:syft.lint.helm]
description = Lint helm chart
changedir = {toxinidir}/packages/grid/helm
passenv=HOME, USER
allowlist_externals =
bash
commands =
bash -c 'kube-linter lint ./syft --config ./kubelinter-config.yaml'
[testenv:syft.package.helm]
description = Package Helm Chart for Kubernetes
deps =
changedir = {toxinidir}
passenv=HOME, USER
allowlist_externals =
bash
helm
commands =
bash -c 'cd packages/grid/helm && \
helm lint syft'
bash -c 'cd packages/grid/helm/syft && \
helm dependency update'
bash -c 'cd packages/grid/helm && \
helm package syft --destination repo'
bash -c 'cd packages/grid/helm/repo && \
helm repo index . --url https://openmined.github.io/PySyft/helm'
[testenv:dev.k8s.ready]
description = Check readiness of k8s deployement
changedir = {toxinidir}/packages/grid
allowlist_externals =
bash
tox
curl
setenv =
CLUSTER_NAME = {env:CLUSTER_NAME:syft}
CLUSTER_HTTP_PORT = {env:SERVER_PORT:8080}
; Usage for posargs: names of the relevant services among {frontend backend proxy mongo seaweedfs registry}
commands =
bash -c "env; date; k3d version"
# Frontend
bash -c "if echo '{posargs}' | grep -q 'frontend'; then \
echo 'Checking readiness of frontend'; \
./scripts/wait_for.sh service frontend --context k3d-$CLUSTER_NAME --namespace syft && \
(kubectl logs service/frontend --context k3d-$CLUSTER_NAME --namespace syft -f &) | grep -q -E 'Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/' || true; \
fi"
# Backend
bash -c "if echo '{posargs}' | grep -q 'backend'; then \
echo 'Checking readiness of backend'; \
./scripts/wait_for.sh service backend --context k3d-$CLUSTER_NAME --namespace syft && \
(kubectl logs service/backend --context k3d-$CLUSTER_NAME --namespace syft -f &) | grep -q 'Application startup complete' || true; \
fi"
# Mongo
bash -c "if echo '{posargs}' | grep -q 'mongo'; then echo 'Checking readiness of Mongo'; ./scripts/wait_for.sh service mongo --context k3d-$CLUSTER_NAME --namespace syft; fi"
# Proxy
bash -c "if echo '{posargs}' | grep -q 'proxy'; then echo 'Checking readiness of proxy'; ./scripts/wait_for.sh service proxy --context k3d-$CLUSTER_NAME --namespace syft; fi"
# Seaweedfs
bash -c "if echo '{posargs}' | grep -q 'seaweedfs'; then echo 'Checking readiness of SeaweedFS'; ./scripts/wait_for.sh service seaweedfs --context k3d-$CLUSTER_NAME --namespace syft; fi"
# Registry
bash -c "if echo '{posargs}' | grep -q 'registry'; then echo 'Checking readiness of Registry'; ./scripts/wait_for.sh service registry --context k3d-$CLUSTER_NAME --namespace syft; fi"
# Extra
bash -c "curl http://localhost:${CLUSTER_HTTP_PORT}/api/v2/metadata"
[testenv:syft.test.helm]
description = Test Helm Chart for Kubernetes
changedir = {toxinidir}/packages/grid
passenv=HOME, USER, EXTERNAL_REGISTRY_USERNAME, EXTERNAL_REGISTRY_PASSWORD
allowlist_externals =
bash
tox
setenv =
ORCHESTRA_DEPLOYMENT_TYPE = {env:ORCHESTRA_DEPLOYMENT_TYPE:remote}
SERVER_PORT = {env:SERVER_PORT:8080}
SERVER_URL = {env:SERVER_URL:http://localhost}
EXCLUDE_NOTEBOOKS = {env:EXCLUDE_NOTEBOOKS:not 10-container-images.ipynb}
SYFT_VERSION = {env:SYFT_VERSION:local}
EXTERNAL_REGISTRY = {env:EXTERNAL_REGISTRY:k3d-registry.localhost:5800}
; env vars for dev.k8s.start
CLUSTER_NAME = testdatasite
CLUSTER_HTTP_PORT = {env:SERVER_PORT:8080}
; Usage for posargs: if you pass override to this tox command, then resourcesPreset will be overridden
commands =
bash -c "env; date; k3d version"
bash -c "k3d cluster delete ${CLUSTER_NAME} || true"
tox -e dev.k8s.start
bash -c 'if [[ $SYFT_VERSION == "local" ]]; then \
echo "Installing local helm charts"; \
if [[ "{posargs}" == "override" ]]; then \
echo "Overriding resourcesPreset"; \
helm install ${CLUSTER_NAME} ./helm/syft -f ./helm/examples/dev/base.yaml --kube-context k3d-${CLUSTER_NAME} --namespace syft --create-namespace --set server.resourcesPreset=null --set seaweedfs.resourcesPreset=null --set mongo.resourcesPreset=null --set registry.resourcesPreset=null --set proxy.resourcesPreset=null --set frontend.resourcesPreset=null; \
else \
helm install ${CLUSTER_NAME} ./helm/syft -f ./helm/examples/dev/base.yaml --kube-context k3d-${CLUSTER_NAME} --namespace syft --create-namespace; \
fi \
else \
echo "Installing helm charts from repo for syft version: ${SYFT_VERSION}"; \
helm repo add openmined https://openmined.github.io/PySyft/helm; \
helm repo update openmined; \
if [[ "{posargs}" == "override" ]]; then \
echo "Overriding resourcesPreset"; \
helm install ${CLUSTER_NAME} openmined/syft --version=${SYFT_VERSION} -f ./helm/examples/dev/base.yaml --kube-context k3d-${CLUSTER_NAME} --namespace syft --create-namespace --set server.resourcesPreset=null --set seaweedfs.resourcesPreset=null --set mongo.resourcesPreset=null --set registry.resourcesPreset=null --set proxy.resourcesPreset=null --set frontend.resourcesPreset=null; \
else \
helm install ${CLUSTER_NAME} openmined/syft --version=${SYFT_VERSION} -f ./helm/examples/dev/base.yaml --kube-context k3d-${CLUSTER_NAME} --namespace syft --create-namespace; \
fi \
fi'
; wait for everything else to be loaded
tox -e dev.k8s.ready -- frontend backend mongo proxy seaweedfs registry
# Run Notebook tests
tox -e e2e.test.notebook
bash -c "k3d cluster delete ${CLUSTER_NAME} || true"
[testenv:syft.test.helm.upgrade]
description = Test helm upgrade
changedir = {toxinidir}/packages/grid/
passenv=HOME,USER,KUBE_CONTEXT
setenv =
UPGRADE_TYPE = {env:UPGRADE_TYPE:ProdToBeta}
allowlist_externals =
bash
commands =
bash ./scripts/helm_upgrade.sh {env:UPGRADE_TYPE}
[testenv:syftcli.test.unit]
description = Syft CLI Unit Tests
deps =
{[testenv:syftcli]deps}
changedir = {toxinidir}/packages/syftcli
allowlist_externals =
uv
pytest
commands =
pytest
[testenv:dev.k8s.registry]
description = Start local Kubernetes registry with k3d
changedir = {toxinidir}
passenv=HOME,USER
allowlist_externals =
bash
sudo
commands =
; check k3d version
bash -c 'k3d --version'
; create registry
bash -c 'docker volume create k3d-registry-vol || true'
bash -c 'k3d registry create registry.localhost --port 5800 -v k3d-registry-vol:/var/lib/registry --no-help || true'
; add patches to host
bash -c 'if ! grep -q k3d-registry.localhost /etc/hosts; then sudo {envpython} scripts/patch_hosts.py --add-k3d-registry --fix-docker-hosts; fi'
; Fail this command if registry is not working
bash -c 'curl --retry 5 --retry-all-errors http://k3d-registry.localhost:5800/v2/_catalog'
[testenv:dev.k8s.patch.coredns]
description = Patch CoreDNS to resolve k3d-registry.localhost
changedir = {toxinidir}
passenv=HOME,USER,CLUSTER_NAME
setenv =
CLUSTER_NAME = {env:CLUSTER_NAME:syft-dev}
allowlist_externals =
bash
commands =
; patch coredns so k3d-registry.localhost works in k3d
bash -c 'kubectl apply -f ./scripts/k8s-coredns-custom.yml --context k3d-${CLUSTER_NAME}'
; restarts coredns
bash -c 'kubectl delete pod -n kube-system -l k8s-app=kube-dns --context k3d-${CLUSTER_NAME}'
[testenv:dev.k8s.start]
description = Start local Kubernetes registry & cluster with k3d
changedir = {toxinidir}
passenv = HOME, USER
setenv =
CLUSTER_NAME = {env:CLUSTER_NAME:syft-dev}
CLUSTER_HTTP_PORT = {env:CLUSTER_HTTP_PORT:8080}
allowlist_externals =
bash
sleep
tox
commands =
; start registry
tox -e dev.k8s.registry
; for NodePort to work add the following --> -p "NodePort:NodePort@loadbalancer"
bash -c 'k3d cluster create ${CLUSTER_NAME} -p "${CLUSTER_HTTP_PORT}:80@loadbalancer" --registry-use k3d-registry.localhost:5800 {posargs} && \
kubectl --context k3d-${CLUSTER_NAME} create namespace syft || true'
; patch coredns
tox -e dev.k8s.patch.coredns
; dump cluster info
tox -e dev.k8s.info
[testenv:dev.k8s.deploy]
description = Deploy Syft to a local Kubernetes cluster with Devspace
changedir = {toxinidir}/packages/grid
passenv = HOME, USER, DEVSPACE_PROFILE
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:syft-dev}
allowlist_externals =
bash
commands =
; deploy syft helm charts
bash -c '\
if [[ -n "${DEVSPACE_PROFILE}" ]]; then export DEVSPACE_PROFILE="-p ${DEVSPACE_PROFILE}"; fi && \
devspace deploy -b --kube-context k3d-${CLUSTER_NAME} --no-warn ${DEVSPACE_PROFILE} --namespace syft --var CONTAINER_REGISTRY=k3d-registry.localhost:5800'
[testenv:dev.k8s.hotreload]
description = Start development with hot-reload in Kubernetes
changedir = {toxinidir}/packages/grid
passenv = HOME, USER, DEVSPACE_PROFILE
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:syft-dev}
allowlist_externals =
bash
commands =
; deploy syft helm charts with hot-reload
bash -c '\
if [[ -n "${DEVSPACE_PROFILE}" ]]; then export DEVSPACE_PROFILE="-p ${DEVSPACE_PROFILE}"; fi && \
devspace dev --kube-context k3d-${CLUSTER_NAME} --no-warn ${DEVSPACE_PROFILE} --namespace syft --var CONTAINER_REGISTRY=k3d-registry.localhost:5800'
[testenv:dev.k8s.info]
description = Gather info about the localKubernetes cluster
passenv = HOME, USER
ignore_errors = True
allowlist_externals =
k3d
kubectl
commands =
k3d cluster list
kubectl cluster-info
kubectl config current-context
kubectl get namespaces
[testenv:dev.k8s.cleanup]
description = Cleanup Syft deployment and associated resources, but keep the cluster running
changedir = {toxinidir}/packages/grid
passenv=HOME, USER
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:syft-dev}
allowlist_externals =
bash
commands =
bash -c 'devspace purge --force-purge --kube-context k3d-${CLUSTER_NAME} --no-warn --namespace syft; sleep 3'
bash -c 'devspace cleanup images --kube-context k3d-${CLUSTER_NAME} --no-warn --namespace syft --var CONTAINER_REGISTRY=k3d-registry.localhost:5800 || true'
bash -c 'kubectl --context k3d-${CLUSTER_NAME} delete namespace syft --now=true || true'
[testenv:dev.k8s.render]
description = Dump devspace rendered chargs for debugging. Save in `packages/grid/out.render`
changedir = {toxinidir}/packages/grid
passenv = HOME, USER, DEVSPACE_PROFILE
setenv=
OUTPUT_DIR = {env:OUTPUT_DIR:./.devspace/rendered}
allowlist_externals =
bash
commands =
bash -c '\
if [[ -n "${DEVSPACE_PROFILE}" ]]; then export DEVSPACE_PROFILE="-p ${DEVSPACE_PROFILE}"; fi && \
rm -rf ${OUTPUT_DIR} && \
mkdir -p ${OUTPUT_DIR} && \
echo "profile: $DEVSPACE_PROFILE" && \
devspace print ${DEVSPACE_PROFILE} > ${OUTPUT_DIR}/config.txt && \
devspace deploy --render --skip-build --no-warn ${DEVSPACE_PROFILE} --namespace syft --var CONTAINER_REGISTRY=k3d-registry.localhost:5800 > ${OUTPUT_DIR}/chart.yaml'
[testenv:dev.k8s.launch.gateway]
description = Launch a single gateway on K8s
passenv = HOME, USER
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:test-gateway-1}
CLUSTER_HTTP_PORT={env:CLUSTER_HTTP_PORT:9081}
DEVSPACE_PROFILE=gateway
allowlist_externals =
tox
commands =
tox -e dev.k8s.start
tox -e dev.k8s.{posargs:deploy}
[testenv:dev.k8s.launch.datasite]
description = Launch a single datasite on K8s
passenv = HOME, USER
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:test-datasite-1}
CLUSTER_HTTP_PORT={env:CLUSTER_HTTP_PORT:9082}
allowlist_externals =
tox
commands =
tox -e dev.k8s.start
tox -e dev.k8s.{posargs:deploy}
[testenv:dev.k8s.launch.enclave]
description = Launch a single Enclave on K8s
passenv = HOME, USER
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:test-enclave-1}
CLUSTER_HTTP_PORT={env:CLUSTER_HTTP_PORT:9083}
DEVSPACE_PROFILE=enclave
allowlist_externals =
tox
commands =
tox -e dev.k8s.start -- --volume /sys/kernel/security:/sys/kernel/security --volume /dev/tmprm0:/dev/tmprm0
tox -e dev.k8s.{posargs:deploy}
[testenv:dev.k8s.destroy]
description = Destroy local Kubernetes cluster
changedir = {toxinidir}/packages/grid
passenv = HOME, USER
setenv=
CLUSTER_NAME = {env:CLUSTER_NAME:syft-dev}
allowlist_externals =
tox
bash
commands =
; destroy cluster
bash -c '\
rm -rf .devspace; echo ""; \
k3d cluster delete ${CLUSTER_NAME};'
[testenv:dev.k8s.destroyall]
description = Destroy both local Kubernetes cluster and registry
changedir = {toxinidir}
passenv = HOME, USER, CLUSTER_NAME
ignore_errors=True
allowlist_externals =
bash
tox
commands =
; destroy cluster
tox -e dev.k8s.destroy
; destroy registry
bash -c 'k3d registry delete registry.localhost || true'
bash -c 'docker volume rm k3d-registry-vol --force || true'
[testenv:backend.test.basecpu]
description = Base CPU Docker Image Test
changedir = {toxinidir}/packages
allowlist_externals =
docker
bash
env
setenv =
PIP_PACKAGES = {env:PIP_PACKAGES:llama-index opendp}
SYSTEM_PACKAGES = {env:SYSTEM_PACKAGES:curl wget}
BUILD_PLATFORM = {env:BUILD_PLATFORM:linux/amd64}
commands =
env
; Build the base image
bash -c 'docker buildx build \
--platform $BUILD_PLATFORM \
-f ./grid/backend/grid/images/worker_cpu.dockerfile . \
-t cpu-worker:latest'
bash -c 'docker rmi cpu-worker:latest'
bash -c '\
docker buildx build \
--platform $BUILD_PLATFORM \
-f grid/backend/grid/images/worker_cpu.dockerfile . \