Skip to content

Commit cb71dfc

Browse files
authored
Merge pull request #132 from MetaCell/feature/131
Feature/131
2 parents baa3f8a + 71b93fd commit cb71dfc

14 files changed

Lines changed: 1444 additions & 14 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ before_script:
4444
- export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
4545

4646
script:
47-
- travis_retry docker build -t="netpyne-ui" --build-arg netpyneuiBranch=$TRAVIS_BRANCH -f="./Dockerfile_dev" .
47+
- travis_retry docker build -t="netpyne-ui" --build-arg branch=$TRAVIS_BRANCH -f="./Dockerfile_dev" .
4848
- travis_retry docker run -t -dit --name=netpyne-ui_container -h localhost -p 8888:8888 netpyne-ui:latest
4949
- cd $TRAVIS_BUILD_DIR/ && ls
5050
- cd geppetto-netpyne && ls

Dockerfile_dev

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
FROM frodriguez4600/jupyter-neuron:latest
33
USER $NB_USER
44

5-
ARG netpyneuiBranch=development
6-
ENV netpyneuiBranch=${netpyneuiBranch}
7-
RUN echo "$netpyneuiBranch";
5+
ARG branch=development
6+
RUN echo "$branch";
87

9-
ENV FOLDER=NetPyNE-UI
8+
ENV INSTALATION_FOLDER=/home/jovyan/work/NetPyNE-UI
109
WORKDIR /home/jovyan/work
1110

1211
COPY --chown=1000:1000 . NetPyNE-UI
13-
WORKDIR ${FOLDER}/utilities
12+
WORKDIR ${INSTALATION_FOLDER}/utilities
1413

15-
RUN python install.py branch $netpyneuiBranch
14+
RUN python install.py branch $branch
1615

17-
WORKDIR /home/jovyan/work/NetPyNE-UI
16+
WORKDIR ${INSTALATION_FOLDER}
1817

1918
RUN git clone https://github.com/Neurosim-lab/netpyne_workspace && rm -rf netpyne_workspace/.git
20-
WORKDIR /home/jovyan/work/NetPyNE-UI/netpyne_workspace
2119

22-
RUN ln -sfn /home/jovyan/work/NetPyNE-UI/netpyne_ui/tests ../tests
23-
CMD /bin/bash -c "cd .. && NetPyNE-UI"
20+
RUN ln -sfn ${INSTALATION_FOLDER}/netpyne_ui/tests ${INSTALATION_FOLDER}/tests
21+
CMD /bin/bash -c "jupyter notebook --NotebookApp.default_url=/geppetto --NotebookApp.token='' --library=netpyne_ui --NotebookApp.disable_check_xsrf=True"

k8s/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM jupyterhub/k8s-hub:0.9.0-beta.4
2+
3+
COPY --chown=1000:1000 templates/page.html /usr/local/share/jupyterhub/templates/page.html
4+
COPY --chown=1000:1000 templates/404.html /usr/local/share/jupyterhub/templates/404.html
5+
COPY --chown=1000:1000 templates/spawn_pending.html /usr/local/share/jupyterhub/templates/spawn_pending.html
6+
COPY --chown=1000:1000 static/jupyter.png /usr/local/share/jupyterhub/static/images/jupyter.png
7+
COPY --chown=1000:1000 static/jupyter.png /usr/local/share/jupyterhub/static/images/jupyterhub-80.png
8+
COPY --chown=1000:1000 static/favicon.ico /usr/local/share/jupyterhub/static/favicon.ico
9+
COPY --chown=1000:1000 static/favicon.ico /usr/local/share/jupyterhub/static/images/favicon.ico
10+
COPY --chown=1000:1000 auth.py /usr/local/lib/python3.6/dist-packages/tmpauthenticator/__init__.py
11+
COPY --chown=1000:1000 js/EventSource.js /usr/local/share/jupyterhub/static/js/EventSource.js
12+
13+
14+
CMD ["jupyterhub", "--config", "/srv/jupyterhub_config.py"]

k8s/auth.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import uuid
2+
3+
from traitlets import Bool
4+
from tornado import gen
5+
6+
from jupyterhub.auth import Authenticator
7+
from jupyterhub.handlers import BaseHandler
8+
from jupyterhub.utils import url_path_join
9+
10+
11+
class TmpAuthenticateHandler(BaseHandler):
12+
def initialize(self, force_new_server, process_user):
13+
super().initialize()
14+
self.force_new_server = force_new_server
15+
self.process_user = process_user
16+
17+
@gen.coroutine
18+
def get(self):
19+
20+
raw_user = yield self.get_current_user()
21+
22+
if raw_user:
23+
if self.force_new_server and raw_user.running:
24+
status = yield raw_user.spawner.poll_and_notify()
25+
if status is None:
26+
yield self.stop_single_user(raw_user)
27+
28+
else:
29+
username = str(uuid.uuid4())
30+
raw_user = self.user_from_username(username)
31+
self.set_login_cookie(raw_user)
32+
33+
user = yield gen.maybe_future(self.process_user(raw_user, self))
34+
35+
server_name = ''
36+
redirection = self.get_next_url(user)
37+
user.spawners[server_name].environment["NETPYNE_URL"] = ''
38+
39+
if 'hub/new-server=' in self.request.uri:
40+
server_name = str(uuid.uuid4()).split('-').pop()
41+
redirection = f'/hub/spawn/{user.name}/{server_name}'
42+
user.spawners[server_name].environment["NETPYNE_URL"] = self.request.uri.split('=').pop()
43+
44+
self.redirect(redirection)
45+
46+
47+
class TmpAuthenticator(Authenticator):
48+
auto_login = True
49+
login_service = 'tmp'
50+
51+
force_new_server = Bool(
52+
False,
53+
help="""
54+
Stop the user's server and start a new one when visiting /hub/tmplogin
55+
When set to True, users going to /hub/tmplogin will *always* get a
56+
new single-user server. When set to False, they'll be
57+
redirected to their current session if one exists.
58+
""",
59+
config=True
60+
)
61+
62+
def process_user(self, user, handler):
63+
return user
64+
65+
def get_handlers(self, app):
66+
# FIXME: How to do this better?
67+
extra_settings = {
68+
'force_new_server': self.force_new_server,
69+
'process_user': self.process_user
70+
}
71+
return [
72+
('/tmplogin.*', TmpAuthenticateHandler, extra_settings),
73+
('/new-server=.*', TmpAuthenticateHandler, extra_settings)
74+
]
75+
76+
def login_url(self, base_url):
77+
return url_path_join(base_url, 'tmplogin')

k8s/cf.yaml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
version: "1.0"
2+
stages:
3+
- "clone"
4+
- "build"
5+
- "deploy"
6+
steps:
7+
main_clone:
8+
type: "git-clone"
9+
description: "Cloning main repository..."
10+
repo: "MetaCell/NetPyNE-UI"
11+
revision: "${{CF_BRANCH}}"
12+
stage: "clone"
13+
when:
14+
branch:
15+
only:
16+
- "${{CF_BRANCH}}"
17+
BuildingNetPyNE-UI:
18+
title: Building NetPyNE-UI
19+
type: build
20+
stage: build
21+
image_name: netpyne-ui
22+
working_directory: ./
23+
tag: '${{CF_SHORT_REVISION}}-${{CF_BUILD_TIMESTAMP}}'
24+
build_arguments:
25+
- branch=${{CF_BRANCH}}
26+
dockerfile: Dockerfile_dev
27+
when:
28+
branch:
29+
only:
30+
- "${{CF_BRANCH}}"
31+
BuildingHub:
32+
title: Building Hub
33+
type: build
34+
stage: "build"
35+
image_name: netpyne-hub
36+
working_directory: ./k8s/
37+
tag: '${{CF_SHORT_REVISION}}-${{CF_BUILD_TIMESTAMP}}'
38+
dockerfile: Dockerfile
39+
when:
40+
branch:
41+
only:
42+
- "${{CF_BRANCH}}"
43+
installing_chart:
44+
create_file:
45+
path: /codefresh/volume/cf-generated
46+
name: values.yaml
47+
content: |
48+
hub:
49+
image:
50+
name: r.cfcr.io/${{ACCOUNT}}/netpyne-hub
51+
tag: '${{CF_SHORT_REVISION}}-${{CF_BUILD_TIMESTAMP}}'
52+
pullPolicy: IfNotPresent
53+
54+
imagePullSecret:
55+
enabled: true
56+
registry: r.cfcr.io
57+
username: ${{ACCOUNT}}
58+
email: null
59+
password: ${{PASSWORD}}
60+
61+
resources:
62+
requests:
63+
cpu: 200m
64+
memory: 512Mi
65+
66+
allowNamedServers: true
67+
namedServerLimitPerUser: 2
68+
shutdownOnLogout: true
69+
70+
extraConfig:
71+
timing: |
72+
c.JupyterHub.allow_named_servers = True
73+
c.Spawner.port = 8000
74+
c.Spawner.http_timeout = 300
75+
c.Spawner.start_timeout = 300
76+
c.Spawner.notebook_dir = '/home/jovyan/work/NetPyNE-UI'
77+
c.Spawner.default_url = '/geppetto'
78+
c.Spawner.debug = True
79+
spawner: >-
80+
c.Spawner.args = ["--library=netpyne_ui"]
81+
82+
scheduling:
83+
userScheduler:
84+
replicas: 1
85+
86+
proxy:
87+
secretToken: ${{SECRET_TOKEN}}
88+
89+
auth:
90+
type: tmp
91+
92+
singleuser:
93+
storage:
94+
type: none
95+
memory:
96+
guarantee: 0.2G
97+
image:
98+
name: r.cfcr.io/${{ACCOUNT}}/netpyne-ui
99+
tag: '${{CF_SHORT_REVISION}}-${{CF_BUILD_TIMESTAMP}}'
100+
pullPolicy: IfNotPresent
101+
102+
imagePullSecret:
103+
enabled: true
104+
registry: r.cfcr.io
105+
username: ${{ACCOUNT}}
106+
email: null
107+
password: ${{PASSWORD}}
108+
109+
cull:
110+
enabled: true
111+
users: false
112+
removeNamedServers: true
113+
timeout: 360
114+
every: 60
115+
concurrency: 10
116+
maxAge: 0
117+
118+
debug:
119+
enabled: false
120+
image: 'codefresh/cfstep-helm:2.12.1'
121+
title: Installing chart
122+
stage: deploy
123+
environment:
124+
- CHART_NAME=jupyterhub
125+
- RELEASE_NAME={{RELEASE_NAME}}
126+
- KUBE_CONTEXT=geppetto-cluster@metacellllc
127+
- NAMESPACE=netpyne
128+
- TILLER_NAMESPACE=kube-system
129+
- CHART_VERSION=0.9.0-beta.4
130+
- 'CHART_REPO_URL=https://jupyterhub.github.io/helm-chart/'
131+
- VALUESFILE_values=/codefresh/volume/cf-generated/values.yaml
132+
- 'CF_CTX_jupyterhub_helm_URL=https://jupyterhub.github.io/helm-chart/'
133+
- HELM_REPO_USE_HTTP=false
134+
- HELM_REPO_CONTEXT_PATH=
135+
- TIMEOUT=600

0 commit comments

Comments
 (0)