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

Commit

Permalink
Feature: JupyterLab plugin (#459)
Browse files Browse the repository at this point in the history
* initial commit

* enable jupyter lab as a default plugin

* remove hack text and add more logging

* remove docker compose code. it is not used yet

* remove unused code and comment
  • Loading branch information
paselem authored Mar 29, 2018
1 parent c1f43c7 commit da61337
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
1 change: 1 addition & 0 deletions aztk/models/plugins/internal/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PluginManager:
# Indexing of all the predefined plugins
plugins = dict(
jupyter=plugins.JupyterPlugin,
jupyterlab=plugins.JupyterLabPlugin,
rstudio_server=plugins.RStudioServerPlugin,
hdfs=plugins.HDFSPlugin,
)
Expand Down
2 changes: 0 additions & 2 deletions aztk/node_scripts/install/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def setup_node():
setup_as_master()
plugins.setup_plugins(is_master=True, is_worker=True)
scripts.run_custom_scripts(is_master=True, is_worker=True)

else:
setup_as_worker()
plugins.setup_plugins(is_master=False, is_worker=True)
Expand All @@ -42,7 +41,6 @@ def setup_as_master():
if os.environ["WORKER_ON_MASTER"] == "True":
spark.start_spark_worker()


def setup_as_worker():
print("Setting up as worker.")
spark.setup_connection()
Expand Down
5 changes: 4 additions & 1 deletion aztk/node_scripts/setup_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
# Usage:
# setup_node.sh [container_name] [gpu_enabled] [docker_repo] [docker_cmd]


container_name=$1
gpu_enabled=$2
repo_name=$3
docker_run_cmd=$4

echo "Installing pre-reqs"
apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual
apt-get -y install apt-transport-https
apt-get -y install curl
apt-get -y install ca-certificates
apt-get -y install software-properties-common
echo "Done installing pre-reqs"

# Install docker
echo "Installing Docker"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update
apt-get -y install docker-ce
echo "Done installing Docker"

if [ $gpu_enabled == "True" ]; then
echo "running nvidia install"
Expand Down
1 change: 1 addition & 0 deletions aztk/spark/models/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .hdfs import *
from .jupyter import *
from .jupyter_lab import *
from .rstudio_server import *
1 change: 1 addition & 0 deletions aztk/spark/models/plugins/jupyter_lab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .configuration import *
23 changes: 23 additions & 0 deletions aztk/spark/models/plugins/jupyter_lab/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
from aztk.models.plugins.plugin_configuration import PluginConfiguration, PluginPort, PluginRunTarget
from aztk.models.plugins.plugin_file import PluginFile
from aztk.utils import constants

dir_path = os.path.dirname(os.path.realpath(__file__))

class JupyterLabPlugin(PluginConfiguration):
def __init__(self):
super().__init__(
name="jupyterlab",
ports=[
PluginPort(
internal=8889,
public=True,
),
],
run_on=PluginRunTarget.All,
execute="jupyter_lab.sh",
files=[
PluginFile("jupyter_lab.sh", os.path.join(dir_path, "jupyter_lab.sh")),
],
)
55 changes: 55 additions & 0 deletions aztk/spark/models/plugins/jupyter_lab/jupyter_lab.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# This custom script has been tested to work on the following docker images:
# - aztk/python:spark2.2.0-python3.6.2-base
# - aztk/python:spark2.2.0-python3.6.2-gpu
# - aztk/python:spark2.1.0-python3.6.2-base
# - aztk/python:spark2.1.0-python3.6.2-gpu

if [ "$IS_MASTER" = "1" ]; then
conda install -c conda-force jupyterlab

PYSPARK_DRIVER_PYTHON="/.pyenv/versions/${USER_PYTHON_VERSION}/bin/jupyter"
JUPYTER_KERNELS="/.pyenv/versions/${USER_PYTHON_VERSION}/share/jupyter/kernels"

# disable password/token on jupyter notebook
jupyter lab --generate-config --allow-root
JUPYTER_CONFIG='/.jupyter/jupyter_notebook_config.py'
echo >> $JUPYTER_CONFIG
echo -e 'c.NotebookApp.token=""' >> $JUPYTER_CONFIG
echo -e 'c.NotebookApp.password=""' >> $JUPYTER_CONFIG

# get master ip
MASTER_IP=$(hostname -i)

# remove existing kernels
rm -rf $JUPYTER_KERNELS/*

# set up jupyter to use pyspark
mkdir $JUPYTER_KERNELS/pyspark
touch $JUPYTER_KERNELS/pyspark/kernel.json
cat << EOF > $JUPYTER_KERNELS/pyspark/kernel.json
{
"display_name": "PySpark",
"language": "python",
"argv": [
"python",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"env": {
"SPARK_HOME": "$SPARK_HOME",
"PYSPARK_PYTHON": "python",
"PYSPARK_SUBMIT_ARGS": "--master spark://$MASTER_IP:7077 pyspark-shell"
}
}
EOF

# start jupyter notebook from /mnt - this is where we recommend you put your azure files mount point as well
cd /mnt
(PYSPARK_DRIVER_PYTHON=$PYSPARK_DRIVER_PYTHON PYSPARK_DRIVER_PYTHON_OPTS="lab --no-browser --port=8889 --allow-root" pyspark &)
fi


0 comments on commit da61337

Please sign in to comment.