forked from nasa/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-harmony
executable file
·94 lines (79 loc) · 2.32 KB
/
update-harmony
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
#!/bin/bash
# Update the harmonyservices/harmony and harmonyservices/query-cmr images and optionally
# update service images
source "env-defaults"
source ".env"
# set -e
SELF=$(basename $0)
function usage
{
echo -e "\033[1mUSAGE\033[0m"
echo -e "\033[1m$SELF\033[0m [-h|--help] [-s|--services]"
echo " -s|--services Upate service images in addition to harmony images."
echo " -h|--help Print this message."
echo -e "\033[1mDESCRIPTION\033[0m"
echo "This script updates the Docker images used internally by Harmony then restars Harmony."
echo "Optionally it can also update the service images."
}
RELOAD_SERVICES=false
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-s|--services)
RELOAD_SERVICES=true
shift
;;
-h|--help)
usage && exit 0
;;
*)
usage && exit 1
;;
esac
done
if [ "$RELOAD_SERVICES" = true ]; then
# read all the image env vars from services.yml
image_vars=()
while read -r line; do
if [[ $line =~ ^.*image:[[:space:]]+!Env[[:space:]]+\$\{(.*)\} ]]; then
image_var=${BASH_REMATCH[1]}
if [[ ! " ${image_vars[@]} " =~ " ${image_var} " ]]; then
image_vars+=( "$image_var" )
fi
fi
done < ./config/services.yml
referenced_images=()
for img_var in ${image_vars[@]}; do
referenced_images+=( "${!img_var}" )
done
# read all the images that are in the local Docker cache
pulled_images=()
IFS=$'\n' lines=(`docker images --format "{{.Repository}}:{{.Tag}}"`)
for line in ${lines[@]}; do
if [[ $line =~ ^(.+):(.+) ]]; then
image_tag="${BASH_REMATCH[1]}:${BASH_REMATCH[2]}"
if [[ ! " ${pulled_images[@]} " =~ " ${image_tag} " ]]; then
pulled_images+=( "$image_tag" )
fi
fi
done
fi
# create a list of images that are in both of the previous lists
all_images=()
while read -r line; do
all_images+=( "$line" )
done < <(sort <(echo "${referenced_images[*]}") <(echo "${pulled_images[*]}") | uniq -d)
# always reload the harmony image and the query-cmr image
all_images+=( "harmonyservices/harmony:latest" "harmonyservices/query-cmr:latest" )
for image in ${all_images[@]}; do
echo "${image}"
docker pull "${image}" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "${image} successfully updated"
else
echo "WARNING: ${image} could not be updated"
fi
done
# restart harmony
./bin/reload-services-config