Installing new packages into JupyterHub itself without PIP_OVERRIDES

We’re deploying JupyterHub with our own custom Authenticator in an extraConfig: section of the helm chart values which relies on a package not installed in the default image. We’ve been building our own image using the PIP_OVERRIDES to install the package but this is a maintenance headache.

I suppose I can maybe run some kind of package install in the extraConfig: section, but is there an official way of specifying that Hub should install extra packages at container startup before starting the Hub code? Or a JupyterHub pre-run section like the pods have?

My overall aim is to have all our site-specific config specified in the, well, config - and not have to maintain forks.

Probably the simplest is to change hub.command to a script that does your preflight and then launches jupyterhub:

hub:
  command:
    - sh
    - "-c"
    - |
      set -ex
      pip install mypackage
      exec jupyterhub --config /usr/local/etc/jupyterhub_config.py

If your script gets big, mounting it as a separate file, then making the command exec your script might be the way to go.

1 Like

That looks great, thank you. I have implemented it in the extraConfig section but that requires a silly dance to update sys.path etc; this looks a lot cleaner.

This seems dangerous if mypackage gets updated and breaks in the future (or is deleted). You won’t have the safety of a good image to use.

1 Like

That’s definitely a consideration, but in our particular case we have full control over the versioning and install known versions via git-ops/flux