479f4c3fa4
increase timeout for cache push revert test db change
159 lines
2.9 KiB
Bash
Executable file
159 lines
2.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
IMAGE="quay-ci"
|
|
|
|
CACHE_DIR="${HOME}/docker"
|
|
SHORT_SHA="${TRAVIS_COMMIT:0:7}"
|
|
IMAGE_TAG="${SHORT_SHA}-${TRAVIS_BUILD_NUMBER}"
|
|
IMAGE_TAR="${CACHE_DIR}/${IMAGE}-${IMAGE_TAG}.tar.gz"
|
|
|
|
MYSQL_IMAGE="mysql:5.6"
|
|
POSTGRES_IMAGE="postgres:9.6"
|
|
|
|
export MYSQL_ROOT_PASSWORD="quay"
|
|
export MYSQL_USER="quay"
|
|
export MYSQL_PASSWORD="quay"
|
|
export MYSQL_DATABASE="quay_ci"
|
|
|
|
export POSTGRES_USER="quay"
|
|
export POSTGRES_PASSWORD="quay"
|
|
export POSTGRES_DB="quay_ci"
|
|
|
|
|
|
build_image() {
|
|
# Build the image and save it to the shared cache.
|
|
docker build -t "${IMAGE}:${IMAGE_TAG}" .
|
|
|
|
echo "Exporting Docker image to cache..."
|
|
time (docker save "${IMAGE}:${IMAGE_TAG}" | gzip -2 > "${IMAGE_TAR}")
|
|
}
|
|
|
|
|
|
load_image() {
|
|
# Load our cached Docker image.
|
|
echo "Loading Docker image from cache..."
|
|
time (zcat "${IMAGE_TAR}" | docker load)
|
|
}
|
|
|
|
|
|
clean_cache() {
|
|
rm "${IMAGE_TAR}"
|
|
}
|
|
|
|
|
|
quay_run() {
|
|
docker run --net=host --entrypoint "/bin/bash" -e TEST_DATABASE_URI -ti "${IMAGE}:${IMAGE_TAG}" -c "$*"
|
|
}
|
|
|
|
|
|
unit() {
|
|
load_image && quay_run make unit-test
|
|
}
|
|
|
|
|
|
registry() {
|
|
load_image && quay_run make registry-test
|
|
}
|
|
|
|
|
|
registry_old() {
|
|
load_image && quay_run make registry-test-old
|
|
}
|
|
|
|
|
|
mysql_ping() {
|
|
mysqladmin --connect-timeout=2 --wait=30 --host=127.0.0.1 \
|
|
--user=root --password="${MYSQL_ROOT_PASSWORD}" ping
|
|
}
|
|
|
|
|
|
mysql_start() {
|
|
docker run --net=host -d -e MYSQL_ROOT_PASSWORD -e MYSQL_USER \
|
|
-e MYSQL_PASSWORD -e MYSQL_DATABASE "${MYSQL_IMAGE}"
|
|
|
|
if ! (sleep 10 && mysql_ping); then
|
|
echo "MySQL failed to respond in time."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
|
|
mysql() {
|
|
TEST_DATABASE_URI="mysql+pymysql://"
|
|
TEST_DATABASE_URI+="${MYSQL_USER}:${MYSQL_PASSWORD}"
|
|
TEST_DATABASE_URI+="@127.0.0.1/${MYSQL_DATABASE}"
|
|
|
|
export TEST_DATABASE_URI
|
|
|
|
load_image
|
|
mysql_start
|
|
quay_run make full-db-test
|
|
}
|
|
|
|
|
|
postgres_ping() {
|
|
pg_isready --timeout=30 --dbname="${TEST_DATABASE_URI}"
|
|
}
|
|
|
|
|
|
postgres_start() {
|
|
docker run --net=host -d -e POSTGRES_USER -e POSTGRES_PASSWORD \
|
|
-e POSTGRES_DB "${POSTGRES_IMAGE}"
|
|
|
|
if ! (sleep 10 && postgres_ping); then
|
|
echo "PostgreSQL failed to respond in time."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
|
|
postgres() {
|
|
TEST_DATABASE_URI="postgresql://"
|
|
TEST_DATABASE_URI+="${POSTGRES_USER}:${POSTGRES_PASSWORD}"
|
|
TEST_DATABASE_URI+="@127.0.0.1/${POSTGRES_DB}"
|
|
|
|
export TEST_DATABASE_URI
|
|
|
|
load_image
|
|
postgres_start
|
|
quay_run make full-db-test
|
|
}
|
|
|
|
|
|
case "$1" in
|
|
build)
|
|
build_image
|
|
;;
|
|
|
|
unit)
|
|
unit
|
|
;;
|
|
|
|
registry)
|
|
registry
|
|
;;
|
|
|
|
registry_old)
|
|
registry_old
|
|
;;
|
|
|
|
mysql)
|
|
mysql
|
|
;;
|
|
|
|
postgres)
|
|
postgres
|
|
;;
|
|
|
|
clean)
|
|
clean_cache
|
|
;;
|
|
|
|
*)
|
|
echo "Usage: $0 {build|unit|registry|registry_old|mysql|postgres|clean}"
|
|
exit 1
|
|
;;
|
|
esac
|