GitLab is open source software to collaborate on code (a GitHub clone to run on your own server). Clicking a blob (a file in a repository) in GitLab shows a nice rendering if GitLab supports the file type (e.g., images, Markdown documents), or its content as plain text otherwise. The patch described here adds support to GitLab for rendering IPython notebooks (.ipynb files).
This is a Quick Hack (tm):
- It is slow
- It probably has some security issue
- Basically, don't use this
If you run this on a public production server, bad things will happen.
On the GitLab server:
Note: The following instructions are for GitLab 6.8. Whenever a new version comes out, I'll try to have a branch ready for that version so you can just substitute the current version for 6-8-stable below.
Install GitLab as you normally would with the following changes:
- Clone the GitLab source code from https://github.com/martijnvermaat/gitlabhq.git (instead of https://github.com/gitlabhq/gitlabhq.git)
- Checkout the
6-8-stable-blob-ipython-notebookbranch (instead of6-8-stable)
If you already have a GitLab installation running, follow the usual update guide with the following commands instead of the Get latest code step:
cd /home/git/gitlab
sudo -u git -H git remote add martijnvermaat https://github.com/martijnvermaat/gitlabhq.git
sudo -u git -H git fetch martijnvermaat
sudo -u git -H git checkout 6-8-stable-blob-ipython-notebook
Alternatively, if you know what you're doing or like living on the edge, use branch blob-ipython-notebook, which is based on master. You probably want to rebase on upstream master in that case too.
If needed, all can be disabled by setting ipython_notebook.render to false in config/gitlab.yml.
In the same file, you can specify a custom command for converting notebook files with ipython_notebook.nbconvert. This command should accept an IPython notebook file as its first argument and write an HTML representation to standard output.
The obvious implementation would be to link to or embed the IPython Notebook Viewer. However, GitLab doesn't (yet) make raw file contents available to non-logged-in users (which the IPython Notebook Viewer server would be). And even if it would, GitLab is often used for private repositories where we obviously cannot share the content with a public service.
So this is an alternate implementation, where the notebook file is converted to HTML on the fly by the IPython nbconvert tool. The result is embedded in the GitLab page as an IFrame using a data URI. Rendered notebooks are not cached.

Hi Martijn;
I've been trying to install this in a Docker on top of sameersbn's docker-gitlab. So, I use his image, then follow your instructions for Existing GitLab installation. Then there's a little more magic to get the correct gitlab.yml (because I need all sameer's config changes, plus yours) file, but everything seems to be in place (the six files you've modified are all there), and when I browse to an .ipynb file, I see the extra green View button that wasn't in my omnibus install.
However, if I click on the green button, I get a "raw" display:
It definitely finds a controller, but then reverts to the Raw handler. Unfortunately, I am completely unfamiliar with Ruby. Do you have any idea what I'm missing?