-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdomino_container
executable file
·2397 lines (1849 loc) · 62 KB
/
domino_container
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
###########################################################################
# dominoctl #
# --------- #
# Nash!Com Domino Container Management Script #
# Version 1.4.2 06.11.2024 #
# #
# (C) Copyright Daniel Nashed/NashCom 2021-2024 #
# Feedback domino_unix@nashcom.de #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.#
# See the License for the specific language governing permissions and #
# limitations under the License. #
###########################################################################
SCRIPT_NAME=$(readlink -f $0)
SCRIPT_DIR_NAME=$(dirname $SCRIPT_NAME)
NAME_PREFIX="container_"
PARAM1=$1
PARAM2=$2
PARAM3=$3
PARAM4=$4
PARAM5=$5
PARAM6=$6
PARAM7=$7
PARAM8=$8
# Default Configuration parameters overwritten by config file if available in same directory
CONTAINER_NAME=
IMAGE_NAME=
CONTAINER_SYSTEMD_NAME=domino_container.service
CONTAINER_HOSTNAME=
# CONTAINER_NETWORK_NAME=host
# CONTAINER_SPECIAL_OPTIONS="--ip 172.17.0.1"
# CONTAINER_PORTS="-p 1352:1352 -p 80:80 -p 443:443"
# Environment file is used for first container start (run) to pass setup parameters
CONTAINER_ENV_FILE=
# Shutdown timeout increased for Domino proper shutdown
DOMINO_SHUTDOWN_TIMEOUT=120
CONTAINER_SCRIPT_VERSION=1.4.2
MYHCL_DOWNLOAD_URL=https://my.hcltechsw.com/
if [ "$1" == "--version" ]; then
echo $CONTAINER_SCRIPT_VERSION
exit 0
fi
# Default config directory. Can be overwritten by environment
if [ -z "$DOMINO_CFG_DIR" ]; then
# Check current directory for config
# If not present check home dir
# Else use standard config dir (default: /etc/sysconfig)
if [ -e .dominoctl ]; then
DOMINO_CFG_DIR=$(pwd)/.dominoctl
elif [ -e ~/.dominoctl ]; then
DOMINO_CFG_DIR=~/.dominoctl
else
DOMINO_CFG_DIR=/etc/sysconfig
fi
fi
# Get configuration from config file
CFG_PREFIX=$(basename $SCRIPT_NAME | awk -F "$NAME_PREFIX" '{print $2}')
if [ -z "$CFG_PREFIX" ]; then
CONFIG_FILE=$DOMINO_CFG_DIR/domino_container
if [ ! -e "$CONFIG_FILE" ]; then
echo
echo "Configuration not found at [$CONFIG_FILE]"
exit 1
fi
else
CONFIG_FILE=$DOMINO_CFG_DIR/config_$CFG_PREFIX
if [ ! -e "$CONFIG_FILE" ]; then
CONFIG_FILE=$SCRIPT_DIR_NAME/config_$CFG_PREFIX
if [ ! -e "$CONFIG_FILE" ]; then
CONFIG_FILE=
fi
if [ -z "$CONFIG_FILE" ]; then
echo
echo "No configuration found!"
exit 1
fi
fi
fi
# Source in the config file
if [ -e "$CONFIG_FILE" ]; then
. $CONFIG_FILE
else
echo
echo "No configuration found"
exit 1
fi
# Check specified environment file or check if the default file exists in config directory
CONTAINER_FULL_ENV_FILE=
if [ -n "$CONTAINER_ENV_FILE" ]; then
if [ -r "$CONTAINER_ENV_FILE" ]; then
CONTAINER_FULL_ENV_FILE="$CONTAINER_ENV_FILE"
elif [ -r "$DOMINO_CFG_DIR/$CONTAINER_ENV_FILE" ]; then
CONTAINER_FULL_ENV_FILE="$DOMINO_CFG_DIR/$CONTAINER_ENV_FILE"
else
echo "Info: Cannot read configured environment file [$CONTAINER_ENV_FILE]!"
fi
else
if [ -r "$DOMINO_CFG_DIR/.env" ]; then
CONTAINER_FULL_ENV_FILE="$DOMINO_CFG_DIR/.env"
fi
fi
CONTAINER_FULL_LABEL_FILE=
if [ -n "$CONTAINER_LABEL_FILE" ]; then
if [ -r "$CONTAINER_LABEL_FILE" ]; then
CONTAINER_FULL_LABEL_FILE="$CONTAINER_LABEL_FILE"
elif [ -r "$DOMINO_CFG_DIR/$CONTAINER_LABEL_FILE" ]; then
CONTAINER_FULL_LABEL_FILE="$DOMINO_CFG_DIR/$CONTAINER_LABEL_FILE"
else
echo "Info: Cannot read configured label file [$CONTAINER_LABEL_FILE]!"
fi
else
if [ -r "$DOMINO_CFG_DIR/.label" ]; then
CONTAINER_FULL_LABEL_FILE="$DOMINO_CFG_DIR/.label"
fi
fi
# Check specified docker compose file or check if the default file exists in config directory
if [ -n "$CONTAINER_COMPOSE_FILE" ]; then
if [ ! -r "$CONTAINER_COMPOSE_FILE" ]; then
echo
echo "Info: Cannot read configured compose file [$CONTAINER_COMPOSE_FILE]!"
fi
else
if [ -r "$DOMINO_CFG_DIR/docker-compose.yml" ]; then
CONTAINER_COMPOSE_FILE="$DOMINO_CFG_DIR/docker-compose.yml"
fi
fi
echo
echo "-----------------------------------------"
echo "$CONFIG_FILE"
if [ -n "$CONTAINER_FULL_ENV_FILE" ]; then
echo "$CONTAINER_FULL_ENV_FILE"
fi
if [ -n "$CONTAINER_FULL_LABEL_FILE" ]; then
echo "$CONTAINER_FULL_LABEL_FILE"
fi
if [ -n "$CONTAINER_COMPOSE_FILE" ]; then
echo "$CONTAINER_COMPOSE_FILE"
fi
echo
IMAGE_BUILD_VERSION=$IMAGE_VERSION
# Special configuration
BUILDTIME=$(date +"%d.%m.%Y %H:%M:%S")
if [ -z "$EDIT_COMMAND" ]; then
EDIT_COMMAND="vi"
fi
# Get OS type
LARCH=$(uname)
SOFTWARE_PORT=7777
SOFTWARE_CONTAINER=hclsoftware
SYSTEMCTL_CMD="systemctl"
# OneTouch configuration file
if [ -z "$DOMINO_AUTO_CONFIG_JSON_FILE" ]; then
export DOMINO_AUTO_CONFIG_JSON_FILE=$DOMINO_CFG_DIR/DominoContainerAutoConfig.json
fi
if [ -z "$DOMINO_AUTO_CFG_DEFAULTS_ENV_FILE" ]; then
export DOMINO_AUTO_CFG_DEFAULTS_ENV_FILE=$DOMINO_CFG_DIR/DominoAutoConfigDefault.env
fi
log_space ()
{
echo
echo "$@"
echo
}
log_and_exit ()
{
echo
echo "$@"
echo
exit 1
}
print_delim ()
{
echo "------------------------------------------------------------------------------------------"
}
header ()
{
echo
print_delim
echo "$@"
print_delim
echo
}
config_warnings ()
{
CONTAINER_STORAGE_DIRVER=$($CONTAINER_CMD info 2>/dev/null |grep "Storage Driver: " | cut -d ":" -f2 | awk '{ sub(/^[ ]+/, ""); print }')
if [ "$CONTAINER_STORAGE_DIRVER" = "overlay" ]; then
echo
echo "Warning: It's strongly recommended to use the 'Overlay2' driver!"
fi
if [ -n "$CONTAINER_IMAGE_ID" ] && [ -n "$IMAGE_ID" ]; then
if [ ! "$CONTAINER_IMAGE_ID" = "$IMAGE_ID" ]; then
log_space "Info: New Image Version available!"
fi
fi
if [ -z "$JQ_VERSION" ] ; then
log_space "Warning: For a better 'inspect' command experience install 'jq' from repository -- infos: https://stedolan.github.io/jq/"
fi
return 0
}
is_sha256()
{
case $1 in
"") return 1 ;;
[!0-9A-Fa-f]) return 2 ;;
*)
case ${#1} in
64) return 0 ;;
* ) return 3 ;;
esac
esac
}
check_version ()
{
local count=1
# Remove any unexpected chars like for Docker CE version on some platforms
local VERSION_STR=$(echo $1 | sed 's/[^0-9.]*//g')
while true
do
VER=$(echo $VERSION_STR|cut -d"." -f $count)
CHECK=$(echo $VERSION_STR|cut -d"." -f $count)
if [ -z "$VER" ]; then return 0; fi
if [ -z "$CHECK" ]; then return 0; fi
if [ $VER -gt $CHECK ]; then return 0; fi
if [ $VER -lt $CHECK ]; then
log_space "Warning: Unsupported $3 version $1 - Must be at least $2 !"
sleep 1
return 1
fi
count=$(expr $count + 1)
done
return 0
}
detect_compose_environment()
{
if [ -n "$CONTAINER_COMPOSE_CMD" ]; then
return 0
fi
# Ensure docker command on Rancher Desktop does not hang during detection
if [ "$CONTAINER_CMD" = "nerdctl" ]; then
return 0
fi
COMPOSE_VERSION=$(docker compose version 2> /dev/null | awk -F'version ' '{print $2}')
if [ -n "$COMPOSE_VERSION" ]; then
CONTAINER_COMPOSE_CMD="docker compose"
return 0
fi
COMPOSE_VERSION=$(docker-compose version 2> /dev/null | grep -i compose | awk -F'version ' '{print $2}')
if [ -n "$COMPOSE_VERSION" ]; then
CONTAINER_COMPOSE_CMD="docker-compose"
return 0
fi
COMPOSE_VERSION=$(podman-compose version 2> /dev/null | grep -i compose | awk -F'version ' '{print $2}' | xargs)
if [ -n "$COMPOSE_VERSION" ]; then
# podman-compose is not supported and cannot be used!
# CONTAINER_COMPOSE_CMD="podman-compose"
return 0
fi
}
detect_container_environment()
{
if [ -n "$CONTAINER_CMD" ]; then
return 0
fi
if [ -n "$USE_DOCKER" ]; then
CONTAINER_CMD=docker
return 0
fi
CONTAINER_RUNTIME_VERSION_STR=$(podman -v 2> /dev/null | head -1)
if [ -n "$CONTAINER_RUNTIME_VERSION_STR" ]; then
CONTAINER_CMD=podman
return 0
fi
CONTAINER_RUNTIME_VERSION_STR=$(nerdctl -v 2> /dev/null | head -1)
if [ -n "$CONTAINER_RUNTIME_VERSION_STR" ]; then
CONTAINER_CMD=nerdctl
return 0
fi
CONTAINER_RUNTIME_VERSION_STR=$(docker -v 2> /dev/null | head -1)
if [ -n "$CONTAINER_RUNTIME_VERSION_STR" ]; then
CONTAINER_CMD=docker
return 0
fi
if [ -z "$CONTAINER_CMD" ]; then
log_space "No container environment detected!"
exit 1
fi
return 0
}
check_container_environment()
{
DOCKER_MINIMUM_VERSION="20.10.0"
PODMAN_MINIMUM_VERSION="3.3.0"
CONTAINER_ENV_NAME=
CONTAINER_RUNTIME_VERSION=
detect_container_environment
detect_compose_environment
TAG_CONTAINER_ID=".Id"
if [ "$CONTAINER_CMD" = "docker" ]; then
CONTAINER_ENV_NAME=docker
if [ -z "$CONTAINER_RUNTIME_VERSION_STR" ]; then
CONTAINER_RUNTIME_VERSION_STR=$(docker -v 2> /dev/null | head -1)
fi
CONTAINER_RUNTIME_VERSION=$(echo $CONTAINER_RUNTIME_VERSION_STR | awk -F'version ' '{print $2 }'|cut -d"," -f1)
# Docker doesn't uses systemd
CONTAINER_SYSTEMD_NAME=
# Check container environment
check_version "$CONTAINER_RUNTIME_VERSION" "$DOCKER_MINIMUM_VERSION" "$CONTAINER_CMD"
# For Docker we are done here
if [ -z "$CONTAINER_HEALTH_CHECK" ]; then
CONTAINER_HEALTH_CHECK="--health-cmd=/healthcheck.sh --health-interval=60s --health-retries=4 --health-start-period=120s"
fi
fi
if [ "$CONTAINER_CMD" = "podman" ]; then
check_version "$CONTAINER_RUNTIME_VERSION" "$PODMAN_MINIMUM_VERSION" "$CONTAINER_CMD"
CONTAINER_ENV_NAME=podman
if [ -z "$CONTAINER_RUNTIME_VERSION_STR" ]; then
CONTAINER_RUNTIME_VERSION_STR=$(podman -v 2> /dev/null | head -1)
fi
CONTAINER_RUNTIME_VERSION=$(echo $CONTAINER_RUNTIME_VERSION_STR | awk -F'version ' '{print $2 }')
if [ "$DOMINO_NO_SYSTEMD" = "yes" ]; then
DOMINO_SYSTEMD_NAME=
else
if [ -z "$DOMINO_SYSTEMD_NAME" ]; then
DOMINO_SYSTEMD_NAME=domino_container.service
fi
fi
if [ -z "$CONTAINER_HEALTH_CHECK" ]; then
CONTAINER_HEALTH_CHECK="--health-cmd=/healthcheck.sh --health-interval=60s --health-retries=4 --health-start-period=120s"
fi
fi
if [ "$CONTAINER_CMD" = "nerdctl" ]; then
CONTAINER_ENV_NAME=nerdctl
if [ -z "$CONTAINER_RUNTIME_VERSION_STR" ]; then
CONTAINER_RUNTIME_VERSION_STR=$(nerdctl -v 2> /dev/null | head -1)
fi
CONTAINER_RUNTIME_VERSION=$(echo $CONTAINER_RUNTIME_VERSION_STR | awk -F'version ' '{print $2 }')
if [ -z "$CONTAINER_NAMESPACE" ]; then
CONTAINER_NAMESPACE=k8s.io
fi
# Always add namespace option to nerdctl command line
CONTAINER_CMD="$CONTAINER_CMD --namespace=$CONTAINER_NAMESPACE"
# nerdctl doesn't uses systemd
CONTAINER_SYSTEMD_NAME=
fi
if [ -z "$CONTAINER_RUNTIME_VERSION" ]; then
if [ ! "$1" = "install" ]; then
log_and_exit "No container environment detected! Tip: use 'install' option to install Podman"
fi
fi
if [ -n "$DOMINO_SYSTEMD_NAME" ]; then
CONTAINER_PID=/run/$DOMINO_SYSTEMD_NAME.pid
CONTAINER_CID=/run/$DOMINO_SYSTEMD_NAME.cid
PODMAN_OPTIONS="--cgroups=no-conmon --conmon-pidfile $CONTAINER_PID --cidfile $CONTAINER_CID"
fi
return 0
}
check_root_permissions ()
{
# Use sudo for su for container command if not root if specified
# Today Docker can run with standard user if user is in 'docker' group.
# You can still enable sudo. systemctl is always invoked with sudo if not root user.
if [ "$EUID" = "0" ]; then
return 0 # root does works for all commands -- no sudo needed
fi
if [ "$CONTAINER_SCRIPT_USE_SUDO" = "yes" ]; then
CONTAINER_CMD="sudo $CONTAINER_CMD"
return 0
fi
SYSTEMCTL_CMD="sudo systemctl"
}
print_runtime ()
{
echo
# the following line does not work on OSX
# echo "Completed in" $(date -d@$SECONDS -u +%T)
hours=$((SECONDS / 3600))
seconds=$((SECONDS % 3600))
minutes=$((seconds / 60))
seconds=$((seconds % 60))
h=""; m=""; s=""
if [ ! $hours = "1" ] ; then h="s"; fi
if [ ! $minutes = "1" ] ; then m="s"; fi
if [ ! $seconds = "1" ] ; then s="s"; fi
if [ ! $hours = 0 ] ; then echo "Completed in $hours hour$h, $minutes minute$m and $seconds second$s"
elif [ ! $minutes = 0 ] ; then echo "Completed in $minutes minute$m and $seconds second$s"
else echo "Completed in $seconds second$s"; fi
}
pull_image ()
{
if [ -z "$CONTAINER_IMAGE" ]; then
log_space "No container image specified"
fi
header "Pulling image $CONTAINER_IMAGE ..."
$CONTAINER_CMD pull "$CONTAINER_IMAGE"
}
upload_image ()
{
# Load image if a .tgz file is specified and skip searching for the image
case "$1" in
*.tgz)
header "Uploading image [$1]"
log_space "Upload takes a moment ..."
$CONTAINER_CMD load --input $1
return 0
;;
esac
if [ -z "$SOFTWARE_FILE" ]; then
SOFTWARE_FILE=/opt/nashcom/startscript/software.txt
fi
if [ ! -r "$SOFTWARE_FILE" ]; then
log_and_exit "No Domino software.txt found"
fi
DOMINO_IMAGE_NAME=domino-docker
local CURRENT_SOFTWARE=$(grep "^$DOMINO_IMAGE_NAME|" $SOFTWARE_FILE | head -1)
DOMINO_VERSION=$(echo $CURRENT_SOFTWARE|cut -d'|' -f2)
DOMINO_IMAGE_FILE_NAME=$(echo $CURRENT_SOFTWARE|cut -d'|' -f3)
DOMINO_IMAGE_VERSION=$(echo $CURRENT_SOFTWARE|cut -d'|' -f4)
DOMINO_IMAGE_HASH=$(echo $CURRENT_SOFTWARE|cut -d'|' -f5)
if [ -z "$DOMINO_IMAGE_FILE_NAME" ]; then
log_and_exit "No container image name configured!"
fi
local SEARCH_IMAGE_ID=$($CONTAINER_CMD inspect --format "{{.ID}}" "$DOMINO_IMAGE_NAME:$DOMINO_IMAGE_VERSION")
if [ -n "$SEARCH_IMAGE_ID" ]; then
if [ "$1" = "force" ]; then
log_space "Replacing existing image"
else
log_space "Image already uploaded"
return 0
fi
fi
# Try current dir first
DOMINO_IMAGE_FILE_PATH=$(find . -name "$DOMINO_IMAGE_FILE_NAME")
# Then try /local
if [ -z "$DOMINO_IMAGE_FILE_PATH" ]; then
DOMINO_IMAGE_FILE_PATH=$(find /local -name "$DOMINO_IMAGE_FILE_NAME" 2>/dev/null | head -1)
fi
# And finally the whole machine
if [ -z "$DOMINO_IMAGE_FILE_PATH" ]; then
DOMINO_IMAGE_FILE_PATH=$(find / -name "$DOMINO_IMAGE_FILE_NAME" 2>/dev/null | head -1)
fi
if [ -z "$DOMINO_IMAGE_FILE_PATH" ]; then
echo
echo "Please download container image from MyHCL Software portal"
echo "$MYHCL_DOWNLOAD_URL"
echo
log_and_exit "Container image file not found!"
fi
if [ -n "$DOMINO_IMAGE_HASH" ]; then
local HASH=$(sha256sum "$DOMINO_IMAGE_FILE_PATH" -b | cut -d" " -f1)
if [ ! "$DOMINO_IMAGE_HASH" = "$HASH" ]; then
log_and_exit "Software image was not downloaded correctly! Checksum for [$DOMINO_IMAGE_FILE_PATH] does not match!"
fi
fi
header "Uploading image [$DOMINO_IMAGE_FILE_PATH]"
log_space "Upload takes a moment ..."
$CONTAINER_CMD load --input "$DOMINO_IMAGE_FILE_PATH"
$CONTAINER_CMD tag "$DOMINO_IMAGE_NAME:$DOMINO_IMAGE_VERSION" "$DOMINO_IMAGE_NAME:latest"
}
nginx_start ()
{
# Create a nginx container hosting software download locally
# Check if we already have this container in status exited
STATUS="$($CONTAINER_CMD inspect --format "{{ .State.Status }}" $SOFTWARE_CONTAINER 2>/dev/null)"
if [ -z "$STATUS" ]; then
log_space "Creating container: $SOFTWARE_CONTAINER"
$CONTAINER_CMD run --name $SOFTWARE_CONTAINER -p $SOFTWARE_PORT:80 -v $SOFTWARE_DIR:/usr/share/nginx/html:ro -d nginx
elif [ "$STATUS" = "exited" ]; then
log_space "Starting existing container: $SOFTWARE_CONTAINER"
$CONTAINER_CMD start $SOFTWARE_CONTAINER
fi
log_space "Starting container: $SOFTWARE_CONTAINER"
# Start local nginx container to host SW Repository
SOFTWARE_REPO_IP="$($CONTAINER_CMD inspect --format "{{ .NetworkSettings.IPAddress }}" $SOFTWARE_CONTAINER 2>/dev/null)"
if [ -z "$SOFTWARE_REPO_IP" ]; then
log_space "Unable to locate software repository."
else
DOWNLOAD_FROM=http://$SOFTWARE_REPO_IP
log_space "Hosting Software repository on $DOWNLOAD_FROM"
fi
}
nginx_stop ()
{
# Stop and remove SW repository
$CONTAINER_CMD stop $SOFTWARE_CONTAINER
$CONTAINER_CMD container rm $SOFTWARE_CONTAINER
log_space "Stopped & Removed Software Repository Container"
}
container_show_status()
{
if [ -z "$CONTAINER_STATUS" ]; then
echo "Status: notexisting"
else
echo Status: "$CONTAINER_STATUS"
fi
return 0
}
container_status ()
{
CONTAINER_STATUS="$($CONTAINER_CMD inspect --format "{{ .State.Status }}" $CONTAINER_NAME 2>/dev/null)"
}
inspect_image_native ()
{
IMAGE_ID="$($CONTAINER_CMD inspect --format "{{.ID}}" $CONTAINER_IMAGE 2>/dev/null | cut -d":" -f2)"
IMAGE_SHORTID=$(echo $IMAGE_ID | cut -c1-12)
if [ -z "$1" ]; then return 0; fi
IMAGE_VERSION="$($CONTAINER_CMD inspect --format "{{ .Config.Labels.version }}" $CONTAINER_IMAGE 2>/dev/null)"
IMAGE_BUILDTIME="$($CONTAINER_CMD inspect --format "{{ .Config.Labels.buildtime }}" $CONTAINER_IMAGE 2>/dev/null)"
IMAGE_SIZE="$($CONTAINER_CMD inspect --format "{{.Size}}" $CONTAINER_IMAGE 2>/dev/null)"
if [ -z "$IMAGE_SIZE" ]; then
IMAGE_SIZE_MB=0
else
IMAGE_SIZE_MB=$(($IMAGE_SIZE / 1000 / 1000 ))
fi
IMAGE_DOMINO_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoContainer.version\" }}" $CONTAINER_IMAGE 2>/dev/null)"
if [ -z "$IMAGE_DOMINO_VERSION" ]; then
IMAGE_DOMINO_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoDocker.version\" }}" $CONTAINER_IMAGE 2>/dev/null)"
fi
IMAGE_TRAVELER_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"TravelerContainer.version\" }}" $CONTAINER_IMAGE 2>/dev/null)"
if [ -z "$IMAGE_TRAVELER_VERSION" ]; then
IMAGE_TRAVELER_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"TravelerDocker.version\" }}" $CONTAINER_IMAGE 2>/dev/null)"
fi
IMAGE_DOMINO_ADDONS="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoContainer.addons\" }}" $CONTAINER_IMAGE 2>/dev/null)"
IMAGE_DOMINO_CUSTOM_ADDONS="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoContainer.custom-addons\" }}" $CONTAINER_IMAGE 2>/dev/null)"
return 0
}
inspect_image ()
{
if [ -z "$JQ_VERSION" ] ; then
inspect_image_native "$@"
return 0
fi
local FULL_JSON=$($CONTAINER_CMD inspect $CONTAINER_IMAGE 2>/dev/null)
if [ -z "$FULL_JSON" ]; then
return 0
fi
if [ "$FULL_JSON" = "[]" ]; then
return 0
fi
local JSON=$(echo $FULL_JSON | jq .[0])
IMAGE_ID=$(echo "$JSON" | jq -r .Id | sed "s/null//" | cut -d":" -f2)
IMAGE_SHORTID=$(echo $IMAGE_ID | cut -c1-12)
if [ -z "$1" ]; then return 0; fi
IMAGE_VERSION="$(echo "$JSON" | jq -r .Config.Labels.version | sed "s/null//")"
IMAGE_BUILDTIME="$(echo "$JSON" | jq -r .Config.Labels.buildtime | sed "s/null//")"
IMAGE_SIZE="$(echo "$JSON" | jq -r .Size | sed "s/null//")"
if [ -z "$IMAGE_SIZE" ]; then
IMAGE_SIZE_MB=0
else
IMAGE_SIZE_MB=$(($IMAGE_SIZE / 1000 / 1000 ))
fi
IMAGE_DOMINO_VERSION="$(echo "$JSON" | jq -r '.Config.Labels."DominoContainer.version"' | sed "s/null//")"
if [ -z "$IMAGE_DOMINO_VERSION" ]; then
IMAGE_DOMINO_VERSION="$(echo "$JSON" | jq -r '.Config.Labels."DominoDocker.version"' | sed "s/null//")"
fi
IMAGE_TRAVELER_VERSION="$(echo "$JSON" | jq -r '.Config.Labels."TravelerContainer.version"' | sed "s/null//")"
if [ -z "$IMAGE_TRAVELER_VERSION" ]; then
IMAGE_TRAVELER_VERSION="$(echo "$JSON" | jq -r '.Config.Labels."TravelerDocker.version"' | sed "s/null//")"
fi
IMAGE_DOMINO_ADDONS="$(echo "$JSON" | jq -r '.Config.Labels."DominoContainer.addons"' | sed "s/null//")"
IMAGE_DOMINO_CUSTOM_ADDONS="$(echo "$JSON" | jq -r '.Config.Labels."DominoContainer.custom-addons"' | sed "s/null//")"
return 0
}
inspect_container_native ()
{
CONTAINER_KEY=
if [ -n "$CONTAINER_CID" ]; then
if [ -e "$CONTAINER_CID" ]; then
CONTAINER_ID=$(cat "$CONTAINER_CID")
CONTAINER_KEY=$CONTAINER_ID
fi
fi
if [ -z "$CONTAINER_KEY" ]; then
CONTAINER_KEY=$CONTAINER_NAME
fi
CONTAINER_STATUS="$($CONTAINER_CMD inspect --format "{{ .State.Status }}" $CONTAINER_KEY 2>/dev/null)"
if [ -z "$CONTAINER_STATUS" ]; then return 0; fi
if [ -z "$CONTAINER_ID" ]; then
CONTAINER_ID="$($CONTAINER_CMD inspect --format "{{ $TAG_CONTAINER_ID }}" $CONTAINER_KEY 2>/dev/null | cut -d":" -f2)"
fi
# nerdctl returns image name instead of ID
local TMP_ID="$($CONTAINER_CMD inspect --format "{{ .Image }}" $CONTAINER_KEY 2>/dev/null)"
CONTAINER_IMAGE_ID="$(echo $TMP_ID | awk -F'sha256:' '{print $2}')"
if [ -z "$CONTAINER_IMAGE_ID" ]; then
is_sha256 "$TMP_ID"
if [ "$?" = "0" ]; then
CONTAINER_IMAGE_ID="$TMP_ID"
else
CONTAINER_IMAGE_ID="$($CONTAINER_CMD inspect --format "{{.ID}}" $TMP_ID 2>/dev/null | cut -d":" -f2)"
fi
fi
CURRENT_CONTAINER_IMAGE="$($CONTAINER_CMD inspect --format "{{ .Image }}" $CONTAINER_IMAGE_ID 2>/dev/null)"
if [ -z "$CURRENT_CONTAINER_IMAGE" ]; then
CURRENT_CONTAINER_IMAGE=$TMP_ID
fi
CONTAINER_IMAGE_SHORTID=$(echo $CONTAINER_IMAGE_ID | cut -c1-12)
CONTAINER_VERSION="$($CONTAINER_CMD inspect --format "{{ .Config.Labels.version }}" $CONTAINER_IMAGE_ID 2>/dev/null)"
CONTAINER_BUILDTIME="$($CONTAINER_CMD inspect --format "{{ .Config.Labels.buildtime }}" $CONTAINER_IMAGE_ID 2>/dev/null)"
if [ -z "$1" ]; then return 0; fi
CONTAINER_NAME_DISPLAY="$($CONTAINER_CMD inspect --format "{{ .Name }}" $CONTAINER_KEY | cut -d/ -f2 2>/dev/null)"
CONTAINER_HOSTNAME="$($CONTAINER_CMD inspect --format "{{ .Config.Hostname }}" $CONTAINER_KEY 2>/dev/null)"
CONTAINER_DRIVER="$($CONTAINER_CMD inspect --format "{{ .Driver }}" $CONTAINER_KEY 2>/dev/null)"
CONTAINER_PLATFORM="$($CONTAINER_CMD inspect --format "{{ .Platform }}" $CONTAINER_KEY 2>/dev/null)"
CONTAINER_NETWORKMODE="$($CONTAINER_CMD inspect --format "{{ .HostConfig.NetworkMode }}" $CONTAINER_KEY 2>/dev/null)"
if [ -z "$CONTAINER_NETWORK_NAME" ]; then
CONTAINER_IPADDRESS="$($CONTAINER_CMD inspect --format "{{ .NetworkSettings.IPAddress }}" $CONTAINER_KEY 2>/dev/null)"
else
CONTAINER_IPADDRESS="$($CONTAINER_CMD inspect --format "{{ .NetworkSettings.Networks.$CONTAINER_NETWORK_NAME.IPAddress }}" $CONTAINER_KEY 2>/dev/null)"
fi
if [ "$CONTAINER_IPADDRESS" = "<no value>" ]; then
CONTAINER_IPADDRESS=
fi
CONTAINER_VOLUMES="$($CONTAINER_CMD inspect --format '{{range .Mounts}} {{ .Source }} {{end}}' $CONTAINER_KEY | xargs 2>/dev/null)"
CONTAINER_MOUNTS="$($CONTAINER_CMD inspect --format '{{range .Mounts}} {{ .Destination }} {{end}}' $CONTAINER_KEY | xargs 2>/dev/null)"
if [ "$CONTAINER_CMD" = "docker" ]; then
CONTAINER_HEALTH="$($CONTAINER_CMD inspect --format "{{ .State.Health.Status }}" $CONTAINER_KEY 2>/dev/null)"
else
CONTAINER_HEALTH="$($CONTAINER_CMD inspect --format "{{ .State.Healthcheck.Status }}" $CONTAINER_KEY 2>/dev/null)"
fi
CONTAINER_DOMINO_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoContainer.version\" }}" $CONTAINER_KEY 2>/dev/null)"
if [ -z "$CONTAINER_DOMINO_VERSION" ]; then
CONTAINER_DOMINO_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoDocker.version\" }}" $CONTAINER_KEY 2>/dev/null)"
fi
CONTAINER_TRAVELER_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"TravelerContainer.version\" }}" $CONTAINER_KEY 2>/dev/null)"
if [ -z "$CONTAINER_TRAVELER_VERSION" ]; then
CONTAINER_TRAVELER_VERSION="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"TravelerDocker.version\" }}" $CONTAINER_KEY 2>/dev/null)"
fi
CONTAINER_DOMINO_ADDONS="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoContainer.addons\" }}" $CONTAINER_KEY 2>/dev/null)"
CONTAINER_DOMINO_CUSTOM_ADDONS="$($CONTAINER_CMD inspect --format "{{ index .Config.Labels \"DominoContainer.custom-addons\" }}" $CONTAINER_KEY 2>/dev/null)"
STARTDATE="$($CONTAINER_CMD inspect --format "{{ .State.StartedAt }}" $CONTAINER_KEY | cut -f1 -d+ 2>/dev/null)"
CONTAINER_STARTED_AT=$(date +"%d.%m.%Y %H:%M:%S" -d "$STARTDATE" 2>/dev/null)
if [ -z "$CONTAINER_STARTED_AT" ]; then
CONTAINER_STARTED_AT=$STARTDATE
fi
# Docker specific information
if [ "$CONTAINER_CMD" = "docker" ]; then
CONTAINER_RESTART_POLICY="$($CONTAINER_CMD inspect --format "{{ .HostConfig.RestartPolicy.Name }}" $CONTAINER_KEY 2>/dev/null)"
CONTAINER_RESTART_POLICY_MAX_RETRY="$($CONTAINER_CMD inspect --format "{{ .HostConfig.RestartPolicy.MaximumRetryCount }}" $CONTAINER_KEY 2>/dev/null)"
fi
return 0
}
inspect_container ()
{
CONTAINER_STATUS=
CONTAINER_VERSION=
if [ -z "$JQ_VERSION" ] ; then
inspect_container_native "$@"
return 0
fi
CONTAINER_KEY=
if [ -n "$CONTAINER_CID" ]; then
if [ -e "$CONTAINER_CID" ]; then
CONTAINER_ID=$(cat "$CONTAINER_CID")
CONTAINER_KEY=$CONTAINER_ID
fi
fi
if [ -z "$CONTAINER_KEY" ]; then
CONTAINER_KEY=$CONTAINER_NAME
fi
local FULL_JSON=$($CONTAINER_CMD inspect $CONTAINER_KEY 2>/dev/null)
if [ -z "$FULL_JSON" ]; then
return 0
fi
if [ "$FULL_JSON" = "[]" ]; then
return 0
fi
local JSON=$(echo $FULL_JSON | jq .[0])
CONTAINER_STATUS=$(echo "$JSON" | jq -r .State.Status | sed "s/null//")
CONTAINER_VERSION=$(echo "$JSON" | jq -r .Config.Labels.version | sed "s/null//")
if [ -z "$CONTAINER_STATUS" ]; then return 0; fi
if [ -z "$CONTAINER_ID" ]; then
CONTAINER_ID=$(echo "$JSON" | jq -r $TAG_CONTAINER_ID | sed "s/null//")
fi
CONTAINER_SHORTID=$(echo $CONTAINER_ID | cut -d":" -f2 | cut -c1-12)
# nerdctl returns image name instead of ID
local TMP_ID=$(echo "$JSON" | jq -r .Image | sed "s/null//")
CONTAINER_IMAGE_ID="$(echo $TMP_ID | awk -F'sha256:' '{print $2}')"
if [ -z "$CONTAINER_IMAGE_ID" ]; then
is_sha256 "$TMP_ID"
if [ "$?" = "0" ]; then
CONTAINER_IMAGE_ID="$TMP_ID"
else
CONTAINER_IMAGE_ID="$($CONTAINER_CMD inspect --format "{{.ID}}" $TMP_ID 2>/dev/null | cut -d":" -f2 )"
fi
fi
CURRENT_CONTAINER_IMAGE=$(echo "$JSON" | jq -r .Config.Image | sed "s/null//")
if [ -z "$CURRENT_CONTAINER_IMAGE" ]; then
CURRENT_CONTAINER_IMAGE=$TMP_ID
fi
CONTAINER_IMAGE_SHORTID=$(echo $CONTAINER_IMAGE_ID | cut -c1-12)
if [ -z "$1" ]; then return 0; fi
CONTAINER_NAME_DISPLAY=$(echo "$JSON" | jq -r .Name | sed "s/null//")
CONTAINER_HOSTNAME=$(echo "$JSON" | jq -r .Config.Hostname | sed "s/null//")
CONTAINER_DRIVER=$(echo "$JSON" | jq -r .Driver | sed "s/null//")
CONTAINER_PLATFORM=$(echo "$JSON" | jq -r .Platform | sed "s/null//")
CONTAINER_NETWORKMODE=$(echo "$JSON" | jq -r .HostConfig.NetworkMode | sed "s/null//")
if [ -z "$CONTAINER_NETWORK_NAME" ]; then
CONTAINER_IPADDRESS=$(echo "$JSON" | jq -r .NetworkSettings.IPAddress | sed "s/null//")
else
CONTAINER_IPADDRESS=$(echo "$JSON" | jq -r .NetworkSettings.Networks.$CONTAINER_NETWORK_NAME.IPAddress | sed "s/null//")
fi
if [ "$CONTAINER_IPADDRESS" = "<no value>" ]; then
CONTAINER_IPADDRESS=
fi
CONTAINER_BUILDTIME=$(echo "$JSON" | jq -r .Config.Labels.buildtime | sed "s/null//")
CONTAINER_VOLUMES=$(echo "$JSON" | jq -r .Mounts[].Source | sed "s/null//" | xargs)
CONTAINER_MOUNTS=$(echo "$JSON" | jq -r .Mounts[].Destination | sed "s/null//" | xargs)
if [ "$CONTAINER_CMD" = "docker" ]; then
CONTAINER_HEALTH=$(echo "$JSON" | jq -r .State.Health.Status | sed "s/null//")
else
CONTAINER_HEALTH=$(echo "$JSON" | jq -r .State.Healthcheck.Status | sed "s/null//")
fi
CONTAINER_DOMINO_VERSION=$(echo "$JSON" | jq -r '.Config.Labels."DominoContainer.version"' | sed "s/null//")
if [ -z "$CONTAINER_DOMINO_VERSION" ]; then
CONTAINER_DOMINO_VERSION=$(echo "$JSON" | jq -r '.Config.Labels."DominoDocker.version"' | sed "s/null//")
fi
CONTAINER_TRAVELER_VERSION=$(echo "$JSON" | jq -r '.Config.Labels."TravelerContainer.version"' | sed "s/null//")
if [ -z "$CONTAINER_TRAVELER_VERSION" ]; then
CONTAINER_TRAVELER_VERSION=$(echo "$JSON" | jq -r '.Config.Labels."TravelerDocker.version"' | sed "s/null//")
fi
CONTAINER_DOMINO_ADDONS=$(echo "$JSON" | jq -r '.Config.Labels."DominoContainer.addons"' | sed "s/null//")
CONTAINER_DOMINO_CUSTOM_ADDONS=$(echo "$JSON" | jq -r '.Config.Labels."DominoContainer.custom-addons"' | sed "s/null//")
STARTDATE=$(echo "$JSON" | jq -r .State.StartedAt | sed "s/null//" | cut -f1 -d+ 2>/dev/null)
CONTAINER_STARTED_AT=$(date +"%d.%m.%Y %H:%M:%S" -d "$STARTDATE" 2>/dev/null)
if [ -z "$CONTAINER_STARTED_AT" ]; then
CONTAINER_STARTED_AT=$STARTDATE
fi
# Docker specific information
if [ "$CONTAINER_CMD" = "docker" ]; then
CONTAINER_RESTART_POLICY="$(echo "$JSON" | jq -r .HostConfig.RestartPolicy.Name | sed "s/null//")"
CONTAINER_RESTART_POLICY_MAX_RETRY="$(echo "$JSON" | jq -r .HostConfig.RestartPolicy.MaximumRetryCount | sed "s/null//")"
fi
return 0
}
container_inspect_extras ()
{
if [ -z "$1" ]; then return 0; fi
# nerdctl has issues with interactive mode in shell scripts
if [ "$CONTAINER_ENV_NAME" = "nerdctl" ]; then
return 0
fi
if [ "$CONTAINER_STATUS" = "running" ]; then
# CONTAINER_OS_VERSION=$($CONTAINER_CMD exec -it $CONTAINER_NAME cat /etc/os-release)
# CONTAINER_OS_KERNEL=$($CONTAINER_CMD exec -it $CONTAINER_NAME uname -r)
CONTAINER_DOMINO_REV=$($CONTAINER_CMD exec -it $CONTAINER_NAME cat /opt/hcl/domino/.install.dat | awk -F '(=| =)' -v SEARCH_STR="rev" '{if (tolower($1) == tolower(SEARCH_STR)) print $2}' | cut -d'"' -f2)