---
# System prepended metadata

title: Plom orchestration

---

Plom orchestration
==================

Background
----------

1. Central DB server, total commodity MariaDB Docker image for example
  - I think one should scale to hundreds of servers.

2. Storage
  - this should be the main cost.  Files last around a month, many instructors will want longer (regrades, etc).
  - Big calc course is maybe 50GiB
  - shorttime: mount persistent storage using docker mount points
  - longer term: s3 bucket?
  - cheap dream: optionally use each course's OneDrive resources as a bucket

3. Servers
  - each server is a self-contained docker image
  - each server will be Django (currently custom AIOHttp)
  - each server talks to clients via a unique address + port
  - longer term: we could envision TAs logging into central server
    that proxies all requests (maybe "Traefik?")
    
  
Hub plan
--------

A = launch_new_container("name", port=41991, data_store=...)

A.get_idle_time()

A.stop()   # now I'm not paying for CPU

A.restart()   # now I'm paying again

When I "just" need a webapp that:
  - allows Instructors to login
  - when they click a button, we start a new server
  - if its idle for say 24 hours, they need to login again and restart it
  
  
Future problems
---------------

TAs need to be able to wake the server too, then we can decrease the idle time 


Post-meeting with Ian
=====================

fixed cost: $200 / month for the hub itself (kubernetes running all the time)

suggestion: ignore kubertnes

get on dockerspwaner with jupyter hub


zero-to-jupyterhub?  no, this is kubernets

go straight to juypter hub itself (docswise)

tutorials for using a gateway for other things


- - - - --

proxy sitting in the middle, we cannot (easily) bypass the jupyterhub auth etc, but if we use that auth we get a dict of auth'd users who can access Colin's course.

JupyterHub proxies the containers by default
--------------------------------------------

It takes care of connecting routes from each container

TA auth: launching jupyter hub auth tkoken..

binder: is jyputer  with auth set to zero/dummy

spawners and authenticators: these are very dumb/simple things

turn auth off, can we proxy our app

DummyAuth: turn auth off, our individual containers will do their own auth

slightly better: one could protect the spawn route only, and leave everything else for the app to spawn


Notes
=====

https://jupyterhub-dockerspawner.readthedocs.io/en/latest/docker-image.html

- - - - 

Colin's first steps
-------------------

0. start the docker without starting jupyterhub (just use bash), then use another terminal for JH: easier to restart

2. jupyterhub with docker
inside:
  - apt-get stuff from Plom's Dockerfile
  - pip install plom
  - pip install jupyterlab

2. I tried forwarding ports with docker's `-p 41988:41988`.  this works.

3. But better: `pip install jupyter-server-proxy`.  This is used for RStudio or R's Shiny...  This sounds cool:

    >  You can also set c.Spawner.default_url to /proxy/8080
    >  to have users be shown to your application directly after logging
    >  in - without ever seeing the notebook interface.




I think I have the magic ingredient for doing this with minimal change: `pip install jupyter-server-proxy`.  It allows access to arbitrary servers by rewriting incoming routes on special ".../proxy" URIs.

1.  Run a plom-server in the Hub, on port 41999, just in a terminal for example, although the same project lets you make icons.

2.  Consider this URI from outside the hub:
    http://127.0.0.1:8000/user/cbm/proxy/41999/info/spec

3.  The plom-server gets a request on
    localhost:41999/info/spec

I have tested this with `python3 -m http.server`.  It does not yet work with plom-server because our legacy server does not speak HTTP (only HTTPS).  The upcoming Django server fixes that.

Also PlomClient would need to accept more general base-url, like:

hub.example.com:8000/user/cbm/proxy/41999

instead of

plom.example.com:41999

I believe that is an easy fix for the client. 


talk: https://www.youtube.com/watch?v=8tFLZWT0u2Y


Run plom django inside the Hub, need to hack demo.sh to:
`python3 manage.py runserver 6789`
(otherwise it runs on 8000)

Then use: 
