mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-07 18:14:10 +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.
|
instead of the default SQLite backend.
|
||||||
|
|
||||||
### Running Postgres with Jupyterhub on the host.
|
### Running Postgres with Jupyterhub on the host.
|
||||||
0. Replace `ENV JPY_PSQL_PASSWORD arglebargle` with your own password in the
|
0. Uncomment and replace `ENV JPY_PSQL_PASSWORD arglebargle` with your own
|
||||||
Dockerfile for `examples/postgres/db`. (Alternatively you can pass -e
|
password in the Dockerfile for `examples/postgres/db`. (Alternatively, pass
|
||||||
`JPY_PSQL_PASSWORD=<password>` when you start the db container.)
|
-e `JPY_PSQL_PASSWORD=<password>` when you start the db container.)
|
||||||
|
|
||||||
1. `cd` to the root of your jupyterhub repo.
|
1. `cd` to the root of your jupyterhub repo.
|
||||||
|
|
||||||
@@ -21,26 +21,27 @@ instead of the default SQLite backend.
|
|||||||
4. Run jupyterhub with
|
4. Run jupyterhub with
|
||||||
`jupyterhub --db=postgresql://jupyterhub:<password>@localhost:5433/jupyterhub`.
|
`jupyterhub --db=postgresql://jupyterhub:<password>@localhost:5433/jupyterhub`.
|
||||||
|
|
||||||
### Running Postgres with Containerized Jupyterhub.
|
5. Log in as the user running jupyterhub on your host machine.
|
||||||
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.)
|
|
||||||
|
|
||||||
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.
|
for `JPY_PSQL_PASSWORD` match for the hub and db containers.
|
||||||
|
|
||||||
2. Build the hub image with `docker build -t jupyterhub-postgres-db
|
1. Build the hub image with `docker build -t jupyterhub-postgres-hub
|
||||||
examples/postgres/db`. This may take a minute or two the first time it's run.
|
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-postgres`. Note that, unlike when connecting to a host machine
|
||||||
jupyterhub, we don't specify a port-forwarding scheme here, but we do need
|
jupyterhub, we don't specify a port-forwarding scheme here, but we do need
|
||||||
to specify a name for the container.
|
to specify a name for the container.
|
||||||
|
|
||||||
4. Run the containerized hub with `docker run -it --link jpy-db:postgres
|
3. Run the containerized hub with `docker run -it --link jpy-db:postgres
|
||||||
jupyterhub-postgres-hub`.
|
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
|
Dockerfile. By default `rhea` is the server's admin user, `io` and
|
||||||
`ganymede` are non-admin users, and all users' passwords are their
|
`ganymede` are non-admin users, and all users' passwords are their
|
||||||
usernames.
|
usernames.
|
||||||
|
@@ -6,5 +6,5 @@ RUN mkdir /docker-entrypoint-initdb.d
|
|||||||
# startup, prior to the the database being started.
|
# startup, prior to the the database being started.
|
||||||
COPY initdb.sh /docker-entrypoint-initdb.d/init.sh
|
COPY initdb.sh /docker-entrypoint-initdb.d/init.sh
|
||||||
|
|
||||||
# Replace this with your own password.
|
# Uncomment and replace this with your own password.
|
||||||
ENV JPY_PSQL_PASSWORD arglebargle
|
# ENV JPY_PSQL_PASSWORD arglebargle
|
||||||
|
@@ -1,5 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/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.
|
# Start a postgres daemon, ignoring log output.
|
||||||
gosu postgres pg_ctl start -w -l /dev/null
|
gosu postgres pg_ctl start -w -l /dev/null
|
||||||
|
|
||||||
|
@@ -7,9 +7,6 @@ RUN apt-get install -y libpq-dev \
|
|||||||
&& apt-get clean -y \
|
&& apt-get clean -y \
|
||||||
&& pip3 install psycopg2
|
&& 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 useradd -m -G shadow -p $(openssl passwd -1 rhea) rhea
|
||||||
RUN chown rhea .
|
RUN chown rhea .
|
||||||
|
|
||||||
|
@@ -6,9 +6,10 @@ c = get_config()
|
|||||||
c.JupyterHubApp.admin_users = {'rhea'}
|
c.JupyterHubApp.admin_users = {'rhea'}
|
||||||
c.Authenticator.whitelist = {'ganymede', 'io', '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;
|
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')
|
pg_host = os.getenv('POSTGRES_PORT_5432_TCP_ADDR')
|
||||||
c.JupyterHubApp.db_url = 'postgresql://jupyterhub:{}@{}:5432/jupyterhub'.format(
|
c.JupyterHubApp.db_url = 'postgresql://jupyterhub:{}@{}:5432/jupyterhub'.format(
|
||||||
pg_pass,
|
pg_pass,
|
||||||
|
Reference in New Issue
Block a user