comparison docker/libervia_cont.sh @ 110:51dc15fbd813

docker (libervia_cont): added check_docker_version function which return 0 if current docker version is greater than wanted one, -1 else
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 21:54:41 +0100
parents cb16c0a1f194
children a3f9cfa2721e
comparison
equal deleted inserted replaced
109:cb16c0a1f194 110:51dc15fbd813
154 which $DOCKER_EXE > /dev/null 2>&1 154 which $DOCKER_EXE > /dev/null 2>&1
155 if [ $? -ne 0 ]; then 155 if [ $? -ne 0 ]; then
156 printf "Docker is not installed or not accessible, please install it.\nYou can check $HELP_SITE for instructions\n" 156 printf "Docker is not installed or not accessible, please install it.\nYou can check $HELP_SITE for instructions\n"
157 return 1 157 return 1
158 fi 158 fi
159 }
160
161 check_docker_version() {
162 # check if current docker version is greater than or equal to the requested one
163 wanted_major=$1
164 wanted_minor=$2
165 wanted_rev=$3
166 raw=$(docker --version | grep -o '\([0-9]\+\)\.[0-9]\+\.[0-9]\+')
167 docker_major=$(echo "$raw" | cut -d . -f 1)
168 docker_minor=$(echo "$raw" | cut -d . -f 2)
169 docker_rev=$(echo "$raw" | cut -d . -f 3)
170 for name in major minor rev; do
171 docker_val=$(eval echo \$docker_$name)
172 wanted_val=$(eval echo \$wanted_$name)
173 if [ $docker_val -gt $wanted_val ]; then
174 return 0
175 fi
176 if [ $docker_val -lt $wanted_val ]; then
177 return 1
178 fi
179 done
180
181 # wanted version and docker version are the same
182 return 0
159 } 183 }
160 184
161 parse_run_args() { 185 parse_run_args() {
162 # manage arguments for run command 186 # manage arguments for run command
163 187
297 if [ $? -eq 0 ]; then 321 if [ $? -eq 0 ]; then
298 printf "$APP_NAME is running" 322 printf "$APP_NAME is running"
299 # we test the presence of "starting on xxxx" (where xxxx is one of the exposed ports) 323 # we test the presence of "starting on xxxx" (where xxxx is one of the exposed ports)
300 # this is not really reliable as ports can be changed in configuration 324 # this is not really reliable as ports can be changed in configuration
301 # but in most case it should work OK 325 # but in most case it should work OK
302 PORTS_REGEX=$(get_dyn_var $TEST_CONT ports | sed 's/ /\\|/') 326 PORTS_REGEX=$(get_dyn_var $TEST_CONT ports | sed 's/ /\\|/')
303 docker logs $TEST_CONT | grep "starting on \($PORTS_REGEX\)" > /dev/null 2>&1 327 docker logs $TEST_CONT | grep "starting on \($PORTS_REGEX\)" > /dev/null 2>&1
304 if [ $? -ne 0 ]; then 328 if [ $? -ne 0 ]; then
305 printf " but no server is started\n" 329 printf " but no server is started\n"
306 exit 2 330 exit 2
307 fi 331 fi