Skip to content

Commit

Permalink
Merge pull request #162 from manics/dev
Browse files Browse the repository at this point in the history
Add example jupyterhub_config.py
  • Loading branch information
manics committed Jun 30, 2024
2 parents 466eadf + 131ec67 commit 3ce3ed2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ dmypy.json

# Pyre type checker
.pyre/

# Other ignores
jupyterhub.sqlite
jupyterhub_cookie_secret
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ For example, this means it can be used as a JupyterHub spawner for BinderHub, wi

### Technical

`subprocess.Popen` is used to make calls to Podman.
`subprocess` is used to make calls to the Podman executable.
See also this [issue](https://github.com/jupyterhub/dockerspawner/issues/360) on
dockerspawner.

## Installation

Via pip:
Install latest release:

pip install podmanclispawner

Install latest development branch:

pip install git+https://github.com/manics/podmanclispawner

Expand All @@ -30,3 +34,8 @@ Via pip:
```python
c.JupyterHub.spawner_class = 'podmancli'
```

For a full example see [`example/jupyterhub_config.py`](example/jupyterhub_config.py):

cd example
jupyterhub -f jupyterhub_config.py
30 changes: 30 additions & 0 deletions example/jupyterhub_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from os import getenv
import socket
from traitlets.config import get_config


def get_host_ip():
"""
Get the IP to connect to the host
If you're using Podman 5+ the default IP will not work, set HOST_IP
a non-default IP:
https://blog.podman.io/2024/03/podman-5-0-breaking-changes-in-detail/
"""
host_ip = getenv("HOST_IP")
if not host_ip:
# IP associated with the default route https://stackoverflow.com/a/28950776
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
# doesn't even have to be reachable
s.connect(("10.255.255.255", 1))
host_ip = s.getsockname()[0]
print(f"Host IP: {host_ip}")
return host_ip


c = get_config()

c.JupyterHub.authenticator_class = "dummy"
c.JupyterHub.hub_connect_ip = get_host_ip()
c.JupyterHub.spawner_class = "podmancli"
c.PodmanCLISpawner.remove = True

0 comments on commit 3ce3ed2

Please sign in to comment.