github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/tools/packaging/test-packages (about) 1 #!/usr/bin/env bash 2 3 set -euf -o pipefail 4 5 readonly IMAGE_PREFIX=$1 6 readonly VERSION=$2 7 readonly DISABLE_CLEANUP=${DISABLE_CLEANUP:-0} 8 9 declare -a CONTAINERS=() 10 11 function error() { 12 echo "$@"; exit 1 13 } 14 15 function cleanup() { 16 if [[ "${DISABLE_CLEANUP}" -ne 1 ]]; then 17 docker rm --force "${CONTAINERS[@]}" &>/dev/null 18 fi 19 } 20 21 function ready() { 22 local -ri max_attempts=$1 23 local -ri sleep_interval=$2 24 local -ri port=$3 25 local -i attempt=1 26 27 sleep "${sleep_interval}" 28 until curl -s localhost:"${port}"/ready | grep -q ready; do 29 if [[ ${attempt} -eq ${max_attempts} ]]; then 30 echo "Cortex not ready in ${max_attempts} attempts" 31 return 1 32 else 33 (( attempt++ )) 34 fi 35 sleep "${sleep_interval}" 36 done 37 } 38 39 trap cleanup EXIT 40 41 function test_with_systemd() { 42 local -r image=$1 43 local -r platform=$2 44 local -r install_command=$3 45 local container 46 47 echo "Testing $install_command on $image ($platform)" 48 49 container=$(docker run --platform="${platform}" --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -itd -v "$(pwd)"/dist:/opt/cortex -p 9009 "${image}") 50 CONTAINERS+=("${container}") 51 52 port=$(docker inspect --format='{{(index (index .NetworkSettings.Ports "9009/tcp") 0).HostPort}}' "${container}") 53 54 docker exec -it "${container}" /bin/bash -c "${install_command}; systemctl start cortex.service; systemctl enable cortex.service" 55 56 ready 10 1 "${port}" || error "Testing image: ${image} with command: '${install_command}' failed" 57 } 58 59 test_with_systemd "${IMAGE_PREFIX}"debian-systemd:amd64 linux/amd64 "dpkg -i /opt/cortex/cortex-${VERSION}_amd64.deb" 60 test_with_systemd "${IMAGE_PREFIX}"debian-systemd:arm64 linux/arm64 "dpkg -i /opt/cortex/cortex-${VERSION}_arm64.deb" 61 62 test_with_systemd "${IMAGE_PREFIX}"centos-systemd:amd64 linux/amd64 "rpm -i /opt/cortex/cortex-${VERSION}_amd64.rpm" 63 test_with_systemd "${IMAGE_PREFIX}"centos-systemd:arm64 linux/arm64 "rpm -i /opt/cortex/cortex-${VERSION}_arm64.rpm"