mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-07 10:04:07 +00:00
DEV: Use docker links to set password environment variable in the hub.
Also, yell at people if they use the default password.
This commit is contained in:
@@ -4,9 +4,9 @@ This example shows how you can connect Jupyterhub to a Postgres database
|
||||
instead of the default SQLite backend.
|
||||
|
||||
### Running Postgres with Jupyterhub on the host.
|
||||
0. Replace `ENV JPY_PSQL_PASSWORD arglebargle` with your own password in the
|
||||
Dockerfile for `examples/postgres/db`. (Alternatively you can pass -e
|
||||
`JPY_PSQL_PASSWORD=<password>` when you start the db container.)
|
||||
0. Uncomment and replace `ENV JPY_PSQL_PASSWORD arglebargle` with your own
|
||||
password in the Dockerfile for `examples/postgres/db`. (Alternatively, pass
|
||||
-e `JPY_PSQL_PASSWORD=<password>` when you start the db container.)
|
||||
|
||||
1. `cd` to the root of your jupyterhub repo.
|
||||
|
||||
@@ -21,26 +21,27 @@ instead of the default SQLite backend.
|
||||
4. Run jupyterhub with
|
||||
`jupyterhub --db=postgresql://jupyterhub:<password>@localhost:5433/jupyterhub`.
|
||||
|
||||
### Running Postgres with Containerized Jupyterhub.
|
||||
0. Replace `ENV JPY_PSQL_PASSWORD arglebargle` with your own password in the
|
||||
Dockerfile for `examples/postgres/hub`. (Alternatively you can pass -e
|
||||
`JPY_PSQL_PASSWORD=<password>` when you start the hub container.)
|
||||
5. Log in as the user running jupyterhub on your host machine.
|
||||
|
||||
1. Do steps 0-2 in from the above section, ensuring that the values set/passed
|
||||
### Running Postgres with Containerized Jupyterhub.
|
||||
0. Do steps 0-2 in from the above section, ensuring that the values set/passed
|
||||
for `JPY_PSQL_PASSWORD` match for the hub and db containers.
|
||||
|
||||
2. Build the hub image with `docker build -t jupyterhub-postgres-db
|
||||
examples/postgres/db`. This may take a minute or two the first time it's run.
|
||||
1. Build the hub image with `docker build -t jupyterhub-postgres-hub
|
||||
examples/postgres/hub`. This may take a minute or two the first time it's
|
||||
run.
|
||||
|
||||
3. Run the db image with `docker run -d --name=jpy-db
|
||||
2. Run the db image with `docker run -d --name=jpy-db
|
||||
jupyterhub-postgres`. Note that, unlike when connecting to a host machine
|
||||
jupyterhub, we don't specify a port-forwarding scheme here, but we do need
|
||||
to specify a name for the container.
|
||||
|
||||
4. Run the containerized hub with `docker run -it --link jpy-db:postgres
|
||||
jupyterhub-postgres-hub`.
|
||||
3. Run the containerized hub with `docker run -it --link jpy-db:postgres
|
||||
jupyterhub-postgres-hub`. This instructs docker to run the hub container
|
||||
with a link to the already-running db container, which will forward
|
||||
environment and connection information from the DB to the hub.
|
||||
|
||||
5. Log in as one of the users defined in the `examples/postgres/hub/`
|
||||
4. Log in as one of the users defined in the `examples/postgres/hub/`
|
||||
Dockerfile. By default `rhea` is the server's admin user, `io` and
|
||||
`ganymede` are non-admin users, and all users' passwords are their
|
||||
usernames.
|
||||
|
@@ -6,5 +6,5 @@ RUN mkdir /docker-entrypoint-initdb.d
|
||||
# startup, prior to the the database being started.
|
||||
COPY initdb.sh /docker-entrypoint-initdb.d/init.sh
|
||||
|
||||
# Replace this with your own password.
|
||||
ENV JPY_PSQL_PASSWORD arglebargle
|
||||
# Uncomment and replace this with your own password.
|
||||
# ENV JPY_PSQL_PASSWORD arglebargle
|
||||
|
@@ -1,5 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "";
|
||||
echo "Running initdb.sh.";
|
||||
if [ -z "$JPY_PSQL_PASSWORD" ]; then
|
||||
echo "Need to set JPY_PSQL_PASSWORD in Dockerfile via command line";
|
||||
exit 1;
|
||||
elif [ "$JPY_PSQL_PASSWORD" == "arglebargle" ]; then
|
||||
echo "WARNING: Running with password!"
|
||||
echo "You are STRONGLY ADVISED to use your own password.";
|
||||
fi
|
||||
echo "";
|
||||
|
||||
# Start a postgres daemon, ignoring log output.
|
||||
gosu postgres pg_ctl start -w -l /dev/null
|
||||
|
||||
|
@@ -7,9 +7,6 @@ RUN apt-get install -y libpq-dev \
|
||||
&& apt-get clean -y \
|
||||
&& pip3 install psycopg2
|
||||
|
||||
# Replace this with your own password.
|
||||
ENV JPY_PSQL_PASSWORD arglebargle
|
||||
|
||||
RUN useradd -m -G shadow -p $(openssl passwd -1 rhea) rhea
|
||||
RUN chown rhea .
|
||||
|
||||
|
@@ -6,9 +6,10 @@ c = get_config()
|
||||
c.JupyterHubApp.admin_users = {'rhea'}
|
||||
c.Authenticator.whitelist = {'ganymede', 'io', 'rhea'}
|
||||
|
||||
# Set up the database url.
|
||||
# These environment variables are automatically supplied by the linked postgres
|
||||
# container.
|
||||
import os;
|
||||
pg_pass = os.getenv('JPY_PSQL_PASSWORD')
|
||||
pg_pass = os.getenv('POSTGRES_ENV_JPY_PSQL_PASSWORD')
|
||||
pg_host = os.getenv('POSTGRES_PORT_5432_TCP_ADDR')
|
||||
c.JupyterHubApp.db_url = 'postgresql://jupyterhub:{}@{}:5432/jupyterhub'.format(
|
||||
pg_pass,
|
||||
|
Reference in New Issue
Block a user