Skip to content

Instantly share code, notes, and snippets.

@ael-code
Forked from anonymous/test_all.sh
Last active December 14, 2017 18:38
Show Gist options
  • Save ael-code/4ceacac5683e33830ac5496f225bdb1b to your computer and use it in GitHub Desktop.
Save ael-code/4ceacac5683e33830ac5496f225bdb1b to your computer and use it in GitHub Desktop.
Libreant installation test script based on docker containers
#! /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