And this path and templates must exist in jupyterhub container. There are 2 ways (that I am aware of) to do this. First you can extend the jupyterhub image by copying the templates and use this image in your config. But this means that you have to create a new image everytime you upgrade your jupyterhub. Second way, which I prefer, you can use initContainers, by which you can clone/download your custom templates into a volume and then you can mount this volume into the hub container. Here is an example config for that:
This config clones the repo (https://github.com/your/repo.git, you have to change this with the url of repo where your custom templates are) into /etc/jupyterhub/custom folder, to where the custom-templates volume is mounted. The same volume will be mounted into hub container too (see extraVolumeMounts config). Finally we have to tell jupyterhub where to find custom templates, for that we have to set c.JupyterHub.template_paths as mentioned before. For example if your templates exist in jupyterhub/templates folder in your repo, then set it to ['/etc/jupyterhub/custom/jupyterhub/templates'] as I did in the example config.
Another perhaps more complicated option is to mount configmaps with the template files, the benefit is that you don’t need to have an init container do stuff but instead mounts things directly assuming you have these files available on helm upgrade etc and some additional configuration work.
To use this approach, do something like below. Note that this is a WIKI post allowing you to edit it if you find something to correct or add, please feel free to do so!
use a custom helm chart that requires the jupyterhub helm chart
add some template files in a local folder alongside helm chart configuration files
spawn.html - In the helm chart that has a requirements.yaml declaring jupyterhub as a dependency, this file could for example be added in files/etc/jupyterhub/templates/. Note that it references an image in /hub/static/external/my-custom-image.svg, this needs also to be mounted for use and that is done if you place it within files/static/external/ assuming the use of the configmaps presented in this example.
The question I asked myself was what content would the webserver that JupyterHub use try to serve if we wrote that? I figured out by some testing and source code inspection, that something within a HTML reference to /hub will map to content on a hard drive where JupyterHub’s data_files_path is configured to point to. I did not reconfigure this location but instead used the default value, which was /usr/local/share/jupyterhub/, and placed a folder of stuff within it using a ConfigMap.
Making extraConfig a dictionary of key value pairs allows extraConfig information from one file to be merged with another better. This could be useful if you have two config.yaml files, one for example being secret-config.yaml, and one being non-secret-config.yaml, and both wanted to add some extraConfig. If both these files had written a string value to extraConfig like we actually do using the | symbol in the YAML syntax, they would override instead of merge in a meaningful way. By introducing a key/value pair in between we can avoid this. That is the only purpose it serves though, so you can name it whatever you like. When the configuration snippets is executed listed under extraConfig, it will be done so in an alphabetical order based on the key name.
print("will execute first")
print("PS: this is Python")
print("will execute second")
I also tried @consideRatio’s solution with slightly different folder paths and reached a similar problem (although I may have botched the helm install of the chart, will try again soon). So it’s most likely a problem on my end?
There are some extra spaces in hub.initContainers.args (after clone command). Actually this should make git-clone-templates container fail and hub shouldn’t start at all. And also with that config you should set c.JupyterHub.template_paths to ['/etc/jupyterhub/custom']. Here is updated version of your config:
My bad, I initially wrote c.JupyterHub.template_paths = ['/etc/jupyterhub/custom']; I changed it to c.JupyterHub.template_paths = ['/etc/jupyterhub/custom/jupyterhub/templates'] while trying to debug. The extra spaces might have come from me copying from a backup file that wasn’t .yaml.
I tried using your config, nothing seems to be in /etc/jupyterhub/custom in the hub- pod still.
The custom folder seems to be mounted (although I’m not sure if that’s the right location):