Skip to content

Commit

Permalink
Use correct ServerApp options in examples and tests (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbunnyru committed Jul 26, 2023
1 parent 75ca54d commit bfe5f20
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 31 deletions.
12 changes: 6 additions & 6 deletions docs/using/common.md
Expand Up @@ -11,19 +11,19 @@ This page describes the options supported by the startup script and how to bypas
You can pass [Jupyter server options](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html) to the `start-notebook.sh` script when launching the container.

1. For example, to secure the Notebook server with a [custom password](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html#preparing-a-hashed-password)
hashed using `jupyter_server.auth.security.passwd()` instead of the default token,
hashed using `jupyter_server.auth.passwd()` instead of the default token,
you can run the following (this hash was generated for the `my-password` password):

```bash
docker run -it --rm -p 8888:8888 jupyter/base-notebook \
start-notebook.sh --NotebookApp.password='argon2:$argon2id$v=19$m=10240,t=10,p=8$JdAN3fe9J45NvK/EPuGCvA$O/tbxglbwRpOFuBNTYrymAEH6370Q2z+eS1eF4GM6Do'
start-notebook.sh --PasswordIdentityProvider.hashed_password='argon2:$argon2id$v=19$m=10240,t=10,p=8$JdAN3fe9J45NvK/EPuGCvA$O/tbxglbwRpOFuBNTYrymAEH6370Q2z+eS1eF4GM6Do'
```

2. To set the [base URL](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html#running-the-notebook-with-a-customized-url-prefix) of the notebook server, you can run the following:

```bash
docker run -it --rm -p 8888:8888 jupyter/base-notebook \
start-notebook.sh --NotebookApp.base_url=/customized/url/prefix/
start-notebook.sh --ServerApp.base_url=/customized/url/prefix/
```

## Docker Options
Expand Down Expand Up @@ -148,8 +148,8 @@ docker run -it --rm -p 8888:8888 \
-v /some/host/folder:/etc/ssl/notebook \
jupyter/base-notebook \
start-notebook.sh \
--NotebookApp.keyfile=/etc/ssl/notebook/notebook.key \
--NotebookApp.certfile=/etc/ssl/notebook/notebook.crt
--ServerApp.keyfile=/etc/ssl/notebook/notebook.key \
--ServerApp.certfile=/etc/ssl/notebook/notebook.crt
```

Alternatively, you may mount a single PEM file containing both the key and certificate.
Expand All @@ -160,7 +160,7 @@ docker run -it --rm -p 8888:8888 \
-v /some/host/folder/notebook.pem:/etc/ssl/notebook.pem \
jupyter/base-notebook \
start-notebook.sh \
--NotebookApp.certfile=/etc/ssl/notebook.pem
--ServerApp.certfile=/etc/ssl/notebook.pem
```

In either case, Jupyter Notebook expects the key and certificate to be a **base64 encoded text file**.
Expand Down
7 changes: 4 additions & 3 deletions docs/using/recipes.md
Expand Up @@ -475,15 +475,16 @@ For JupyterLab:
```bash
docker run -it --rm \
jupyter/base-notebook:2023-07-25 \
start.sh jupyter lab --LabApp.token=''
start-notebook.sh --IdentityProvider.token=''
```

For jupyter classic:
For Jupyter Notebook:

```bash
docker run -it --rm \
-e DOCKER_STACKS_JUPYTER_CMD=notebook \
jupyter/base-notebook:2023-07-25 \
start.sh jupyter notebook --NotebookApp.token=''
start-notebook.sh --IdentityProvider.token=''
```

## Enable nbclassic-extension spellchecker for markdown (or any other nbclassic-extension)
Expand Down
4 changes: 2 additions & 2 deletions examples/docker-compose/notebook/letsencrypt-notebook.yml
Expand Up @@ -19,8 +19,8 @@ services:
PASSWORD: ${PASSWORD}
command: >
start-notebook.sh
--NotebookApp.certfile=/etc/letsencrypt/fullchain.pem
--NotebookApp.keyfile=/etc/letsencrypt/privkey.pem
--ServerApp.certfile=/etc/letsencrypt/fullchain.pem
--ServerApp.keyfile=/etc/letsencrypt/privkey.pem
volumes:
work:
Expand Down
4 changes: 2 additions & 2 deletions examples/make-deploy/letsencrypt.makefile
Expand Up @@ -52,8 +52,8 @@ letsencrypt-notebook: DOCKER_ARGS:=-e USE_HTTPS=yes \
-e PASSWORD=$(PASSWORD) \
-v $(SECRETS_VOLUME):/etc/letsencrypt
letsencrypt-notebook: ARGS:=\
--NotebookApp.certfile=/etc/letsencrypt/fullchain.pem \
--NotebookApp.keyfile=/etc/letsencrypt/privkey.pem
--ServerApp.certfile=/etc/letsencrypt/fullchain.pem \
--ServerApp.keyfile=/etc/letsencrypt/privkey.pem
letsencrypt-notebook: check
@test -n "$(PASSWORD)" || \
(echo "ERROR: PASSWORD not defined or blank"; exit 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/openshift/templates.json
Expand Up @@ -38,7 +38,7 @@
}
},
"data": {
"jupyter_server_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n import notebook.auth\n c.NotebookApp.password = notebook.auth.passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_server_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
"jupyter_server_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n from jupyter_server.auth import passwd\n c.ServerApp.password = passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_server_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/source-to-image/templates.json
Expand Up @@ -221,7 +221,7 @@
}
},
"data": {
"jupyter_server_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n import notebook.auth\n c.NotebookApp.password = notebook.auth.passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_server_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
"jupyter_server_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n from jupyter_server.auth import passwd\n c.ServerApp.password = passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_server_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions tests/base-notebook/test_container_options.py
Expand Up @@ -16,7 +16,7 @@ def test_cli_args(container: TrackedContainer, http_client: requests.Session) ->
(e.g., disabling token security)"""
host_port = find_free_port()
running_container = container.run_detached(
command=["start-notebook.sh", "--NotebookApp.token=''"],
command=["start-notebook.sh", "--IdentityProvider.token=''"],
ports={"8888/tcp": host_port},
)
resp = http_client.get(f"http://localhost:{host_port}")
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_custom_internal_port(
host_port = find_free_port()
internal_port = env.get("JUPYTER_PORT", 8888)
running_container = container.run_detached(
command=["start-notebook.sh", "--NotebookApp.token=''"],
command=["start-notebook.sh", "--IdentityProvider.token=''"],
environment=env,
ports={internal_port: host_port},
)
Expand Down
16 changes: 8 additions & 8 deletions tests/base-notebook/test_healthcheck.py
Expand Up @@ -22,23 +22,23 @@
(["RESTARTABLE=yes"], None, None),
(["JUPYTER_PORT=8171"], None, None),
(["JUPYTER_PORT=8117", "DOCKER_STACKS_JUPYTER_CMD=notebook"], None, None),
(None, ["start-notebook.sh", "--NotebookApp.base_url=/test"], None),
(None, ["start-notebook.sh", "--NotebookApp.base_url=/test/"], None),
(["GEN_CERT=1"], ["start-notebook.sh", "--NotebookApp.base_url=/test"], None),
(None, ["start-notebook.sh", "--ServerApp.base_url=/test"], None),
(None, ["start-notebook.sh", "--ServerApp.base_url=/test/"], None),
(["GEN_CERT=1"], ["start-notebook.sh", "--ServerApp.base_url=/test"], None),
(
["GEN_CERT=1", "JUPYTER_PORT=7891"],
["start-notebook.sh", "--NotebookApp.base_url=/test"],
["start-notebook.sh", "--ServerApp.base_url=/test"],
None,
),
(["NB_USER=testuser", "CHOWN_HOME=1"], None, "root"),
(
["NB_USER=testuser", "CHOWN_HOME=1"],
["start-notebook.sh", "--NotebookApp.base_url=/test"],
["start-notebook.sh", "--ServerApp.base_url=/test"],
"root",
),
(
["NB_USER=testuser", "CHOWN_HOME=1", "JUPYTER_PORT=8123"],
["start-notebook.sh", "--NotebookApp.base_url=/test"],
["start-notebook.sh", "--ServerApp.base_url=/test"],
"root",
),
],
Expand Down Expand Up @@ -75,12 +75,12 @@ def test_health(
(["NB_USER=testuser", "CHOWN_HOME=1"], None, None),
(
["NB_USER=testuser", "CHOWN_HOME=1"],
["start-notebook.sh", "--NotebookApp.base_url=/test"],
["start-notebook.sh", "--ServerApp.base_url=/test"],
None,
),
(
["NB_USER=testuser", "CHOWN_HOME=1", "JUPYTER_PORT=8123"],
["start-notebook.sh", "--NotebookApp.base_url=/test"],
["start-notebook.sh", "--ServerApp.base_url=/test"],
None,
),
],
Expand Down
1 change: 0 additions & 1 deletion tests/base-notebook/test_start_container.py
Expand Up @@ -45,7 +45,6 @@ def test_start_notebook(
running_container = container.run_detached(
tty=True,
environment=env,
command=["start-notebook.sh"],
ports={"8888/tcp": host_port},
)
# sleeping some time to let the server start
Expand Down
7 changes: 2 additions & 5 deletions tests/pluto_check.py
Expand Up @@ -18,11 +18,8 @@ def check_pluto_proxy(
token = secrets.token_hex()
container.run_detached(
command=[
"start.sh",
"jupyter",
"lab",
"--port=8888",
f"--LabApp.token={token}",
"start-notebook.sh",
f"--IdentityProvider.token={token}",
],
ports={"8888/tcp": host_port},
)
Expand Down

0 comments on commit bfe5f20

Please sign in to comment.