-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathccd
More file actions
executable file
·896 lines (801 loc) · 29 KB
/
ccd
File metadata and controls
executable file
·896 lines (801 loc) · 29 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
#!/bin/bash
TAGS_FILE=".tags.env"
WORKSPACE_ROOT=".workspace"
# Build related
GRADLE_ASSEMBLE_CMD="./gradlew assemble"
function askYesNo() {
while true; do
read -n 1 -s yn
case $yn in
y|Y) eval "$1"; break ;;
n|N) eval "$2"; break ;;
*) echo "Please answer yes (y) or no (n)." ;;
esac
done
}
function project_config() {
project=$1
config=$2
case $project in
operational-reports|reports-runner)
name=operational
repository="git@github.com:hmcts/hmc-operational-reports-runner.git"
envPrefix="HMC_OPERATIONAL_REPORTS"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
cft-hearing-service|hearing-service)
name=hearings
repository="git@github.com:hmcts/hmc-cft-hearing-service.git"
envPrefix="HMC_HEARING_SERVICE"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
outbound-adapter)
name=outbound
repository="git@github.com:hmcts/hmc-hmi-outbound-adapter.git"
envPrefix="HMC_OUTBOUND_ADAPTER"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
inbound-adapter)
name=inbound
repository="git@github.com:hmcts/hmc-hmi-inbound-adapter.git"
envPrefix="HMC_INBOUND_ADAPTER"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-data-store-api|data-store-api|data-store|datastore|data-store)
name=ccd-data-store-api
repository="git@github.com:hmcts/ccd-data-store-api.git"
envPrefix="CCD_DATA_STORE_API"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-case-document-am-api|case-document-api|document-api|case-document)
name=ccd-ccd-case-document-am-api
repository="git@github.com:hmcts/ccd-case-document-am-api.git"
envPrefix="CCD_CASE_DOCUMENT_AM_API"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ts-translation-service|translation-service)
name=ts-translation-service
repository="git@github.com:hmcts/ts-translation-service.git"
envPrefix="TS_TRANSLATION_SERVICE"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-definition-store-api|definition-store-api|definition-store|def-store|defstore)
name=ccd-definition-store-api
repository="git@github.com:hmcts/ccd-definition-store-api.git"
envPrefix="CCD_DEFINITION_STORE_API"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-user-profile-api|user-profile-api|user-profile|userprofile)
name=ccd-user-profile-api
repository="git@github.com:hmcts/ccd-user-profile-api.git"
envPrefix="CCD_USER_PROFILE_API"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-api-gateway|api-gateway|gateway)
name=ccd-api-gateway
repository="git@github.com:hmcts/ccd-api-gateway.git"
envPrefix="CCD_API_GATEWAY"
;;
ccd-admin-web|admin-web|admin-web)
name=ccd-admin-web
repository="git@github.com:hmcts/ccd-admin-web.git"
envPrefix="CCD_ADMIN_WEB"
;;
dm-store|document-store)
name=dm-store
repository="git@github.com:hmcts/document-management-store-app.git"
envPrefix="DM_STORE"
buildCommand="./gradlew installDist assemble"
;;
ccd-test-stubs-service|test-stubs-service)
name=ccd-test-stubs-service
repository="git@github.com:hmcts/ccd-test-stubs-service.git"
envPrefix="CCD_TEST_STUBS_SERVICE"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
xui-manage-cases)
name=xui-manage-cases
repository="git@github.com:hmcts/rpx-xui-webapp.git"
envPrefix="XUI_MANAGE_CASES"
;;
ccd-message-publisher|message-publisher)
name=ccd-message-publisher
repository="git@github.com:hmcts/ccd-message-publisher.git"
envPrefix="CCD_MESSAGE_PUBLISHER"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-case-disposer|case-disposer)
name=ccd-case-disposer
repository="git@github.com:hmcts/ccd-case-disposer.git"
envPrefix="CCD_CASE_DISPOSER"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
ccd-next-hearing-date-updater|next-hearing-date-updater)
name=ccd-next-hearing-date-updater
repository="git@github.com:hmcts/ccd-next-hearing-date-updater.git"
envPrefix="CCD_NEXT_HEARING_DATE_UPDATER"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
am-role-assignment-service|role-assignment-service|ras)
name=am-role-assignment-service
repository="git@github.com:hmcts/am-role-assignment-service.git"
envPrefix="AM_ROLE_ASSIGNMENT_SERVICE"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
case-payment-orders|case-payment-orders-api)
name=cpo-case-payment-orders-api
repository="git@github.com:hmcts/cpo-case-payment-orders-api.git"
envPrefix="CPO_CASE_PAYMENT_ORDERS_API"
buildCommand=$GRADLE_ASSEMBLE_CMD
;;
*)
echo "Project must be one of ccd-data-store-api, ccd-definition-store-api, ccd-user-profile-api, ccd-api-gateway, xui-manage-cases, ccd-message-publisher, ccd-case-disposer, ccd-admin-web, dm-store, ccd-case-document-am-api, ts-translation-service, ccd-next-hearing-date-updater, hearing-service, operational-reports, outbound-adapter, inbound-adapter, case-payment-orders-api"
exit 1
;;
esac
case $config in
name)
echo $name
;;
tagEnv)
echo ${envPrefix}_TAG
;;
useLocalEnv)
echo ${envPrefix}_USE_LOCAL
;;
repository)
echo $repository
;;
buildCommand)
echo $buildCommand
;;
*)
echo "Config is one of name, repository, tagEnv, useLocalEnv or buildCommand. '$config' is unknown"
exit 1
;;
esac
}
function tag_unset() {
project=$1
tagEnv=$(project_config $project tagEnv)
useLocalEnv=$(project_config $project useLocalEnv)
touch $TAGS_FILE
sed -i '' "/$tagEnv/d" $TAGS_FILE
sed -i '' "/${useLocalEnv}/d" $TAGS_FILE
}
function tag_set() {
project=$1
branch=$2
tagEnv=$(project_config $project tagEnv)
useLocalEnv=$(project_config $project useLocalEnv)
tagName=$(tag_name $project $branch)
touch $TAGS_FILE
sed -i '' "/$tagEnv/d" $TAGS_FILE
echo "export $tagEnv=$tagName" >> $TAGS_FILE
echo "export ${useLocalEnv}=''" >> $TAGS_FILE
}
function has_active_tags() {
if [ $(has_tagfile) -eq 0 ]; then
echo 0
else
egrep -q "_TAG=" $TAGS_FILE
if [ $? -eq 0 ]; then
echo 1
else
echo 0
fi
fi
}
function active_tags() {
egrep "_TAG=" $TAGS_FILE | sed -E 's/^export +(.*)_TAG=.*/\1/'
}
function active_tag_hash() {
tag=$1
egrep "${tag}_TAG=" $TAGS_FILE | sed -E 's/.*[-]([a-f0-9]+)$/\1/'
}
function active_tag_branch() {
tag=$1
egrep "${tag}_TAG=" $TAGS_FILE | sed -E 's/.*=(.+)[-][a-f0-9]+$/\1/'
}
function tag_friendly_name() {
tag=$1
echo $1 | tr "[:upper:]_" "[:lower:]-"
}
function workspace_dir() {
project=$1
name=$(project_config $project name)
workspace="$WORKSPACE_ROOT/$name"
echo $workspace
}
function clean_name() {
name=$1
clean=$(echo $name | sed 's#/#-#')
echo $clean
}
function git_clone() {
project=$1
branch=$2
local_repository=$3
if [ -n "$branch" ]; then
branch_option="--branch $branch"
fi
workspace=$(workspace_dir $project)
repository=$(project_config $project repository)
rm -rf $workspace
mkdir -p $workspace
if [ "$local_repository" ]; then
echo "Cloning from local repository $local_repository"
repository=$local_repository
fi
result=$(git clone --depth=20 --no-tags $branch_option $repository $workspace 2>&1 || exit $?)
exitcode=$?
echo "$result"
echo $result | egrep -q "Remote branch .* not found in upstream origin"
no_branch=$?
if [ $no_branch -eq 0 ]; then
echo
echo "$project does not contain the branch '$branch'"
echo
echo " $(basename $0) branches $project"
echo
echo "To list available branches in '$project'"
echo
exit $exitcode
fi
}
function available_branches() {
project=$1
workspace=$(workspace_dir $project)
git_clone $project
(cd $workspace; git branch -vr --sort refname --no-merged) | egrep -v 'HEAD|master|demo' | sed 's#origin/##'
}
git_hash() {
project=$1
workspace=$(workspace_dir $project)
gitHash=$(cd $workspace && git rev-parse HEAD | cut -c -7)
echo $gitHash
}
function tag_name() {
project=$1
branch=$2
gitHash=$(git_hash $project)
cleanBranch=$(clean_name $branch)
branch_and_hash=${cleanBranch}-${gitHash}
echo $branch_and_hash
}
function project_build() {
project=$1
workspace=$(workspace_dir $project)
buildCommand=$(project_config $project buildCommand)
# Build if required
if [ -n "$buildCommand" ]; then
(cd $workspace && eval $buildCommand || exit $?)
fi
}
function docker_build() {
project=$1
branch=$2
buildProject=$project
workspace=$(workspace_dir $project)
tagName=$(tag_name $project $branch)
# ccd-api-gateway image from azure coming as ccd-api-gateway-web, to match and fix for local branch build
if [[ $project == "ccd-api-gateway" && $branch != "master" ]]; then
buildProject="$buildProject-web"
fi
imageName=${buildProject#"ccd-"}
if [[ $project == "xui-manage-cases" ]]; then
(cd $workspace && docker build . -t xui/webapp:$tagName || exit $?)
fi
if [[ $project == "am-role-assignment-service" ]]; then
(cd $workspace && docker build . -t am/role-assignment-service:$tagName || exit $?)
fi
if [[ $project == "ts-translation-service" ]]; then
(cd $workspace && docker build . -t ts/translation-service:$tagName || exit $?)
fi
if [[ $project == "ccd-next-hearing-date-updater" ]]; then
(cd $workspace && docker build . -t ccd/next-hearing-date-updater:$tagName || exit $?)
fi
if [[ $project == "outbound-adapter" ]]; then
(cd $workspace && docker build . -t hmc/hmi-outbound-adapter:$tagName || exit $?)
fi
if [[ $project == "inbound-adapter" ]]; then
(cd $workspace && docker build . -t hmc/hmi-inbound-adapter:$tagName || exit $?)
fi
if [[ $project == "cft-hearing-service" || $project == "hearing-service" ]]; then
(cd $workspace && docker build . -t hmc/cft-hearing-service:$tagName || exit $?)
fi
if [[ $project == "operational-reports" || $project == "reports-runner" ]]; then
(cd $workspace && docker build . -t hmc/operational-reports-runner:$tagName || exit $?)
fi
if [[ $project == "case-payment-orders" || $project == "case-payment-orders-api" ]]; then
(cd $workspace && docker build . -t cpo/case-payment-orders-api:$tagName || exit $?)
fi
if [[ $project != "xui-manage-cases" && $project != "am-role-assignment-service"
&& $project != "ts-translation-service" && $project != "ccd-next-hearing-date-updater"
&& $project != "hearing-service" && $project != "cft-hearing-service"
&& $project != "operational-reports" && $project != "reports-runner"
&& $project != "outbound-adapter" && $project != "inbound-adapter"
&& $project != "case-payment-orders" && $project != "case-payment-orders-api" ]]; then
(cd $workspace && docker build . -t ccd/$imageName:$tagName || exit $?)
fi
}
function available_compose_files() {
find compose -name "*.yml" | xargs -I % basename % .yml
}
function default_compose_files() {
cat compose/defaults.conf
}
function has_tagfile() {
if [ -f $TAGS_FILE ]; then
echo 1
else
echo 0
fi
}
function has_active_compose_files() {
if [ $(has_tagfile) -eq 0 ]; then
echo 0
else
egrep -q "^CCD_ENABLED_COMPOSE_FILES=" $TAGS_FILE
if [ $? -eq 0 ]; then
echo 1
else
echo 0
fi
fi
}
function active_compose_files() {
if [ $(has_active_compose_files) -eq 1 ]; then
source $TAGS_FILE
echo $CCD_ENABLED_COMPOSE_FILES
else
echo $(default_compose_files)
fi
}
function create_compose_file_options() {
for compose_file in $(active_compose_files)
do
compose_file_options="$compose_file_options -f compose/${compose_file}.yml"
done
echo $compose_file_options
}
function status_tags() {
if [ $(has_active_tags) -eq 1 ]; then
echo "Current overrides:"
for tag in $(active_tags)
do
echo "$(tag_friendly_name $tag) branch:$(active_tag_branch $tag) hash:$(active_tag_hash $tag)"
done
echo -e "\n"
else
echo -e "No overrides, all using master\n"
fi
}
function status_compose_files() {
if [ $(has_active_compose_files) -eq 1 ]; then
echo "Active compose files:"
echo -e "$(active_compose_files)\n"
else
echo "Using default compose files:"
echo -e "$(default_compose_files)\n"
fi
}
function usage() {
echo "Usage: $(basename $0) <command> [options]"
echo
echo "Commands:"
echo " default - setup default compose files and run them for linux/mac"
echo " set <project> <branch> [file://local_repository_path] - override and build project"
echo " unset <project...> - remove project override(s)"
echo " branches <project...> - list available branches"
echo " status - list current overrides and their status against upstream"
echo " update <project...> - update project override to match upstream branch; and build"
echo " enable <project>|defaults|show - enable a compose file"
echo " disable <project> - disable a compose file"
echo " compose [<docker-compose command> [options]] - wrap docker compose for your configuration"
echo
exit 1
}
function usage_default() {
if [ $# -gt 1 ] || ([ $# -eq 1 ] && [ "$1" != "idam" ] && [ "$1" != "xui" ]); then
echo "Setup default compose files and run them for linux/mac. Usage:"
echo "$(basename $0) default # setup default compose files with idam simulator"
echo "$(basename $0) default idam # setup default compose files with full idam stack"
echo "$(basename $0) default xui # setup default compose files with idam sim + xui-frontend"
echo
exit 1
fi
}
function usage_set() {
if [ "$1" == "-h" ] || ([ $# -ne 2 ] && [ $# -ne 3 ]); then
echo "Overrides project to use the supplied branch, and build the project."
echo "To use a local repository provide its path (file://..) as a third parameter"
echo "Usage: $(basename $0) set <project> <branch> [file://local_repository_path]"
echo
exit 1
fi
}
function usage_unset() {
if [ $# -lt 1 -o "$1" == "-h" ]; then
echo "Remove branch overrides for the given projects."
echo "Usage: $(basename $0) unset <project...>"
echo
exit 1
fi
}
function usage_branches() {
if [ $# -lt 1 -o "$1" == "-h" ]; then
echo "List available branches for the given projects."
echo "Usage: $(basename $0) branches <project...>"
echo
exit 1
fi
}
function usage_enable() {
if [ $# -eq 1 -a "$1" == "-h" ]; then
echo "Enable projects that will be run by 'compose'"
echo "Usage:"
echo " $(basename $0) enable <project> - enable 'project'"
echo " $(basename $0) enable defaults - reset the enabled projects to the defaults"
echo " $(basename $0) enable show - currently enabled projects"
echo
exit 1
fi
}
function usage_disable() {
if [ $# -ne 1 -o "$1" == "-h" ]; then
echo "Disable a projects from being run by 'compose'"
echo "Usage: $(basename $0) disable <project>"
echo
exit 1
fi
}
function usage_compose() {
if [ $# -eq 1 -a "$1" == "-h" ]; then
echo "Use docker-compose to run the configured overrides and enabled projects"
echo "Usage: $(basename $0) compose [<docker-compose command> [options]]"
echo
exit 1
fi
}
function notimplemented() {
echo "Not Implemented yet"
exit 1
}
function ccd_set() {
usage_set $*
project=$1
branch=$2
if [ "$branch" == "master" ]; then
tag_unset $project
return
fi
project_config $project repository
git_clone $*
project_build $project
docker_build $project $branch
tag_set $project $branch
}
function ccd_unset() {
usage_unset $*
projects=$*
for project in $projects
do
tag_unset $project
done
}
function ccd_branches() {
usage_branches $*
projects=$*
for project in $projects
do
echo "Branches in '$project'"
available_branches $project
echo
done
}
function ccd_init() {
echo "creating docker network 'ccd-network'"
docker network create ccd-network && echo "'ccd-network' created"
}
function ccd_status() {
echo "Status:"
echo "======="
echo
status_compose_files
echo
status_tags
echo
}
function ccd_update() {
notimplemented
}
function ccd_enable_show() {
if [ $(has_active_compose_files) -eq 1 ]; then
echo "Currently active compose files:"
for compose_file in $(active_compose_files)
do
echo $compose_file
done | sort
echo
else
echo "No active compose files, using defaults."
fi
echo "Default compose files:"
for compose_file in $(default_compose_files)
do
echo $compose_file
done | sort
}
function ccd_enable_defaults() {
if [ $(has_active_compose_files) -eq 1 ]; then
sed -i '' "/CCD_ENABLED_COMPOSE_FILES/d" $TAGS_FILE
fi
}
function ccd_enable_compose_file() {
for compose_file in $*
do
if [ ! -f compose/${compose_file}.yml ]; then
(>&2 echo "No such compose file. Choose one of:"
echo $(available_compose_files))
else
touch $TAGS_FILE
source $TAGS_FILE
sed -i '' "/CCD_ENABLED_COMPOSE_FILES/d" $TAGS_FILE
existing=0
for enabled_file in $CCD_ENABLED_COMPOSE_FILES
do
if [ "$compose_file" == "$enabled_file" ]; then
existing=1
fi
done
if [ $existing -eq 0 ]; then
echo "CCD_ENABLED_COMPOSE_FILES=\"$CCD_ENABLED_COMPOSE_FILES $compose_file\"" >> $TAGS_FILE
else
echo "CCD_ENABLED_COMPOSE_FILES=\"$CCD_ENABLED_COMPOSE_FILES\"" >> $TAGS_FILE
fi
fi
done
}
function ccd_enable() {
usage_enable $*
subcommand=$1
case $subcommand in
show)
ccd_enable_show
;;
default|defaults)
ccd_enable_defaults
;;
*)
ccd_enable_compose_file $*
;;
esac
}
function ccd_disable() {
if [ $(has_active_compose_files) -eq 0 ]; then
(>&2 echo "No enabled compose files, so we can't remove this. Currently using defaults:"
echo $(default_compose_files))
else
for compose_file in $*
do
touch $TAGS_FILE
source $TAGS_FILE
sed -i '' "/CCD_ENABLED_COMPOSE_FILES/d" $TAGS_FILE
existing=0
for enabled_file in $CCD_ENABLED_COMPOSE_FILES
do
#if enabled_file is not in the list to be disabled and it's not in $new_enabled yet
if [[ ! " $* " =~ .*\ $enabled_file\ .* ]] && [[ ! " $new_enabled " =~ .*\ $enabled_file\ .* ]]; then
new_enabled="$new_enabled $enabled_file"
else
existing=1
fi
done
if [ $existing -eq 0 ]; then
(>&2 echo "Cannot disable \"$compose_file\", as it is not active. Currently active:"
echo $(active_compose_files))
fi
if [ "$new_enabled" != "" ]; then
echo "CCD_ENABLED_COMPOSE_FILES=\"$new_enabled\"" >> $TAGS_FILE
fi
done
fi
}
function ccd_compose() {
print_warn_on_compose_down_if_idam_enabled $*
usage_compose $*
status_compose_files
status_tags
options="$@"
if [ $(has_tagfile) -eq 1 ]; then
source $TAGS_FILE
fi
compose_file_options=$(create_compose_file_options)
echo "Docker compose:"
echo -e "docker-compose $compose_file_options $options\n"
docker-compose $compose_file_options $options
}
function print_warn_on_compose_down_if_idam_enabled {
if [[ $(active_compose_files) == *"sidam"* ]] && [[ $1 = "down" ]]; then
echo "WARNING - 'down' will remove Idam data. Use 'stop' to preserve data. Or if you intended to remove only CCD containers, disable Idam
compose files first. Do you want to continue?"
askYesNo "break" "exit"
fi
}
function ccd_login() {
#docker logout hmctsprod.azurecr.io &>/dev/null
az acr login --name hmctsprod --subscription DCD-CNP-Prod
}
function echo_ccd() {
echo -e "\033[34mCCD ::--\033[0m $@" # blue
}
function echo_error() {
echo -e "\033[1;91mERROR ::--\033[0m $@" # red
}
function echo_break() {
echo -e "\033[34m-----------------------------------------------------------------------------------------------------------------------\033[0m"
}
function ccd_default() {
usage_default $*
echo_break
echo -e "\033[34m" # set blue
echo " _____ _____ _____ ____ ___ ____ _ _______ ____"
echo " / ____/ ____| __ \\ | _ \\ / _ \\ / ___|| |/ / ____| _ \\"
echo " | | | | | | | | | | | | | | | | | ' /| _| | |_) |"
echo " | |___| |____| |__| | | |_| | |_| | |___ | . \\| |___| _ <"
echo " \\_____\\_____|_____/ |____/ \\___/ \\____||_|\\_\\_____|_| \\_\\"
echo_break
echo -e "\033[0m" # reset color
if [ "$1" == "idam" ]; then
echo_ccd "Starting default CCD setup with full idam compose files..."
else
echo_ccd "Starting default CCD setup..."
fi
echo_ccd "Looking for azure cli installation..."
if ! command -v az >/dev/null 2>&1; then
echo_error "Azure CLI is not installed. Please install it from: https://learn.microsoft.com/cli/azure/install-azure-cli"
exit 1
fi
echo_ccd "Azure CLI installation found."
# Check if user is already logged in
if az account show >/dev/null 2>&1; then
echo_ccd "Skipping Azure login as already logged in..."
else
echo_ccd "Logging in to Azure..."
if ! az login >/dev/null 2>&1; then
echo_error "Azure CLI login failed. Please run 'az login' manually. "
exit 1
fi
echo_ccd "Azure CLI login succeeded."
fi
echo_ccd "Logging into CCD container registries..."
if ! ccd_login >/dev/null; then
echo_error "CCD container registry login issues detected. Diagnosing..."
az acr check-health -n hmctsprod --yes
exit 1
fi
echo_ccd "Setting up default environment variables..."
source ./bin/set-environment-variables.sh &>/dev/null
compose_file_options=$(create_compose_file_options) >/dev/null
if docker-compose $compose_file_options ps --services --filter status=running | grep -q . >/dev/null; then
echo_ccd "Compose containers currently running running."
echo_ccd "Do you wish to remove existing containers and volumes? (y/n)"
askYesNo "docker-compose $compose_file_options down -v &>/dev/null; echo_ccd Containers and volumes removed." "echo_ccd Existing containers and volumes preserved."
fi
compose_file_options="" # reset variable
echo_ccd "Enabling default compose files..."
ccd_enable defaults >/dev/null
# unset backend
echo_ccd "Resetting existing backend ccd container config..."
ccd_unset ccd-user-profile-api ccd-definition-store-api ccd-data-store-api am-role-assignment-service service-auth-provider-api ccd-test-stubs-service >/dev/null
# unset frontend
echo_ccd "Resetting existing frontend ccd container config..."
ccd_unset ccd-api-gateway ccd-admin-web >/dev/null
# unset sidam
echo_ccd "Resetting existing idam related container config..."
ccd_unset idam-sim fr-am fr-idm shared-db smtp-server idam-api idam-web-public idam-web-admin >/dev/null
if [ "$1" == "idam" ]; then
echo_ccd "Enable default stack with full idam compose files..."
ccd_enable backend frontend sidam >/dev/null
fi
if [ "$1" == "xui" ]; then
echo_ccd "Enable default stack with idam simulator and xui frontend compose files..."
ccd_enable backend frontend idam-sim xui-frontend >/dev/null
fi
compose_file_options=$(create_compose_file_options) >/dev/null
echo_ccd "Pulling latest images..."
if ! docker-compose $compose_file_options pull; then
echo_error "Failed to pull latest images. Continue anyways? (y/n)"
askYesNo "echo_ccd Continuing despite pull failures." "exit 1"
fi
echo_ccd "Initializing ccd network..."
ccd_init &>/dev/null # will either create or already exists
echo_ccd "Starting up services..."
if ! docker compose $compose_file_options up -d >/dev/null; then
echo_error "Failed to start some containers please check logs."
exit 1
fi
echo_ccd "Waiting 30 seconds for services to finish spinning up..."
sleep 30
if [ "$1" == "idam" ]; then
echo_ccd "Setting IDAM_FULL_ENABLED to true for scripts..."
export IDAM_FULL_ENABLED=true
echo_ccd "\033[33m[--------------------] 0% Complete\033[0m - Adding IDAM clients..."
./bin/add-idam-clients.sh &>/dev/null || { echo_error "IDAM clients failed to apply correctly." ; exit 1; }
echo_ccd "\033[33m[####----------------] 20% Complete\033[0m - Adding IDAM roles..."
./bin/add-idam-roles.sh &>/dev/null || { echo_error "IDAM roles failed to apply correctly." ; exit 1; }
echo_ccd "\033[33m[########------------] 40% Complete\033[0m - Adding users..."
./bin/add-users.sh &>/dev/null || { echo_error "Users failed to apply correctly." ; exit 1; }
echo_ccd "\033[33m[############--------] 60% Complete\033[0m - Adding ccd roles..."
./bin/add-ccd-roles.sh &>/dev/null || { echo_error "Roles failed to apply correctly." ; exit 1; }
echo_ccd "\033[33m[################----] 80% Complete\033[0m - Adding role assignments..."
./bin/add-role-assignments.sh &>/dev/null || { echo_error "Role assignments failed to apply correctly." ; exit 1; }
echo_ccd "\033[32m[####################] 100% Complete\033[0m - Setup complete!"
else
unset IDAM_FULL_ENABLED
echo_ccd "\033[33m[--------------------] 0% Complete\033[0m - Adding users..."
./bin/add-users.sh &>/dev/null || { echo_error "Users failed to apply correctly." ; exit 1; }
echo_ccd "\033[33m[######--------------] 33% Complete\033[0m - Adding ccd roles..."
./bin/add-ccd-roles.sh &>/dev/null || { echo_error "Roles failed to apply correctly." ; exit 1; }
echo_ccd "\033[33m[##############------] 66% Complete\033[0m - Adding role assignments..."
./bin/add-role-assignments.sh &>/dev/null || { echo_error "Role assignments failed to apply correctly." ; exit 1; }
echo_ccd "\033[32m[####################] 100% Complete\033[0m - Setup complete!"
fi
echo_break
if [ "$1" == "idam" ]; then
echo_ccd "Default setup with full idam compose files complete!"
echo_ccd "Access admin-web at https://localhost:3100/ with idam credentials ( e.g. ccd.docker.default@hmcts.net : Pa55word11 )"
elif [ "$1" == "xui" ]; then
echo_ccd "Default setup with idam simulator and xui frontend compose files complete!"
echo_ccd "Access admin-web at https://localhost:3100/ with idam credentials ( e.g. ccd.docker.default@hmcts.net : Pa55word11 )"
echo_ccd "Access xui frontend at http://localhost:3455/ with idam credentials ( e.g. master.caseworker@gmail.com : Pa55word11 )"
else
echo_ccd "Default setup complete!"
echo_ccd "Access admin-web at https://localhost:3100/ with idam credentials ( e.g. ccd.docker.default@hmcts.net : Pa55word11 )"
fi
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
command=$1
shift
case $command in
init)
ccd_init
;;
set)
ccd_set $*
;;
unset)
ccd_unset $*
;;
branches)
ccd_branches $*
;;
status)
ccd_status
;;
update)
ccd_update
;;
enable)
ccd_enable $*
;;
disable)
ccd_disable $*
;;
compose)
ccd_compose "$@"
;;
login)
ccd_login
;;
default|defaults)
ccd_default $*
;;
*)
usage
;;
esac