Commit 30e56412 authored by sebastien letort's avatar sebastien letort

Notebook integration

parent f8657c96
#!/bin/bash
CONTAINERS="dev-redis dev-mysql dev-controller dev-ssh dev-django dev-smtpsink dev-registry dev-nginx"
CONTAINERS="dev-redis dev-mysql dev-controller dev-ssh dev-django dev-smtpsink dev-registry dev-nginx dev-jupyterhub"
die()
......
......@@ -157,6 +157,9 @@ class WebappForm(forms.ModelForm):
entrypoint = forms.CharField(label="Entrypoint", label_suffix="",
help_text=mark_safe('This is the <a href="https://allgo.gitlabpages.inria.fr/doc/deploy.html#entrypoint">command executed when allgo runs a job</a> for this app.'),
initial="/home/allgo/entrypoint")
notebook_gitrepo = forms.CharField(label="Notebook repository", label_suffix="",
help_text=mark_safe('git repository URL (https only) publicly available.<br /> This repo should contain a notebook (ipynb file).'),
initial="https://")
owner = forms.CharField(required=False, label="Owner", label_suffix='',
help_text="Username of the new owner of the application. You will immediately loose access to the application.")
tags = TagField(required=False, label_suffix='',
......@@ -187,7 +190,9 @@ class WebappForm(forms.ModelForm):
class Meta:
model = Webapp
fields = ('name', 'description', 'contact', 'entrypoint', 'job_queue', 'private', 'docker_os', 'entrypoint', 'owner', 'tags')
fields = ('name', 'description', 'contact', 'private',
'job_queue', 'notebook_gitrepo',
'docker_os', 'entrypoint', 'owner', 'tags')
class WebappSandboxForm(forms.ModelForm):
......
......@@ -316,6 +316,10 @@ class WebappCreate(ProviderAccessMixin, SuccessMessageMixin, CreateView):
obj.docker_name = slugify(form.cleaned_data['name'])
obj.memory_limit = form.get_memory_limit(self.request)
notebook_field = form.declared_fields['notebook_gitrepo']
if( notebook_field.initial == form.cleaned_data['notebook_gitrepo'] ):
obj.notebook_gitrepo = None
# validate the Webapp record before saving
# (this is a safety measure, do not remove)
# FIXME: currently this raises an exception if the slugify-generated
......
......@@ -126,6 +126,11 @@
</div>
{% endif %}
{{ form.notebook_gitrepo.label_tag }}
<div class="input-group">
{{ form.notebook_gitrepo | add_class:"form-control" }}
</div>
<small class="form-text text-muted">{{ form.notebook_gitrepo.help_text }}</small>
</div><!-- form-group col-md-6 -->
</div>
</div>
......
......@@ -203,6 +203,9 @@
<p class="mt-3">A Jupyter notebook is available to try the application online. You can
launch it <a href="/jupyter?repo={{ webapp.notebook_gitrepo }}" title="Jupyter notebook">using this link</a>.</p>
<p class="small text-muted">If you don't know what Jupyter is, you can <a href="https://jupyter.org/" title="Project Jupyter">visit their website</a>.</p>
<iframe id="jupyterhub"
src="/jupyter?repo={{ webapp.notebook_gitrepo }}"
></iframe>
</div>
{% endif %}
</div>
......
......@@ -2,8 +2,11 @@ import base64
import logging
import config.env
from urllib.parse import urlencode
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse, HttpResponse
from django.shortcuts import redirect
from main.models import User, AllgoUser, Runner
from .tokens import Token
......@@ -21,13 +24,15 @@ def jupyter(request):
token = Token("jupyter")
user = request.user.get_username()
token.claim['upn'] = user
token.claim['atk'] = AllgoUser.objects.get(user=User.objects.get(username=user)).token
token.claim['atk'] = AllgoUser(request.user).token
log.info("Jupyter token %s %s", user, token.claim['atk'])
encoded_token = token.encode_token()
next = "/user/%s/git-pull?" % user + urlencode({'repo': request.GET.get("repo")})
jupyter_url = config.env.ALLGO_JUPYTER_URL
return redirect(jupyter_url + "?" + urlencode({'bearer': encoded_token, "next": next}))
url_redirect = jupyter_url + "?" + urlencode({'bearer': encoded_token, "next": next})
log.info( "jupyter redirect to : " + url_redirect )
return redirect(url_redirect)
def jwt_auth(request):
"""
......
......@@ -41,7 +41,7 @@ services:
ALLGO_DEBUG: "True"
ALLGO_ALLOW_LOCAL_ACCOUNTS: "True"
ALLGO_JUPYTER_URL: "http://0.0.0.0:8000/hub/login"
ALLGO_TOKEN_SIGNING_KEY_PATH: "/certs/server.key"
ALLGO_TOKEN_SIGNING_KEY_PATH: "/vol/ro/certs/tokens.key"
ALLGO_HTTP_SERVER: "django"
ALLGO_EMAIL_BACKEND: "django.core.mail.backends.console.EmailBackend"
......@@ -55,11 +55,14 @@ services:
ports:
- "8000:8000"
volumes:
- "./certs:/certs"
- "/data/dev/django/ro/certs:/certs"
- "./jupyterhub/jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py"
- "./jupyterhub/jupyter_notebook_config.py:/etc/jupyter/jupyter_notebook_config.py"
networks: [dev]
environment:
JUPYTERHUB_LOG_LEVEL: "debug"
JUPYTERHUB_JWT_KEY: "/certs/server.key"
JUPYTERHUB_JWT_KEY: "/certs/tokens.key"
# IFRAME_CSP: "http://localhost:8008" # we do not succeed in unsing it.
# REDIS
......
import os
c.NotebookApp.tornado_settings = {
'headers': {
'Content-Security-Policy': "frame-ancestors 'self' http://localhost:8008 "
# 'Content-Security-Policy': "frame-ancestors 'self' %s " % os.environ.get("IFRAME_CSP") #FIXME
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment