forked from ODIM-Project/ODIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-images.sh
executable file
·104 lines (92 loc) · 2.6 KB
/
docker-images.sh
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
#!/bin/bash
#(C) Copyright [2020] Hewlett Packard Enterprise Development LP
#
#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.
declare ACTION
declare DIR_PATH
declare -A images_list=(\
["account-session"]="5.0" \
["aggregation"]="6.0" \
["api"]="7.0" \
["etcd"]="1.16" \
["events"]="7.0" \
["fabrics"]="5.0" \
["kafka"]="3.0" \
["managers"]="7.0" \
["redis"]="5.0" \
["systems"]="7.0" \
["task"]="6.0" \
["telemetry"]="4.0"\
["update"]="6.0" \
["zookeeper"]="3.0" \
["licenses"]="4.0" \
)
eval_cmd_exec()
{
if [[ $# -lt 3 ]]; then
echo "[$(date)] -- ERROR -- eval_cmd_exec syntax error $2"
exit 1
fi
if [[ $1 -eq 0 ]]; then
echo "[$(date)] -- INFO -- $4"
else
echo "[$(date)] -- ERROR -- $2"
echo "$3"
fi
}
load_images()
{
for image in "${!images_list[@]}"; do
output=$(docker load -i ${DIR_PATH}/${image}.tar 2>&1)
eval_cmd_exec $? "failed to load ${DIR_PATH}/${image}.tar" \
"$output" "Successfully loaded ${DIR_PATH}/${image}.tar"
done
echo "[$(date)] -- INFO -- Cleaning up any dangling images created while loading images"
docker rmi $(/usr/bin/docker images -f "dangling=true" -q) > /dev/null 2>&1
}
save_images()
{
for image in "${!images_list[@]}"; do
output=$(docker save -o ${DIR_PATH}/${image}.tar ${image}:${images_list[${image}]} 2>&1)
eval_cmd_exec $? "failed to save ${image}:${images_list[${image}]} as ${DIR_PATH}/${image}.tar" \
"$output" "Successfully saved ${image}:${images_list[${image}]} as ${DIR_PATH}/${image}.tar"
done
}
usage()
{
echo -e "$(basename $BASH_SOURCE) load|save <dir_path_to_save_or_load_from>"
exit 1
}
##############################################
############### MAIN #######################
##############################################
ACTION=$1
DIR_PATH=$2
if [[ $# -gt 2 ]]; then
usage
fi
if [[ -z ${DIR_PATH} ]]; then
DIR_PATH="."
fi
case $1 in
load)
load_images
;;
save)
save_images
;;
*)
usage
;;
esac
exit 0