mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
separate docker-db from init-db
so we don't need docker on Travis
This commit is contained in:
@@ -1,19 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
NAME="hub-test-$DB"
|
||||
docker rm -f $NAME 2>/dev/null || true
|
||||
# source this file to setup postgres and mysql
|
||||
# for local testing (as similar as possible to docker)
|
||||
|
||||
case $DB in
|
||||
mysql)
|
||||
ARGS="-p 13306:3306 -e MYSQL_ROOT_PASSWORD=x -e MYSQL_DATABASE=jupyterhub mysql:5.7"
|
||||
;;
|
||||
postgres)
|
||||
ARGS="-p 15432:5432 -e POSTGRES_DB=jupyterhub postgres:9.5"
|
||||
;;
|
||||
*)
|
||||
echo "must be mysql or postgres"
|
||||
exit -1
|
||||
esac
|
||||
DOCKER="docker run --rm -d --name"
|
||||
|
||||
set -x
|
||||
docker run --rm --name $NAME -d $ARGS
|
||||
export MYSQL_HOST=127.0.0.1
|
||||
export PGHOST=127.0.0.1
|
||||
|
||||
set -ex
|
||||
docker rm -f hub-test-mysql hub-test-postgres 2>/dev/null || true
|
||||
|
||||
$DOCKER hub-test-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -p 3306:3306 mysql:5.7
|
||||
$DOCKER hub-test-postgres -p 5432:5432 postgres:9.5
|
||||
set +x
|
||||
|
||||
echo -n 'waiting for postgres'
|
||||
for i in {1..60}; do
|
||||
if psql --user postgres -c '\q' 2>/dev/null; then
|
||||
echo 'done'
|
||||
break
|
||||
else
|
||||
echo -n '.'
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo -n 'waiting for mysql'
|
||||
for i in {1..60}; do
|
||||
if mysql --user root -e '\q' 2>/dev/null; then
|
||||
echo 'done'
|
||||
break
|
||||
else
|
||||
echo -n '.'
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "
|
||||
Set these environment variables:
|
||||
|
||||
export MYSQL_HOST=127.0.0.1
|
||||
export PGHOST=127.0.0.1
|
||||
"
|
14
test-db-upgrade/init-db.sh
Normal file
14
test-db-upgrade/init-db.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
set -e
|
||||
|
||||
MYSQL="mysql --user root -e "
|
||||
PSQL="psql --user postgres -c "
|
||||
|
||||
set -x
|
||||
|
||||
# drop databases if they don't exist
|
||||
$MYSQL 'DROP DATABASE jupyterhub_upgrade' 2>/dev/null || true
|
||||
$PSQL 'DROP DATABASE jupyterhub_upgrade' 2>/dev/null || true
|
||||
|
||||
# create the databases
|
||||
$MYSQL 'CREATE DATABASE jupyterhub_upgrade CHARACTER SET utf8 COLLATE utf8_general_ci;'
|
||||
$PSQL 'CREATE DATABASE jupyterhub_upgrade;'
|
@@ -3,9 +3,9 @@ c.JupyterHub.cookie_secret = os.urandom(32)
|
||||
|
||||
DB = os.environ.get('DB')
|
||||
if DB == 'mysql':
|
||||
c.JupyterHub.db_url = 'mysql+pymysql://root:x@127.0.0.1:13306/jupyterhub'
|
||||
c.JupyterHub.db_url = 'mysql+pymysql://root@127.0.0.1/jupyterhub_upgrade'
|
||||
elif DB == 'postgres':
|
||||
c.JupyterHub.db_url = 'postgresql://postgres@127.0.0.1:15432/jupyterhub'
|
||||
c.JupyterHub.db_url = 'postgresql://postgres@127.0.0.1/jupyterhub_upgrade'
|
||||
|
||||
c.JupyterHub.authenticator_class = 'jupyterhub.auth.Authenticator'
|
||||
c.Authenticator.whitelist = {'alpha', 'beta', 'gamma'}
|
||||
|
@@ -1,13 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
TMPDIR=$(mktemp -d)
|
||||
ENVDIR="$TMPDIR/env"
|
||||
|
||||
# start mysql and postgres (do this first, so they have time to startup)
|
||||
for DB in postgres mysql; do
|
||||
export DB
|
||||
bash docker-db.sh
|
||||
done
|
||||
# initialize the databases
|
||||
bash "$(dirname $0)"/init-db.sh
|
||||
|
||||
# create virtualenv with jupyterhub 0.7
|
||||
echo "creating virutalenv in $ENVDIR"
|
||||
@@ -20,16 +18,9 @@ echo "jupyterhub-$(jupyterhub --version)"
|
||||
set -x
|
||||
# launch jupyterhub-0.7 token entrypoint to ensure db is initialized
|
||||
for DB in sqlite postgres mysql; do
|
||||
export $DB
|
||||
export DB
|
||||
echo -e "\n\n\nupgrade-db test: $DB"
|
||||
for i in {1..60}; do
|
||||
if "$ENVDIR/bin/jupyterhub" token alpha; then
|
||||
break
|
||||
else
|
||||
echo "waiting for $DB"
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
"$ENVDIR/bin/jupyterhub" token alpha
|
||||
|
||||
# run upgrade-db
|
||||
jupyterhub upgrade-db
|
||||
@@ -39,5 +30,4 @@ for DB in sqlite postgres mysql; do
|
||||
echo -e "\n\n$DB OK"
|
||||
done
|
||||
|
||||
docker rm -f hub-test-postgres hub-test-mysql
|
||||
rm -rf $ENVDIR
|
||||
rm -rf $ENVDIR
|
||||
|
Reference in New Issue
Block a user