-
-
Save ael-code/4ceacac5683e33830ac5496f225bdb1b to your computer and use it in GitHub Desktop.
Libreant installation test script based on docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
DIR=$(dirname "$(readlink -f "$0")") | |
LIBREANT_SRC=$(readlink -f ${DIR}/..) | |
CURL_RETRY_DELAY=3 # seconds | |
CURL_RETRIES=30 # seconds | |
DEBIAN="debian-stable" | |
UBUNTU="ubuntu-lts" | |
ARCH="arch" | |
OSES=( ${DEBIAN} ${UBUNTU} ${ARCH} ) | |
PREFIX="libreant-inst-test__" | |
function cleanup { | |
for os in ${OSES[@]}; do | |
docker kill ${OSES[@]/#/"$PREFIX"} > /dev/null 2>&1 | |
done | |
} | |
function test_libreant_search { | |
curl -f -sS "localhost:5000/search?q=*:*" > /dev/null | |
} | |
function with_backoff { | |
local max_attempts=${CURL_RETRIES} | |
local timeout=${CURL_RETRY_DELAY} | |
local attempt=0 | |
local exitCode=0 | |
while (( $attempt < $max_attempts )) | |
do | |
set +e | |
"$@" | |
exitCode=$? | |
set -e | |
if [[ $exitCode == 0 ]]; then | |
break | |
fi | |
printf ". " | |
sleep $timeout | |
attempt=$(( attempt + 1 )) | |
done | |
if [[ $exitCode != 0 ]] | |
then | |
echo "Failed too many times" 1>&2 | |
else | |
printf "\n" | |
fi | |
return $exitCode | |
} | |
trap cleanup EXIT | |
set -e | |
for os in ${OSES[@]} ; do | |
printf "Testing libreant installation on ${os}\n" | |
docker build --file="${LIBREANT_SRC}/.docker/dockerfile-${os}" --tag="${PREFIX}${os}" "${LIBREANT_SRC}" | |
docker run --rm -p 5000:5000 -d --name ${PREFIX}${os} ${PREFIX}${os} | |
with_backoff test_libreant_search | |
docker kill ${PREFIX}${os} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment