-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharc_cli.sh
More file actions
executable file
·1871 lines (1769 loc) · 70.7 KB
/
Copy patharc_cli.sh
File metadata and controls
executable file
·1871 lines (1769 loc) · 70.7 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
#!/bin/bash
# shellcheck disable=SC2086
# Set the Project Name for docker-compose note: cannot be done any other way
# other than setting it as part of the docker-compose COMMAND -p flag.
export COMPOSE_PROJECT_NAME='arc'
# ======================================================= #
# ==================== # Variables # ==================== #
# ======================================================= #
VERSION=1.1.2
WORKDIR=$(dirname "$(readlink -f "$0")")
DOCKER_COMPOSE_PATH="${WORKDIR}/docker-compose.yml"
ARGS=""
CONTAINER_GROUP=""
CONTAINER_ARGS="arclytics simcct client redis mongodb nginx celery-worker fluentd elasticsearch kibana apm-server"
CONTAINER_LOG=""
LOGS_WATCH=0
FLUSH_ALL=0
BUILD_CONTAINER_ARGS=""
BUILD_FLAG=0
DETACH_FLAG=0
SEED_DB_FLAG=0
SCALE_FLAG=0
SCALE_CONTAINERS_ARGS=""
DOCKER_DOWN_FLAG=0
SWAGGER_FLAG=0
JUPYTER_FLAG=0
PRODUCTION_DATA=0
MONGO_USERNAME=""
MONGO_PASSWORD=""
MONGO_APP_DB=""
TEST_SERVER_ARGS=""
TEST_TYPE="test"
TEST_TITLE="Flask-Testing Unittests (without coverage)"
tty=0
printWidth=0
terminalColWidth=$(tput cols)
# ========================================================= #
# ==================== # ANSI colors # ==================== #
# ========================================================= #
##### -- use these variables to make output in differen colors
esc="\033"; # if this doesn't work, enter an ESC directly
# Foreground colours
# shellcheck disable=SC2034
blackf="${esc}[30m"; redf="${esc}[31m"; greenf="${esc}[32m"; yellowf="${esc}[33m"
# shellcheck disable=SC2034
bluef="${esc}[34m"; purplef="${esc}[35m"; cyanf="${esc}[36m"; whitef="${esc}[37m"
# Background colors
# shellcheck disable=SC2034
blackb="${esc}[40m"; redb="${esc}[41m"; greenb="${esc}[42m"; yellowb="${esc}[43m"
# shellcheck disable=SC2034
blueb="${esc}[44m"; purpleb="${esc}[45m"; cyanb="${esc}[46m"; whiteb="${esc}[47m"
# Bold, italic, underline, and inverse style toggles
# shellcheck disable=SC2034
boldon="${esc}[1m"; boldoff="${esc}[22m"; italicson="${esc}[3m";
# shellcheck disable=SC2034
italicsoff="${esc}[23m"; ulon="${esc}[4m"; uloff="${esc}[24m";
# shellcheck disable=SC2034
invon="${esc}[7m"; invoff="${esc}[27m";
reset="${esc}[0m"
# ====================================================== #
# ==================== # Messages # ==================== #
# ====================================================== #
function headerMessage() { echo -e "${greenf}${boldon}# [ARCLYTICS CLI] | $1${boldoff}${reset}"; }
function actionMessage() { echo -e "${whiteb}${redf}${boldon}# [ARCLYTICS CLI] | $1...${boldoff}${reset}"; echo ""; }
function generalMessage() { echo -e "${yellowf}# [ARCLYTICS CLI] | $1${reset}"; }
function echoSpace() { echo ""; }
function completeMessage() { echo -e "${greenf}${boldon}# [ARCLYTICS CLI] | Complete${boldoff}${reset}"; }
function echoLine() {
width=$terminalColWidth-4;
printWidth=0
echo -ne "${greenf}${boldon}# "
while [[ ${printWidth} -lt ${width} ]]; do
echo -n -e "=";
printWidth=$printWidth+1;
done
echo -n -e "${greenf}${boldon} #${boldoff}${reset}"
}
# =============================================================== #
# ==================== # Utility Functions # ==================== #
# =============================================================== #
# Read the .env file and get the password
getMongoUserAndPassword() {
input="${WORKDIR}/.env"
user_key=""
pass_key=""
if [[ $1 == 'root' ]]; then
user_key='MONGO_ROOT_USER'
pass_key='MONGO_ROOT_PASSWORD'
elif [[ $1 == 'user' ]]; then
user_key="MONGO_APP_USER"
pass_key="MONGO_APP_USER_PASSWORD"
fi
if [[ ${user_key} != "" ]]; then
while IFS= read -r line
do
KEY="$(cut -d'=' -f1 <<< "${line}" )"
if [[ ${KEY} == "${user_key}" ]]; then
MONGO_USERNAME="$(cut -d'=' -f2 <<< "${line}" )"
fi
if [[ ${KEY} == "${pass_key}" ]]; then
MONGO_PASSWORD="$(cut -d'=' -f2 <<< "${line}" )"
fi
if [[ ${KEY} == "MONGO_APP_DB" ]]; then
MONGO_APP_DB="$(cut -d'=' -f2 <<< "${line}" )"
fi
done < "$input"
fi
}
# Run only the arclytics tests
arcTest() {
headerMessage "RUNNING ARCLYTICS SERVER TESTS"
generalMessage "Beginning ${TEST_TITLE} for Arclytics Server"
echoSpace
if [[ ${tty} == 1 ]]; then
generalMessage "docker-compose exec -T arclytics python manage.py ${TEST_TYPE}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec -T arclytics python manage.py "${TEST_TYPE}"
else
generalMessage "docker-compose exec arclytics python manage.py ${TEST_TYPE}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec arclytics python manage.py "${TEST_TYPE}"
fi
generalMessage "Finishing ${TEST_TITLE} for Users Server"
}
# Run only the simcct server tests
simcct() {
headerMessage "RUNNING SIMCCT SERVER TESTS"
generalMessage "Beginning ${TEST_TITLE} for SimCCT Server"
echoSpace
if [[ ${tty} == 1 ]]; then
generalMessage "docker-compose exec -T simcct python manage.py ${TEST_TYPE}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec -T simcct python manage.py "${TEST_TYPE}"
else
generalMessage "docker-compose exec simcct python manage.py ${TEST_TYPE}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py "${TEST_TYPE}"
fi
generalMessage "Finishing ${TEST_TITLE} for SimCCT Server"
}
# Run server-side tests
server() {
simcct
}
client() {
pass
}
# run all tests
all() {
simcct
arcTest
# client
# e2e
}
groupUsage() {
echo -e """
${greenf}ARCLYTICS CLI SCRIPT
Usage:
arc_cli.sh [options...] up --group [SERVICE GROUP]
arc_cli.sh --group [SERVICE GROUP] up [options...]
The Arclytics CLI group flag command to run a group of docker-compose services
based on the available service groups.
Options:
-b, --build Build the Docker containers before running.
-d, --detach Run Docker Engine logs in a detached shell mode.
-s, --seed_db Seed the MongoDB database with test data.
Service Group:
all Run all available services which includes the following:
arclytics, simcct, redis, mongodb, dask-scheduler,
dask-worker, jupyter, swagger, fluentd, elasticsearch,
kibana, client.
e2e Run the services to with the front-end client and back-end
microservices to test an end-to-end example of any feature.
This includes: client, simcct, mongodb, redis.
server Run all services related to the back-end microservices and
database which includes the following: simcct, mongodb, redis.
server-dask Run all services related to the back-end and include the
\`dask\` containers. This includes: simcct, mongodb, redis,
dask-scheduler, dask-worker.
client Run only the client microservice.
dask Run only the services to test the \`dask\` containers which
includes: dask-scheduler, dask-worker, jupyter.
fluentd Run only the microservices with the \`fluentd\` logging
container and associated containers for storage. This
includes: fluentd, elasticsearch, kibana.
fluentd-test Run only the microservices for \`fluentd\` testing with a
basic Flask API server and a production build React app.
This includes: fluent-python, fluent-react, fluentd, kibana,
elasticsearch.
swagger-test Run the microservices to test the back-end API from swagger.
This includes: swagger, simcct, redis, mongodb.
${reset}
"""
}
# shellcheck disable=SC1079,SC1078,SC2006
upUsage() {
echo -e """
${greenf}ARCLYTICS CLI SCRIPT
Usage: arc_cli.sh up [options] [SERVICE ARGS...]
The Arclytics CLI command to run the containers.
Options:
-b, --build Build the Docker containers before running.
-d, --detach Run Docker Engine logs in a detached shell mode.
-s, --seed_db Seed the MongoDB database with test data.
--scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the
\`--scale\` setting in the Compose file if present
-G, --group GROUP Specify a GROUP of services to use to run. You can use
\`help\` to get more information about groups available.
-h, --help Get the Usage information for this COMMAND.
Optional Containers:
-S, --swagger Run the Swagger container with the cluster.
-J, --jupyter Run the Jupyter container with the cluster.
Service (only one for \`logs\`; * default for \`up\`):
client *
nginx *
simcct *
arclytics *
celery-worker *
redis *
mongodb *
elasticsearch *
apm-server *
kibana *
dask-scheduler
dask-worker
jupyter
swagger
${reset}
"""
}
# shellcheck disable=SC1079
testUsage() {
# shellcheck disable=SC1078
echo -e """
${greenf}ARCLYTICS CLI SCRIPT
Usage: arc_cli.sh test [OPTIONS] [TEST TYPE]
The Arclytics CLI command to run Unit Tests.
Options:
-b, --build Build the Docker containers before running tests.
-t, --tty Attach a pseudo-TTY to the tests.
-c, --coverage Run the unit tests with coverage.
-f, --file Set the path of the docker-compose YAML file to use.
-h, --help Get the Usage information for this command.
Test Types (one only):
all Run all unit tests for Arclytics Sim
server Run the server-side unit tests.
client Run the client-side unit tests.
arclytics Run only the arclytics tests.
simcct Run only the simcct tests.
${reset}
"""
}
# shellcheck disable=SC1079
usage() {
# shellcheck disable=SC1078
echo -e """
${greenf}ARCLYTICS CLI SCRIPT
The Arclytics CLI script for running \`docker\` and \`docker-compose\` commands on the
Arclytics Sim Docker orchestration.
Usage:
arc_cli.sh build [SERVICE ARGS...]
arc_cli.sh up [options] [SERVICE ARGS...]
arc_cli.sh up --scale [SERVICE=NUM]
arc_cli.sh logs [SERVICE]
arc_cli.sh test [options] [TEST TYPE]
arc_cli.sh down [options]
arc_cli.sh scale [SERVICE=NUM...]
arc_cli.sh [COMMAND] [ARGS...]
Options:
-b, --build Build the Docker containers before running.
-d, --detach Run Docker Engine logs in a detached shell mode.
-s, --seed_db Seed the MongoDB database with test data.
-f, --file Set the path of the docker-compose YAML file to use.
-h, --help Get the Usage information for this script.
Up Options:
--scale SERVICE=NUM Scale the a single container when running the cluster.
-S, --swagger Run the Swagger container with the cluster.
-J, --jupyter Run the Jupyter container with the cluster.
Test Options:
-b, --build Build the Docker containers before running tests.
-t, --tty Attach a pseudo-TTY to the tests.
-c, --coverage Run the unit tests with coverage.
Down Options:
-D, --docker Stop the containers using the Docker PS stat.
System Options:
usage, df Show docker disk usage.
events Get real time events from the server.
info Display the system-wide information.
Management Commands:
container Manage containers. Run \`help | --help\` to get usage options.
image Manage image. Run \`help | --help\` to get usage options.
system Manage Docker system. Additional options available.
Commands:
build Build the Docker images from docker-compose.yml only (passing services
to build specific ones or leave empty to build all).
down Stop all containers.
flush Flush both Redis datastore and MongoDB database only.
images List images build.
logs Get the logs of the container.
ls List all containers, volumes, and images with formatting.
mongo Connect to the \`mongo\` CLI running in the container.
ps List the running containers.
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
prune Prune all stopped images, containers, networks, and volumes based
on the \`labels\` used for this project.
pwd Get the full path directory of the Arclytics CLI script.
seed Seed the microservices with test data and flush both Redis
datastore and MongoDB database.
scale Set number of containers to run for a service. Numbers are specified
in the form \`service=num\` as arguments.
minikube Use as a wrapper for the minikube service.
stats Display a live stream of container(s) resource usage statistics.
test Run unit tests on the microservices.
up Run the main containers in docker-compose.yml or provide a list of
arguments to run only those provided.
help Get the Usage information for this script and exit.
Service (only one for \`logs\`; * default for \`up\`):
client *
nginx *
simcct *
arclytics *
celery-worker *
redis *
mongodb *
elasticsearch *
apm-server *
kibana *
dask-scheduler
dask-worker
jupyter
swagger
Test Types (one only):
all Run all unit tests for Arclytics Sim
server Run the server-side unit tests.
client Run the client-side unit tests.
arclytics Run only the arclytics tests.
simcct Run only the simcct tests.
${reset}
"""
}
# ==================================================================== #
# ==================== # Main Command Functions # ==================== #
# ==================================================================== #
dockerLsFormatted() {
echo
headerMessage "ARCLYTICS SIM DOCKER CONTAINERS, VOLUMES, AND IMAGES"
echoLine
generalMessage "Containers"
echoLine
docker container ls -a --format \
"table {{.ID}}\t{{.Image}}\t{{.RunningFor}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}" \
--filter "label=arclytics.io"
echoLine
generalMessage "Volumes"
echoLine
docker volume ls --format \
"table {{.Name}}\t{{.Labels}}\t{{.Driver}}\t{{.Mountpoint}}" \
# --filter "label=arclytics.io"
echoLine
generalMessage "Images"
echoLine
docker image ls --format \
"table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}" \
--filter "label=arclytics.io"
echoLine
completeMessage
echo
}
dockerPs() {
headerMessage "ARCLYTICS SIM RUNNING CONTAINERS"
generalMessage "docker ps --size ${ARGS}"
docker ps --size ${ARGS}
completeMessage
}
dockerLogs() {
if [[ $LOGS_WATCH == 1 ]] ; then
echo "watch docker-compose -f ${DOCKER_COMPOSE_PATH} logs ${CONTAINER_LOG}"
watch docker-compose -f "${DOCKER_COMPOSE_PATH}" logs ${CONTAINER_LOG}
else
headerMessage "ARCLYTICS SIM CONTAINER LOGS"
generalMessage "docker-compose logs ${CONTAINER_LOG}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" logs ${CONTAINER_LOG}
fi
completeMessage
}
dockerStats() {
headerMessage "ARCLYTICS SIM CONTAINER STATS"
generalMessage "docker stats ${ARGS}"
docker stats ${ARGS}
}
dockerSystemPrune() {
headerMessage "PRUNE ARCLYTICS SIM DOCKER ORCHESTRATION"
running_container_ids=$(docker ps -aq)
generalMessage "docker stop ${running_container_ids}"
docker stop ${running_container_ids}
generalMessage "docker system prune -af --volumes --filter 'label=arclytics.io'"
docker volume prune -f
docker system prune -af --volumes --filter 'label=arclytics.io'
completeMessage
}
containerDown() {
headerMessage "STOPPING ARCLYTICS SIM CONTAINERS"
if [[ "${DOCKER_DOWN_FLAG}" == 1 ]]; then
running=$(docker ps -aq)
if [[ ${running} == "" ]]; then
generalMessage "No containers running"
docker ps
else
generalMessage "docker stop \$(docker ps -aq)"
# shellcheck disable=SC2046
docker stop ${running}
fi
else
generalMessage "docker-compose down ${ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" down ${ARGS}
fi
completeMessage
}
buildContainers() {
headerMessage "BUILDING ARCLYTICS SIM CONTAINERS ONLY"
generalMessage "docker-compose build ${BUILD_CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" build ${BUILD_CONTAINER_ARGS}
}
scaleContainers() {
headerMessage "SCALING ARCLYTICS SIM CONTAINERS"
docker-compose -f "${DOCKER_COMPOSE_PATH}" scale ${SCALE_CONTAINERS_ARGS}
completeMessage
}
flushDb() {
headerMessage "FLUSH BACK-END MICROSERVICES"
generalMessage "Flushing simcct microservice database (Redis and MongoDB)"
if [[ $FLUSH_ALL == 1 ]] ; then
generalMessage "docker-compose exec simcct python manage.py flush_all"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py flush_all
else
generalMessage "docker-compose exec simcct python manage.py flush"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py flush
fi
}
# Flush and seed database
flushAndSeedDb() {
if [[ $PRODUCTION_DATA == 1 ]]; then
headerMessage "SEED AND FLUSH BACK-END MICROSERVICES (WITH PRODUCTION DATA)"
generalMessage "Flushing simcct microservice database (Redis and MongoDB)"
generalMessage "docker-compose exec simcct python manage.py flush_all"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py flush
echoSpace
generalMessage "Seeding simcct microservice database with global alloys"
generalMessage "docker-compose exec simcct python manage.py seed_db"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python load_production_data.py
echoSpace
else
headerMessage "SEED AND FLUSH BACK-END MICROSERVICES"
generalMessage "Flushing simcct microservice database (Redis and MongoDB)"
generalMessage "docker-compose exec simcct python manage.py flush_all"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py flush
echoSpace
generalMessage "Seeding simcct microservice database with global alloys"
generalMessage "docker-compose exec simcct python manage.py seed_db"
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py seed_db
docker-compose -f "${DOCKER_COMPOSE_PATH}" exec simcct python manage.py seed_alloys_db
echoSpace
fi
}
getLatestKubeVersion() {
LATEST=$(\gcloud container get-server-config \
${LOCATION_COMMAND} \
--project=${PROJECT_ID} \
--format="json" \
| jq --raw-output '
def to_gke_semver(o):
capture("(?<major>[0-9]*).(?<minor>[0-9]*).(?<patch>[0-9]*)-gke.(?<gke>[0-9]*)");
def from_gke_semver(o):
.major + "." + .minor + "." + .patch + "-gke." + .gke;
reduce (
.validMasterVersions[] | to_gke_semver(.)
) as $this (
{
"major":"0",
"minor":"0",
"patch": "0",
"gke": "0"
};
if ($this.major|tonumber) > (.major|tonumber)
then . = $this
else (
if ($this.major|tonumber) == (.major|tonumber)
then (
if ($this.minor|tonumber) > (.minor|tonumber)
then . = $this
else (
if ($this.minor|tonumber) == (.minor|tonumber)
then (
if ($this.patch|tonumber) > (.patch|tonumber)
then . = $this
else (
if ($this.patch|tonumber) == (.patch|tonumber)
then (
if ($this.gke|tonumber) > (.gke|tonumber)
then . = $this
else .
end
)
else .
end
)
end
)
else .
end
)
end
)
else .
end
)
end
) | from_gke_semver(.)
')
}
# shellcheck disable=SC2086
runTests() {
# Make sure the correct container groups are run for each test.
# By default, we ensure the server back-end ones are running
CONTAINER_GROUP="server"
changeContainerGroup
## run appropriate tests
if [[ "${TEST_SERVER_ARGS}" == "server" ]]; then
if [[ ${BUILD_FLAG} == 1 ]]; then
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build "${CONTAINER_ARGS}"
server
generalMessage "docker-compose down"
docker-compose -f "${DOCKER_COMPOSE_PATH}" down
else
server
fi
elif [[ "${TEST_SERVER_ARGS}" == "arclytics" ]]; then
if [[ ${BUILD_FLAG} == 1 ]]; then
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build "${CONTAINER_ARGS}"
arcTest
generalMessage "docker-compose down"
docker-compose -f "${DOCKER_COMPOSE_PATH}" down
else
arcTest
fi
elif [[ "${TEST_SERVER_ARGS}" == "simcct" ]]; then
if [[ ${BUILD_FLAG} == 1 ]]; then
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build "${CONTAINER_ARGS}"
simcct
generalMessage "docker-compose down"
docker-compose -f "${DOCKER_COMPOSE_PATH}" down
else
simcct
fi
elif [[ "${TEST_SERVER_ARGS}" == "client" ]]; then
if [[ ${BUILD_FLAG} == 1 ]]; then
CONTAINER_GROUP="client"
changeContainerGroup
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build "${CONTAINER_ARGS}"
client
generalMessage "docker-compose down"
docker-compose -f "${DOCKER_COMPOSE_PATH}" down
fi
elif [[ "${TEST_SERVER_ARGS}" == "e2e" ]]; then
if [[ ${BUILD_FLAG} == 1 ]]; then
CONTAINER_GROUP="e2e"
changeContainerGroup
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build "${CONTAINER_ARGS}"
fi
elif [[ "${TEST_SERVER_ARGS}" == "all" ]]; then
if [[ ${BUILD_FLAG} == 1 ]]; then
CONTAINER_GROUP="e2e"
changeContainerGroup
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build "${CONTAINER_ARGS}"
all
generalMessage "docker-compose down"
docker-compose -f "${DOCKER_COMPOSE_PATH}" down
else
all
fi
else
testUsage
exit 1
fi
completeMessage
}
changeContainerGroup() {
if [[ "${CONTAINER_GROUP}" == "all" ]]; then
# Leaving this empty will build everything in the docker-compose.yml
CONTAINER_ARGS=""
# Make sure these are not added to the CONTAINERS_ARGS
SWAGGER_FLAG=0
JUPYTER_FLAG=0
elif [[ "${CONTAINER_GROUP}" == "server" ]]; then
CONTAINER_ARGS="simcct celery-worker redis mongodb"
elif [[ "${CONTAINER_GROUP}" == "server-dask" ]]; then
CONTAINER_ARGS="simcct celery-worker redis mongodb dask-scheduler dask-worker"
elif [[ "${CONTAINER_GROUP}" == "client-dask" ]]; then
CONTAINER_ARGS="client simcct celery-worker redis mongodb dask-scheduler dask-worker"
elif [[ "${CONTAINER_GROUP}" == "client" ]]; then
CONTAINER_ARGS="client nginx"
elif [[ "${CONTAINER_GROUP}" == "fluentd" ]]; then
CONTAINER_ARGS="fluentd elasticsearch kibana"
elif [[ "${CONTAINER_GROUP}" == "fluentd-test" ]]; then
CONTAINER_ARGS="fluentd fluent-python fluent-react elasticsearch kibana"
elif [[ "${CONTAINER_GROUP}" == "swagger-test" ]]; then
CONTAINER_ARGS="simcct redis celery-worker mongodb swagger"
elif [[ "${CONTAINER_GROUP}" == "dask" ]]; then
CONTAINER_ARGS="dask-scheduler dask-worker jupyter"
elif [[ "${CONTAINER_GROUP}" == "e2e" ]]; then
CONTAINER_ARGS="client simcct nginx celery-worker redis mongodb"
fi
}
run() {
headerMessage "RUN ARCLYTICS SIM CONTAINERS"
if [[ ${SCALE_FLAG} == 1 ]]; then
CONTAINER_ARGS="--scale ${scale_service} ${CONTAINER_ARGS}"
fi
if [[ ${SWAGGER_FLAG} == 1 ]]; then
# Check if we haven't been told to build all
if [[ "${CONTAINER_GROUP}" != "all" ]]; then
CONTAINER_ARGS="${CONTAINER_ARGS} swagger"
fi
fi
if [[ ${JUPYTER_FLAG} == 1 ]]; then
if [[ "${CONTAINER_GROUP}" != "all" ]]; then
CONTAINER_ARGS="${CONTAINER_ARGS} jupyter"
fi
fi
if [[ ${BUILD_FLAG} == 1 ]]; then
if [[ ${DETACH_FLAG} == 1 ]]; then
generalMessage "docker-compose up -d --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d --build ${CONTAINER_ARGS}
if [[ ${JUPYTER_FLAG} == 1 ]]; then
docker-compose logs jupyter
fi
else
generalMessage "docker-compose up --build ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up --build ${CONTAINER_ARGS}
fi
else
if [[ ${DETACH_FLAG} == 1 ]]; then
generalMessage "docker-compose up -d ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up -d ${CONTAINER_ARGS}
else
generalMessage "docker-compose up ${CONTAINER_ARGS}"
docker-compose -f "${DOCKER_COMPOSE_PATH}" up ${CONTAINER_ARGS}
fi
fi
if [[ ${SEED_DB_FLAG} == 1 ]]; then
echoSpace
flushAndSeedDb
fi
completeMessage
}
# =========================================================== #
# ==================== # CLI Arguments # ==================== #
# =========================================================== #
if [[ $1 == "" ]]; then
usage
exit 1
fi
while [[ "$1" != "" ]] ; do
case $1 in
-V | --version )
generalMessage "Arclytis CLI"
echo v${VERSION}
;;
-h | --help )
usage
exit 0
;;
-f | --file )
DOCKER_COMPOSE_PATH=$2
;;
-d | --detach )
DETACH_FLAG=1
;;
-b | --build )
BUILD_FLAG=1
;;
-s | --seed_db )
SEED_DB_FLAG=1
;;
-S | --swagger )
SWAGGER_FLAG=1
;;
-J | --jupyter )
JUPYTER_FLAG=1
;;
-G | --group )
# Simply change the CONTAINER_ARGS based on the CONTAINER_GROUP
CONTAINER_GROUP=$2
if [[ "${CONTAINER_GROUP}" == 'help' ]]; then
groupUsage
exit 0
fi
changeContainerGroup
# Let the while condition continue and shift $3 --> $2 below
;;
ps )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
dockerPs
;;
ls | list | show )
dockerLsFormatted
exit 0
;;
stats )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
dockerStats
;;
prune )
dockerSystemPrune
;;
down )
while [[ "$2" != "" ]] ; do
case $2 in
-D | --docker )
DOCKER_DOWN_FLAG=1
;;
* )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
esac
shift
done
containerDown
;;
scale )
SCALE_CONTAINERS_ARGS=$2
while [[ $3 != "" ]] ; do
SCALE_CONTAINERS_ARGS="${SCALE_CONTAINERS_ARGS} $3"
shift
done
scaleContainers
;;
build )
BUILD_CONTAINER_ARGS=$2
while [[ "$3" != "" ]] ; do
BUILD_CONTAINER_ARGS="${BUILD_CONTAINER_ARGS} $3"
shift
done
buildContainers
;;
up )
while [[ "$2" != "" ]] ; do
case $2 in
-b | --build )
BUILD_FLAG=1
;;
-d | --detach )
DETACH_FLAG=1
;;
-s | --seed_db )
SEED_DB_FLAG=1
;;
-S | --swagger )
SWAGGER_FLAG=1
;;
-J | --jupyter )
JUPYTER_FLAG=1
;;
--scale )
SCALE_FLAG=1
# Shift to the arg after --SCALE_FLAG
shift
# Get the first argument after --SCALE_FLAG flag
# TODO(andrew@neuraldev.io): Currently only taking one
scale_service=$2
# scale_num="$(cut -d'=' -f2 <<< "${scale_service}" )"
shift
;;
-G | --group )
shift
CONTAINER_GROUP=$2
changeContainerGroup
while [[ "$3" != "" ]]; do
case $3 in
-b | --build )
BUILD_FLAG=1
;;
-d | --detach )
DETACH_FLAG=1
;;
-s | --seed_db )
SEED_DB_FLAG=1
;;
--scale )
SCALE_FLAG=1
# Shift to the arg after --scale
shift
# Get the first argument after --SCALE_FLAG flag
# TODO(andrew@neuraldev.io): Currently only taking one
scale_service=$3
# scale_num="$(cut -d'=' -f2 <<< "${scale_service}" )"
shift
;;
help )
groupUsage
exit 0
;;
esac
shift
done
# We run from here and as will only accept the flags above
run
exit 0
;;
-h | --help )
upUsage
exit 0
;;
* )
CONTAINER_ARGS=$2
while [[ "$3" != "" ]] ; do
CONTAINER_ARGS="${CONTAINER_ARGS} $3"
shift
done
;;
esac
shift
done
run
;;
logs )
CONTAINER_LOG=$2
shift
if [[ $2 == "--watch" ]] ; then
LOGS_WATCH=1
fi
dockerLogs
;;
test )
while [[ "$2" != "" ]] ; do
case $2 in
-b | --build )
BUILD_FLAG=1
;;
-t | --tty )
tty=1
;;
-c | --coverage )
TEST_TYPE="test_coverage"
TEST_TITLE="Flask-Testing Unittests with Coverage"
;;
-h | --help )
testUsage
exit 0
;;
* )
TEST_SERVER_ARGS=$2
esac
shift
done
runTests
;;
images )
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Size}}"
;;
image )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
docker image "${ARGS}"
;;
pull )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
docker pull "${ARGS}"
;;
push )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
docker push "${ARGS}"
;;
container )
ARGS=$2
while [[ "$3" != "" ]] ; do
ARGS="${ARGS} $3"
shift
done
docker container "${ARGS}"
;;
system )
while [[ "$2" != "" ]] ; do
case $2 in
usage | df )
docker system df
exit 0
;;
* )
ARGS="${ARGS} $2"
;;
esac
shift
done