Skip to content

Commit

Permalink
Merge pull request elasticdeeplearning#5 from typhoonzero/develop
Browse files Browse the repository at this point in the history
Run notebook in web page
  • Loading branch information
typhoonzero committed May 3, 2017
2 parents c2c1bb1 + 6a8bd2e commit ad3da5a
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 169 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.Python
*.crt
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
# {{ project_name }}
# PaddlePaddle Cloud

## Getting Started

### Pre-Requirements
- PaddlePaddle Cloud needs python to support `OPENSSL 1.2`. To check it out, simply run:
```python
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2k 26 Jan 2017'
```
- Make sure you have `Python > 2.7.10` installed.

### Run on kubernetes
```bash
# build docker image
git clone https://github.com/PaddlePaddle/cloud.git
cd cloud/paddlecloud
docker build -t [your_docker_registry]/pcloud .
docker push [your_docker_registry]/pcloud
# submit to kubernetes
kubectl create -f ./k8s
```

To test or visit the web site, find out the kubernetes [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) ip addresses, and bind it to your `/etc/hosts` file:
```
# your ingress ip address
192.168.1.100 cloud.paddlepaddle.org
```

Then open your browser and visit http://cloud.paddlepaddle.org.

### Run locally
Make sure you are using a virtual environment of some sort (e.g. `virtualenv` or
`pyenv`).
```
virtualenv paddlecloudenv
# enable the virtualenv
source paddlecloudenv/bin/activate
```

To run for the first time, you need to:
```
npm install
pip install -r requirements.txt
Expand All @@ -13,4 +48,10 @@ pip install -r requirements.txt
npm run dev
```

Browse to http://localhost:3000/
Browse to http://localhost:8000/

If you are starting the server for the second time, just run:
```
./manage.py runserver
```

8 changes: 8 additions & 0 deletions paddlecloud/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:2.7.13-alpine
RUN apk add --update nodejs openssl

ADD requirements.txt package.json /pcloud/
RUN cd /pcloud && npm install && pip install -r requirements.txt && npm build
WORKDIR /pcloud

CMD ["sh", "-c", "./manage.py migrate; ./manage.py loaddata sites; npm run dev"]
18 changes: 0 additions & 18 deletions paddlecloud/ca.crt

This file was deleted.

24 changes: 24 additions & 0 deletions paddlecloud/k8s/cloud_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: paddle-cloud
spec:
replicas: 1
template:
metadata:
labels:
app: paddle-cloud
spec:
volumes:
- name: pcloud-volume
hostPath:
path: "/Users/wuyi/go/src/github.com/typhoonzero/PaddleCloud/paddlecloud"
containers:
- name: paddle-cloud
imagePullPolicy: Always
volumeMounts:
- mountPath: /pcloud
name: pcloud-volume
image: docker.paddlepaddlehub.com/pcloud:latest
ports:
- containerPort: 8000
13 changes: 13 additions & 0 deletions paddlecloud/k8s/cloud_ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: paddle-cloud-ingress
spec:
rules:
- host: cloud.paddlepaddle.org
http:
paths:
- path: /
backend:
serviceName: paddle-cloud-service
servicePort: 8000
11 changes: 11 additions & 0 deletions paddlecloud/k8s/cloud_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Service
apiVersion: v1
metadata:
name: paddle-cloud-service
spec:
selector:
app: paddle-cloud
ports:
- protocol: TCP
port: 8000
targetPort: 8000
10 changes: 9 additions & 1 deletion paddlecloud/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ server {
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;

location ~ ^/notebook/([a-z0-9]+) {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.64.2:80;
}

location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://172.20.166.33:8000/;
proxy_pass http://172.20.166.33:8000;
}
}

Expand Down
10 changes: 10 additions & 0 deletions paddlecloud/notebook/frame_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class NotebookMiddleware:

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)
response["Content-Security-Policy"] = "frame-ancestors 'self' http://notebook.paddlepaddle.org"
response["X-Frame-Options"] = "ALLOW-FROM http://notebook.paddlepaddle.org"
return response
15 changes: 11 additions & 4 deletions paddlecloud/notebook/templates/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
{% block body_class %}home{% endblock %}

{% block body_base %}
<div class="container">
<iframe src="http://notebook.paddlepaddle.org/" width="100%" height="768" style="border:none;"></iframe>
</div>
{{ notebook_id }}
<script>
$(document).ready(function(){
$(window).resize(function(){
$(".fullheight").height($(document).height());
});
});
</script>

<div class="container fullheight">
<iframe src="http://cloud.paddlepaddle.org/notebook/{{ notebook_id }}" width="100%" height="500" style="border:none;"></iframe>
</div>

{% endblock %}
7 changes: 4 additions & 3 deletions paddlecloud/notebook/tls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import os
from django.conf import settings

def __check_cert_requirements__(program):
def is_exe(fpath):
Expand Down Expand Up @@ -29,13 +30,13 @@ def create_user_cert(ca_path, username):
user_cert_cmds = []
user_cert_dir = os.path.join(settings.USER_CERTS_PATH, username)
user_cert_cmds.append("mkdir -p %s" % user_cert_dir)
user_cert_cmd.append("openssl genrsa -out \
user_cert_cmds.append("openssl genrsa -out \
%s/%s-key.pem 2048"%(user_cert_dir, username))
user_cert_cmd.append("openssl req -new -key %s/%s-key.pem -out\
user_cert_cmds.append("openssl req -new -key %s/%s-key.pem -out\
%s/%s.csr -subj \"/CN=%s\""%\
(user_cert_dir, username,
user_cert_dir, username, username))
user_cert_cmd.append("openssl x509 -req -in %s/%s.csr -CA %s -CAkey %s \
user_cert_cmds.append("openssl x509 -req -in %s/%s.csr -CA %s -CAkey %s \
-CAcreateserial -out %s/%s.pem -days 365"% \
(user_cert_dir, username,
settings.CA_PATH, settings.CA_KEY_PATH,
Expand Down
Loading

0 comments on commit ad3da5a

Please sign in to comment.