|
| 1 | +# Customizing your BinderHub deployment |
| 2 | + |
| 3 | +```{important} |
| 4 | +In this section, we assume that you are deploying BinderHub to Kubernetes using Helm as documented in [](#zero-to-binderhub). |
| 5 | +``` |
| 6 | + |
| 7 | +## Frontend |
| 8 | + |
| 9 | +BinderHub's frontend is built using [React](https://react.dev/). |
| 10 | +We prepared the key parts of the BinderHub's frontend as re-usable components available as [`@jupyterhub/binderhub-react-components` on NPM](https://www.npmjs.com/package/@jupyterhub/binderhub-react-components`). |
| 11 | +Some customization might require changes in the re-usable components or the way the are connected. |
| 12 | + |
| 13 | +### Banner customization |
| 14 | + |
| 15 | +By default BinderHub shows a banner at the top of all pages. You can define the content of the banner by setting the `banner_message` configuration option to the raw HTML you would like to add. |
| 16 | + |
| 17 | +#### Example |
| 18 | + |
| 19 | +The banner was configured at <https://mybinder.org> using `banner_message`: |
| 20 | + |
| 21 | +```{code-block} yaml |
| 22 | +:caption: Snippet from <https://github.com/jupyterhub/mybinder.org-deploy/blob/114ba49335ee3d258654e264b544b67ab270f953/mybinder/values.yaml#L182-L187> |
| 23 | +
|
| 24 | +banner_message: | |
| 25 | + <a class="btn" style="width:fit-content;height:fit-content;padding:10px;background-color:#e66581;color:white;font-weight:bold;position:absolute;right:4px;" |
| 26 | + onmouseover="this.style.backgroundColor='#d15b75'" onmouseout="this.style.backgroundColor='#e66581'" |
| 27 | + href="https://jupyter.org/about#donate" target="_blank"> |
| 28 | + 🤍 Donate to mybinder.org! |
| 29 | + </a> |
| 30 | +``` |
| 31 | + |
| 32 | +### About page customization |
| 33 | + |
| 34 | +BinderHub's frontend is configured with simple about page at `https://BINDERHOST/about`. By default this shows the version of BinderHub you are running. You can add additional HTML to the page by setting the `about_message` configuration option to the raw HTML you would like to add. You can use this to display contact information or other details about your deployment. |
| 35 | + |
| 36 | +#### Example |
| 37 | + |
| 38 | +The about page was configured at <https://mybinder.org/about> using `about_message`: |
| 39 | + |
| 40 | +```{code-block} yaml |
| 41 | +:caption: Snippet from <https://github.com/jupyterhub/mybinder.org-deploy/blob/114ba49335ee3d258654e264b544b67ab270f953/mybinder/values.yaml#L194-L200> |
| 42 | +
|
| 43 | +about_message: | |
| 44 | + <p>mybinder.org is public infrastructure operated by the <a href="https://jupyterhub-team-compass.readthedocs.io/en/latest/team.html#binder-team">Binder Project team</a>.<br /><br /> |
| 45 | + The Binder Project is a member of <a href="https://jupyter.org">Project Jupyter</a>. |
| 46 | + Donations are managed by <a href="https://lf-charities.org">LF Charities</a>, a US 501c3 non-profit.<br /><br /> |
| 47 | + For abuse please email: <a href="mailto:[email protected]">[email protected]</a>, to report a |
| 48 | + security vulnerability please see: <a href="https://mybinder.readthedocs.io/en/latest/faq.html#where-can-i-report-a-security-issue">Where can I report a security issue</a><br /><br /> |
| 49 | + For more information about the Binder Project, see <a href="https://mybinder.readthedocs.io/en/latest/about.html">the About Binder page</a></p> |
| 50 | +``` |
| 51 | + |
| 52 | +### `window.pageConfig` |
| 53 | + |
| 54 | +```{warning} |
| 55 | +This should be used **only** when providing a BinderHub frontend without the BinderHub backend. |
| 56 | +``` |
| 57 | + |
| 58 | +Some customization is **exposed** using the `window.pageConfig` JavaScript variable, including |
| 59 | + |
| 60 | +- `aboutMessage` |
| 61 | +- `badgeBaseUrl` |
| 62 | +- `bannerHtml` |
| 63 | +- `baseUrl` |
| 64 | +- `logoUrl` |
| 65 | +- `logoWidth` |
| 66 | +- `repoProviders` |
| 67 | + |
| 68 | +Change the value of the above keys will change how the BinderHub's frontend works. |
| 69 | + |
| 70 | +### Extra JavaScript |
| 71 | + |
| 72 | +BinderHUb tries to be neutral regarding [web analytics](https://en.wikipedia.org/wiki/Web_analytics). You should be able to configure any web analytics tools using `extra_header_html` and `extra_footer_scripts`. |
| 73 | + |
| 74 | +#### Example |
| 75 | + |
| 76 | +[Plausible](https://plausible.io/) was configured at <https://mybinder.org> using `extra_header_html`: |
| 77 | + |
| 78 | +```{code-block} yaml |
| 79 | +:caption: Snippet from <https://github.com/jupyterhub/mybinder.org-deploy/blob/114ba49335ee3d258654e264b544b67ab270f953/mybinder/values.yaml#L202-L205> |
| 80 | +
|
| 81 | +extra_header_html: |
| 82 | + 01-plausible: | |
| 83 | + <script defer data-domain="mybinder.org" src="https://plausible.io/js/script.file-downloads.outbound-links.js"></script> |
| 84 | + <script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script> |
| 85 | +``` |
| 86 | + |
| 87 | +### Header and Footer customization |
| 88 | + |
| 89 | +BinderHub uses [Jinja](https://jinja.palletsprojects.com/en/stable/) as template engine to process the page template (default is [binderhub/templates/page.html](https://github.com/jupyterhub/binderhub/blob/main/binderhub/templates/page.html)). To add a custom header and footer, |
| 90 | + |
| 91 | +1. copy `binderhub/templates/page.html` into `files/custom-page.html` |
| 92 | + |
| 93 | +2. edit `files/custom-page.html` to include the desired header and footer. For example: |
| 94 | + |
| 95 | + ```html |
| 96 | + <body> |
| 97 | + <header>My Own BinderHub</header> |
| 98 | + <div id="root"></div> |
| 99 | + <footer>Powered by BinderHub</footer> |
| 100 | + </body> |
| 101 | + ``` |
| 102 | + |
| 103 | + It is important to include `<div id="root"></div>` because this is the HTML node that React will use to build the launch form. |
| 104 | + |
| 105 | +3. copy `files/custom-page.html` into `extraFiles` in the Helm configuration file. For example: |
| 106 | + |
| 107 | + ```yaml |
| 108 | + extraFiles: |
| 109 | + custom-page: |
| 110 | + mountPath: files/custom-page.html |
| 111 | + stringData: | |
| 112 | + ... |
| 113 | + <body> |
| 114 | + <header> |
| 115 | + My Own BinderHub |
| 116 | + </header> |
| 117 | + <div id="root"></div> |
| 118 | + <footer> |
| 119 | + Powered by BinderHub |
| 120 | + </footer> |
| 121 | + </body> |
| 122 | + ... |
| 123 | + ``` |
| 124 | + |
| 125 | +4. change `template_file` in the Helm configuration file. For example: |
| 126 | + |
| 127 | + ```yaml |
| 128 | + config: |
| 129 | + BinderHub: |
| 130 | + template_file: files/custom-page.html |
| 131 | + ``` |
| 132 | + |
| 133 | +## JupyterHub customization |
| 134 | + |
| 135 | +Because BinderHub uses JupyterHub to manage all user sessions, you can customize many aspects of the resources available to the user. This is primarily done by modifications to your BinderHub\'s Helm chart (`config.yaml`). |
| 136 | + |
| 137 | +To make edits to your JupyterHub deplyoment via `config.yaml`, use the following pattern: |
| 138 | + |
| 139 | +```yaml |
| 140 | +binderhub: |
| 141 | + jupyterhub: <JUPYTERHUB-CONFIG-YAML> |
| 142 | +``` |
| 143 | + |
| 144 | +For example, see [this section of the mybinder.org Helm Chart](https://github.com/jupyterhub/mybinder.org-deploy/blob/a7d83838aea24a4f143a2b8630f4347fa722a6b3/mybinder/values.yaml#L192). |
| 145 | + |
| 146 | +For information on how to configure your JupyterHub deployment, see the [JupyterHub for Kubernetes Customization Guide](https://zero-to-jupyterhub.readthedocs.io/en/latest/#customization-guide). |
| 147 | + |
| 148 | +If you want to customise the spawner you can subclass it in `extraConfig`. For example: |
| 149 | + |
| 150 | +```yaml |
| 151 | +binderhub: |
| 152 | + jupyterhub: |
| 153 | + hub: |
| 154 | + extraConfig: |
| 155 | + 10-binder-customisations: | |
| 156 | + class MyCustomBinderSpawner(BinderSpawner): |
| 157 | + ... |
| 158 | +
|
| 159 | + c.JupyterHub.spawner_class = MyCustomBinderSpawner |
| 160 | +``` |
| 161 | +
|
| 162 | +BinderHub uses the [jupyterhub.hub.extraConfig setting](https://zero-to-jupyterhub.readthedocs.io/en/latest/administrator/advanced.html#hub-extraconfig) to customise JupyterHub. For example, `BinderSpawner` is defined under the `00-binder` key. Keys are evaluated in alphanumeric order, so later keys such as `10-binder-customisations` can use objects defined in earlier keys. |
| 163 | + |
| 164 | +(repo-specific-config)= |
| 165 | + |
| 166 | +## Custom configuration for specific repositories |
| 167 | + |
| 168 | +Sometimes you would like to provide a repository-specific configuration. For example, if you\'d like certain repositories to have **higher pod quotas** than others, or if you\'d like to provide certain resources to a subset of repositories. |
| 169 | + |
| 170 | +To override the configuration for a specific repository, you can provide a list of dictionaries that allow you to provide a pattern to match against each repository\'s specification, and override configuration values for any repositories that match this pattern. |
| 171 | + |
| 172 | +```{note} |
| 173 | +If you provide **multiple patterns that match a single repository** in your spec-specific configuration, then **later values in the list will override earlier values**. |
| 174 | +``` |
| 175 | + |
| 176 | +To define this list of patterns and configuration overrides, use the following pattern in your Helm Chart (here we show an example using `GitHubRepoProvider`, but this works for other RepoProviders as well): |
| 177 | + |
| 178 | +```yaml |
| 179 | +config: |
| 180 | + GitHubRepoProvider: |
| 181 | + spec_config: |
| 182 | + - pattern: ^ines/spacy-binder.*: |
| 183 | + config: |
| 184 | + key1: value1 |
| 185 | + - pattern: pattern2 |
| 186 | + config: |
| 187 | + key1: othervalue1 |
| 188 | + key2: othervalue2 |
| 189 | +``` |
| 190 | + |
| 191 | +For example, the following specification configuration will assign a pod quota of 999 to the spacy-binder repository, and a pod quota of 1337 to any repository in the JupyterHub organization. |
| 192 | + |
| 193 | +```yaml |
| 194 | +config: |
| 195 | + GitHubRepoProvider: |
| 196 | + spec_config: |
| 197 | + - pattern: ^ines/spacy-binder.*: |
| 198 | + config: |
| 199 | + quota: 999 |
| 200 | + - pattern: ^jupyterhub.* |
| 201 | + config: |
| 202 | + quota: 1337 |
| 203 | +``` |
| 204 | + |
| 205 | +## Banning specific repositories |
| 206 | + |
| 207 | +You may want to exclude certain repositories from your BinderHub instance. You can do this by providing a list of **banned_spec** patterns. BinderHub will not accept URLs matching any of the banned patterns. |
| 208 | + |
| 209 | +For example, the following configuration will prevent notebooks in the spacy-binder repository and the ml-training repository from launching. |
| 210 | + |
| 211 | +```yaml |
| 212 | +config: |
| 213 | + GitHubRepoProvider: |
| 214 | + # Add banned repositories to the list below |
| 215 | + # They should be strings that will match "^<org-name>/<repo-name>.*" |
| 216 | + banned_specs: |
| 217 | + - ^ines/spacy-binder.* |
| 218 | + - ^aschen/ml-training.* |
| 219 | +``` |
| 220 | + |
| 221 | +You can also use a negative lookahead. For example, the following configuration will prevent all notebooks except those in repositories in the myorg organization from launching. |
| 222 | + |
| 223 | +```yaml |
| 224 | +config: |
| 225 | + GitHubRepoProvider: |
| 226 | + banned_specs: |
| 227 | + - ^(?!myorg\/.*).*$ |
| 228 | +``` |
0 commit comments