mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 23:42:59 +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
|
#!/usr/bin/env bash
|
||||||
set -e
|
# source this file to setup postgres and mysql
|
||||||
NAME="hub-test-$DB"
|
# for local testing (as similar as possible to docker)
|
||||||
docker rm -f $NAME 2>/dev/null || true
|
|
||||||
|
|
||||||
case $DB in
|
DOCKER="docker run --rm -d --name"
|
||||||
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
|
|
||||||
|
|
||||||
set -x
|
export MYSQL_HOST=127.0.0.1
|
||||||
docker run --rm --name $NAME -d $ARGS
|
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')
|
DB = os.environ.get('DB')
|
||||||
if DB == 'mysql':
|
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':
|
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.JupyterHub.authenticator_class = 'jupyterhub.auth.Authenticator'
|
||||||
c.Authenticator.whitelist = {'alpha', 'beta', 'gamma'}
|
c.Authenticator.whitelist = {'alpha', 'beta', 'gamma'}
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
TMPDIR=$(mktemp -d)
|
TMPDIR=$(mktemp -d)
|
||||||
ENVDIR="$TMPDIR/env"
|
ENVDIR="$TMPDIR/env"
|
||||||
|
|
||||||
# start mysql and postgres (do this first, so they have time to startup)
|
# initialize the databases
|
||||||
for DB in postgres mysql; do
|
bash "$(dirname $0)"/init-db.sh
|
||||||
export DB
|
|
||||||
bash docker-db.sh
|
|
||||||
done
|
|
||||||
|
|
||||||
# create virtualenv with jupyterhub 0.7
|
# create virtualenv with jupyterhub 0.7
|
||||||
echo "creating virutalenv in $ENVDIR"
|
echo "creating virutalenv in $ENVDIR"
|
||||||
@@ -20,16 +18,9 @@ echo "jupyterhub-$(jupyterhub --version)"
|
|||||||
set -x
|
set -x
|
||||||
# launch jupyterhub-0.7 token entrypoint to ensure db is initialized
|
# launch jupyterhub-0.7 token entrypoint to ensure db is initialized
|
||||||
for DB in sqlite postgres mysql; do
|
for DB in sqlite postgres mysql; do
|
||||||
export $DB
|
export DB
|
||||||
echo -e "\n\n\nupgrade-db test: $DB"
|
echo -e "\n\n\nupgrade-db test: $DB"
|
||||||
for i in {1..60}; do
|
"$ENVDIR/bin/jupyterhub" token alpha
|
||||||
if "$ENVDIR/bin/jupyterhub" token alpha; then
|
|
||||||
break
|
|
||||||
else
|
|
||||||
echo "waiting for $DB"
|
|
||||||
sleep 2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# run upgrade-db
|
# run upgrade-db
|
||||||
jupyterhub upgrade-db
|
jupyterhub upgrade-db
|
||||||
@@ -39,5 +30,4 @@ for DB in sqlite postgres mysql; do
|
|||||||
echo -e "\n\n$DB OK"
|
echo -e "\n\n$DB OK"
|
||||||
done
|
done
|
||||||
|
|
||||||
docker rm -f hub-test-postgres hub-test-mysql
|
rm -rf $ENVDIR
|
||||||
rm -rf $ENVDIR
|
|
||||||
|
Reference in New Issue
Block a user