2018-05-04 18:03:18 +00:00
|
|
|
#!/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"
|
|
|
|
|
2018-06-13 16:00:04 +00:00
|
|
|
MYSQL_IMAGE="mysql:5.7"
|
2018-05-04 18:03:18 +00:00
|
|
|
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}"
|
|
|
|
}
|
|
|
|
|
2018-06-13 14:43:39 +00:00
|
|
|
fail_clean() {
|
|
|
|
if [[ $TRAVIS_TEST_RESULT -ne 0 ]]; then
|
|
|
|
echo "Job failed. Cleaning cache..."
|
|
|
|
clean_cache
|
|
|
|
fi
|
|
|
|
}
|
2018-05-04 18:03:18 +00:00
|
|
|
|
|
|
|
quay_run() {
|
2018-06-13 00:35:37 +00:00
|
|
|
docker run --net=host -e TEST_DATABASE_URI -ti "${IMAGE}:${IMAGE_TAG}" "$@"
|
2018-05-04 18:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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() {
|
2018-07-24 17:36:33 +00:00
|
|
|
mysqladmin --connect-timeout=2 --wait=60 --host=127.0.0.1 \
|
2018-05-04 18:03:18 +00:00
|
|
|
--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}"
|
|
|
|
|
2018-07-24 17:36:33 +00:00
|
|
|
if ! (sleep 20 && mysql_ping); then
|
2018-05-04 18:03:18 +00:00
|
|
|
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
|
|
|
|
;;
|
|
|
|
|
2018-06-13 14:43:39 +00:00
|
|
|
fail-clean)
|
|
|
|
fail_clean
|
|
|
|
;;
|
|
|
|
|
2018-05-04 18:03:18 +00:00
|
|
|
clean)
|
|
|
|
clean_cache
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {build|unit|registry|registry_old|mysql|postgres|clean}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|