Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.

Commit bfe3faa

Browse files
authored
chore: First commit (#1)
1 parent 0fb96f0 commit bfe3faa

File tree

8 files changed

+213
-1
lines changed

8 files changed

+213
-1
lines changed

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.conda/
2+
.config
3+
.bash_history
4+
.local
5+
.npm
6+
node_modules
7+
*~
8+
*.py[co]
9+
.cache
10+
.coverage
11+
.coverage.*
12+
.DS_Store
13+
*.egg-info
14+
.env
15+
.idea/
16+
*.ipynb
17+
.ipynb_checkpoints
18+
*.pid
19+
.pytest_cache
20+
*.retry
21+
.vim/
22+
.vscode
23+
.yarn
24+
hosts.*
25+
dist
26+
docs/_build
27+
docs/build
28+
docs/source/_static/rest-api
29+
grades-sender.lock
30+
hosts
31+
htmlcov
32+
jupyterhub_cookie_secret
33+
jupyterhub.sqlite
34+
MANIFEST
35+
pip-wheel-metadata
36+
*pycache*
37+
secrets
38+
share/jupyterhub/static/components
39+
share/jupyterhub/static/css/style.min.css
40+
share/jupyterhub/static/css/style.min.css.map
41+
src/build*
42+
venv

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM jupyter/minimal-notebook:latest
2+
3+
USER root
4+
RUN apt-get update \
5+
&& apt-get install -y \
6+
curl \
7+
unzip \
8+
wget
9+
10+
# install pgweb
11+
ENV PGWEB_VERSION=0.11.6
12+
RUN wget -q "https://github.com/sosedoff/pgweb/releases/download/v${PGWEB_VERSION}/pgweb_linux_amd64.zip" \
13+
&& unzip pgweb_linux_amd64.zip -d /usr/bin \
14+
&& mv /usr/bin/pgweb_linux_amd64 /usr/bin/pgweb
15+
16+
# setup package, enable classic extension, build lab extension
17+
USER "${NB_USER}"
18+
COPY . "${HOME}"/
19+
COPY requirements.txt "${HOME}"/
20+
WORKDIR "${HOME}"
21+
RUN python3 -m pip install .
22+
RUN python3 -m pip install -r requirements.txt \
23+
&& jupyter serverextension enable --sys-prefix jupyter_server_proxy \
24+
&& jupyter labextension install @jupyterlab/server-proxy \
25+
&& jupyter lab build
26+
27+
# copy configs, update permissions as root
28+
USER root
29+
RUN fix-permissions /etc/jupyter
30+
31+
USER "${NB_USER}"

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
11
# jupyter-pgweb-proxy
2-
Jupyter server proxy w/ pgweb
2+
3+
This package was built using the [`illumidesk/jupyter-server-proxy` cookiecutter template](https://github.com/illumidesk/cookiecutter-jupyter-server-proxy).
4+
5+
## Requirements
6+
7+
- Python 3.6+
8+
- Jupyter Notebook 6.0+
9+
- JupyterLab 2.1+
10+
11+
This package executes the standard `pgweb` command. This command assumes the `pgweb` command is available in the environment's `PATH`.
12+
13+
### Install jupyter-pgweb-proxy
14+
15+
Install the package with pip:
16+
17+
```
18+
pip install git+https://github.com/illumidesk/jupyter-pgweb-proxy.git
19+
```
20+
21+
## Example
22+
23+
Try with binder:
24+
25+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/illumidesk/jupyter-pgweb-proxy/main?urlpath=pgweb)
26+
27+
Test locally:
28+
29+
```bash
30+
docker build -t jupyter/pgweb .
31+
docker build -it --rm -p 8888:8888 jupyter/pgweb
32+
```
33+
34+
## Credits
35+
36+
- [`jupyter-server-proxy`](https://github.com/jupyterhub/jupyter-server-proxy)
37+
38+
## License
39+
40+
BSD 3-Clause

jupyter_notebook_config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
c = get_config()
2+
3+
4+
# load base config
5+
load_subconfig('/etc/jupyter/jupyter_notebook_config_base.py')
6+
7+
8+
# supports iframe and samesite cookies
9+
c.NotebookApp.tornado_settings = {
10+
"headers": {"Content-Security-Policy": "frame-ancestors 'self' *"},
11+
"cookie_options": {"SameSite": "None", "Secure": True},
12+
}
13+
c.NotebookApp.allow_root = True
14+
c.NotebookApp.allow_origin = '*'
15+
c.NotebookApp.token = ''
16+
c.NotebookApp.default_url = '/lab'

jupyter_pgweb_proxy/__init__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import shutil
3+
import logging
4+
5+
6+
logger = logging.getLogger(__name__)
7+
logger.setLevel('INFO')
8+
9+
10+
def setup_pgweb():
11+
"""Setup commands and icon paths and return a dictionary compatible
12+
with jupyter-server-proxy.
13+
"""
14+
def _get_icon_path():
15+
return os.path.join(
16+
os.path.dirname(os.path.abspath(__file__)), 'icons', 'pgweb.svg'
17+
)
18+
19+
# Make sure executable is in $PATH
20+
def _get_pgweb_command(port):
21+
executable = 'pgweb'
22+
if not shutil.which(executable):
23+
raise FileNotFoundError('Can not find pgweb executable in $PATH')
24+
# Create working directory
25+
home_dir = os.environ.get('HOME') or '/home/jovyan'
26+
working_dir = f'{home_dir}/pgweb'
27+
if not os.path.exists(working_dir):
28+
os.makedirs(working_dir)
29+
logger.info("Created directory %s" % working_dir)
30+
else:
31+
logger.info("Directory %s already exists" % working_dir)
32+
return ['pgweb', '--bind=0.0.0.0', '--listen=' + str(port)]
33+
34+
return {
35+
'command': _get_pgweb_command,
36+
'timeout': 20,
37+
'new_browser_tab': True,
38+
'launcher_entry': {
39+
'title': 'pgweb',
40+
'icon_path': _get_icon_path()
41+
},
42+
}

jupyter_pgweb_proxy/icons/pgweb.svg

Lines changed: 9 additions & 0 deletions
Loading

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jupyter-server-proxy>=1.5.0

setup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import setuptools
2+
from os import path
3+
4+
5+
# read the contents of your README file
6+
this_directory = path.abspath(path.dirname(__file__))
7+
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
8+
long_description = f.read()
9+
10+
11+
setuptools.setup(
12+
name="jupyter-pgweb-proxy",
13+
version='0.1.0',
14+
url="https://github.com/illumidesk/jupyter-pgweb-proxy",
15+
author="IllumiDesk Team",
16+
description="[email protected]",
17+
long_description=long_description,
18+
long_description_content_type='text/markdown',
19+
packages=setuptools.find_packages(),
20+
keywords=['jupyter', 'pgweb', 'jupyterhub'],
21+
classifiers=['Framework :: Jupyter'],
22+
install_requires=[
23+
'jupyter-server-proxy>=1.5.0'
24+
],
25+
entry_points={
26+
'jupyter_serverproxy_servers': [
27+
'pgweb = jupyter_pgweb_proxy:setup_pgweb',
28+
]
29+
},
30+
package_data={
31+
'jupyter_pgweb_proxy': ['icons/pgweb.svg'],
32+
},
33+
)

0 commit comments

Comments
 (0)