Skip to content

Commit

Permalink
Jupyterlab openmpp poc (#518)
Browse files Browse the repository at this point in the history
* feat: install openmpp as jupyterlab service

* fix: generate dockerfiles

* chore: trigger auto-deploy

* fix: copy oms startup script

* fix: copy script in correct docker bit

* fix: make script executable

* fix: update openm version, fix config

* fix: sync issue

* fix: prepare openmpp config for prod deployment

* fix: move config to start-oms script
  • Loading branch information
vexingly authored Sep 25, 2023
1 parent 9089ab1 commit c7a8c55
Show file tree
Hide file tree
Showing 43 changed files with 1,345 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ DEFAULT_NB_PREFIX := /notebook/username/notebookname

.PHONY: clean .output generate-dockerfiles


clean:
rm -rf $(OUT) $(TMP)

Expand Down
29 changes: 29 additions & 0 deletions docker-bits/6_jupyterlab.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,35 @@ RUN julia -e 'using Pkg; Pkg.add("LanguageServer")' && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER

# OpenM install
# Install OpenM++ MPI
ARG OMPP_VERSION="1.15.4"
# IMPORTANT: Don't forget to update the version number in the openmpp.desktop file!!
ARG OMPP_PKG_DATE="20230803"
ARG SHA256ompp=5da79984ef67ad16b3b7d429896b8a553930ca46a16079aaef24b3c9dc867956
# OpenM++ environment settings
ENV OMPP_INSTALL_DIR=/opt/openmpp/${OMPP_VERSION}

# OpenM++ expects sqlite to be installed (not just libsqlite)
RUN apt-get install --yes sqlite3 \
&& wget -q https://github.com/openmpp/main/releases/download/v${OMPP_VERSION}/openmpp_debian_${OMPP_PKG_DATE}.tar.gz -O /tmp/ompp.tar.gz \
&& echo "${SHA256ompp} /tmp/ompp.tar.gz" | sha256sum -c - \
&& mkdir -p ${OMPP_INSTALL_DIR} \
&& tar -xf /tmp/ompp.tar.gz -C ${OMPP_INSTALL_DIR} --strip-components=1

# Customize and rebuild omp-ui for jupyter-ompp-proxy install
# issue with making a relative publicPath https://github.com/quasarframework/quasar/issues/8513
RUN sed -i -e 's/history/hash/' ${OMPP_INSTALL_DIR}/ompp-ui/quasar.conf.js \
&& sed -i -e "s/OMS_URL:.*''/OMS_URL: '.'/" ${OMPP_INSTALL_DIR}/ompp-ui/quasar.conf.js \
&& npm install --prefix ${OMPP_INSTALL_DIR}/ompp-ui \
&& npm run build --prefix ${OMPP_INSTALL_DIR}/ompp-ui \
&& rm -r ${OMPP_INSTALL_DIR}/html \
&& mv ${OMPP_INSTALL_DIR}/ompp-ui/dist/spa ${OMPP_INSTALL_DIR}/html \
&& fix-permissions ${OMPP_INSTALL_DIR}

COPY jupyter-ompp-proxy/ /opt/jupyter-ompp-proxy/
RUN pip install /opt/jupyter-ompp-proxy/

# Solarized Theme and Cell Execution Time
COPY jupyterlab-overrides.json /opt/conda/share/jupyter/lab/settings/overrides.json

Expand Down
3 changes: 3 additions & 0 deletions docker-bits/∞_CMD.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ EXPOSE 8888
COPY start-custom.sh /usr/local/bin/
COPY mc-tenant-wrapper.sh /usr/local/bin/mc
COPY trino-wrapper.sh /usr/local/bin/trino
COPY start-oms.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/start-oms.sh

# Add --user to all pip install calls and point pip to Artifactory repository
COPY pip.conf /tmp/pip.conf
Expand Down
1 change: 1 addition & 0 deletions docker-bits/∞_CMD_remote-desktop.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ EXPOSE 8888
COPY start-remote-desktop.sh /usr/local/bin/
COPY mc-tenant-wrapper.sh /usr/local/bin/mc
COPY trino-wrapper.sh /usr/local/bin/trino

RUN chmod +x /usr/local/bin/trino
RUN chsh -s /bin/bash $NB_USER

Expand Down
3 changes: 3 additions & 0 deletions output/docker-stacks-datascience-notebook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ EXPOSE 8888
COPY start-custom.sh /usr/local/bin/
COPY mc-tenant-wrapper.sh /usr/local/bin/mc
COPY trino-wrapper.sh /usr/local/bin/trino
COPY start-oms.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/start-oms.sh

# Add --user to all pip install calls and point pip to Artifactory repository
COPY pip.conf /tmp/pip.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import logging

logger = logging.getLogger(__name__)
logger.setLevel("INFO")

def setup_ompp():

def _get_cmd():

return [
"bash",
"-c",
"/usr/local/bin/start-oms.sh"
]

def _rewrite_response(response):
if 'Location' in response.headers:
response.headers['Location'] = response.headers['Location'].replace('/SASStudio', os.environ.get('NB_PREFIX') + '/sasstudio/SASStudio')

return {
"command": _get_cmd,
"timeout": 60,
"port": 4040,
"launcher_entry": {
"title": "OpenM++",
"icon_path": os.path.join(os.getenv("OMPP_INSTALL_DIR", None), "html", "icons", "openmpp.svg"),
},
"rewrite_response": _rewrite_response,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import setuptools

setuptools.setup(
name="jupyter-ompp-proxy",
version='0.0.1',
url="https://github.com/StatCan/jupyter-ompp-proxy",
author="Her Majesty The Queen In Right of Canada",
description="Jupyter extension to proxy OpenM++ webui",
packages=setuptools.find_packages(),
keywords=['SAS'],
classifiers=['Framework :: Jupyter'],
install_requires=[
'jupyter-server-proxy>=3.2.0'
],
entry_points={
'jupyter_serverproxy_servers': [
'ompp = jupyter_ompp_proxy:setup_ompp'
]
},
# package_data={
# 'jupyter_sasstudio_proxy': ['icons/sasstudio.svg'],
# },
)
8 changes: 8 additions & 0 deletions output/docker-stacks-datascience-notebook/start-custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ if [[ "$KUBERNETES_SERVICE_HOST" =~ ".131." ]]; then
conda config --add channels https://jfrog.aaw.cloud.statcan.ca/artifactory/api/conda/conda-pytorch-remote
fi

# Copy default ompp models on first start up
export OMS_MODELS_DIR="/home/jovyan/models"
if [ ! -d "$OMS_MODELS_DIR" ]; then
echo "Creating ompp default model directory"
mkdir -p "$OMS_MODELS_DIR"
cp -r "$OMPP_INSTALL_DIR/models/." "$OMS_MODELS_DIR"
fi

echo "--------------------starting jupyter--------------------"

/opt/conda/bin/jupyter server --notebook-dir=/home/${NB_USER} \
Expand Down
86 changes: 86 additions & 0 deletions output/docker-stacks-datascience-notebook/start-oms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
#
# It does:
# ulimit -S -s 65536
# OM_ROOT=${OM_ROOT} bin/oms -oms.Listen http://localhost:${OMS_PORT} -oms.HomeDir models/home -oms.AllowDownload -oms.AllowUpload -oms.AllowMicrodata -oms.LogRequest
#
# Environment:
# OM_ROOT - openM++ root folder, default: current directory
# OMS_PORT - oms web-service port to listen, default: 4040

# set -e
set -m

# large models may require stack limit increase
#
ulimit -S -s 65536
status=$?

if [ $status -ne 0 ] ;
then
echo "FAILED to set: ulimit -S -s 65536"
echo -n "Press Enter to exit..."
read any
exit $status
fi

# set openM++ root folder
#
self=$(basename $0)

OM_ROOT="$OMPP_INSTALL_DIR"

[ "$OM_ROOT" != "$PWD" ] && pushd $OM_ROOT

# allow to use $MODEL_NAME.ini file in UI for model run
#
export OM_CFG_INI_ALLOW=true
export OM_CFG_INI_ANY_KEY=true
export OMS_URL=${JUPYTER_SERVER_URL}ompp

# OpenM++ default configuraton
if [[ "$KUBERNETES_SERVICE_HOST" =~ ".131." ]]; then
#DEV
export OMS_MODEL_DIR=/home/jovyan/models
export OMS_HOME_DIR=/home/jovyan/
else
if [ -d "/etc/protb" ]; then
export OMS_MODEL_DIR=/home/jovyan/buckets/aaw-protected-b/microsim/models
export OMS_HOME_DIR=/home/jovyan/buckets/aaw-protected-b/microsim/
else
export OMS_MODEL_DIR=/home/jovyan/buckets/aaw-unclassified/microsim/models
export OMS_HOME_DIR=/home/jovyan/buckets/aaw-unclassified/microsim/
fi
fi

# start oms web-service
#
[ -z "$OMS_PORT" ] && OMS_PORT=4040

echo "OM_ROOT=$OM_ROOT"
echo "OMS_PORT=$OMS_PORT"
echo "OMS_URL=$OMS_URL"

echo "OMS_MODEL_DIR=$OMS_MODEL_DIR"
if [ ! -d $OMS_MODEL_DIR ]; then
mkdir -p $OMS_MODEL_DIR
fi

echo "OMS_HOME_DIR=$OMS_HOME_DIR"
if [ ! -d $OMS_HOME_DIR ]; then
mkdir -p $OMS_HOME_DIR
fi

OM_ROOT=$OM_ROOT ./bin/oms -l localhost:${OMS_PORT} -oms.ModelDir ${OMS_MODEL_DIR} -oms.HomeDir ${OMS_HOME_DIR} -oms.AllowDownload -oms.AllowUpload -oms.AllowMicrodata -oms.LogRequest
status=$?

if [ $status -ne 0 ] ;
then
[ $status -eq 130 ] && echo " oms web-service terminated by Ctrl+C"
[ $status -ne 130 ] && echo " FAILED to start oms web-service"
fi

echo "."
echo -n "Press Enter to exit..."
read any
exit $status
32 changes: 32 additions & 0 deletions output/jupyterlab-cpu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,35 @@ RUN julia -e 'using Pkg; Pkg.add("LanguageServer")' && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER

# OpenM install
# Install OpenM++ MPI
ARG OMPP_VERSION="1.15.4"
# IMPORTANT: Don't forget to update the version number in the openmpp.desktop file!!
ARG OMPP_PKG_DATE="20230803"
ARG SHA256ompp=5da79984ef67ad16b3b7d429896b8a553930ca46a16079aaef24b3c9dc867956
# OpenM++ environment settings
ENV OMPP_INSTALL_DIR=/opt/openmpp/${OMPP_VERSION}

# OpenM++ expects sqlite to be installed (not just libsqlite)
RUN apt-get install --yes sqlite3 \
&& wget -q https://github.com/openmpp/main/releases/download/v${OMPP_VERSION}/openmpp_debian_${OMPP_PKG_DATE}.tar.gz -O /tmp/ompp.tar.gz \
&& echo "${SHA256ompp} /tmp/ompp.tar.gz" | sha256sum -c - \
&& mkdir -p ${OMPP_INSTALL_DIR} \
&& tar -xf /tmp/ompp.tar.gz -C ${OMPP_INSTALL_DIR} --strip-components=1

# Customize and rebuild omp-ui for jupyter-ompp-proxy install
# issue with making a relative publicPath https://github.com/quasarframework/quasar/issues/8513
RUN sed -i -e 's/history/hash/' ${OMPP_INSTALL_DIR}/ompp-ui/quasar.conf.js \
&& sed -i -e "s/OMS_URL:.*''/OMS_URL: '.'/" ${OMPP_INSTALL_DIR}/ompp-ui/quasar.conf.js \
&& npm install --prefix ${OMPP_INSTALL_DIR}/ompp-ui \
&& npm run build --prefix ${OMPP_INSTALL_DIR}/ompp-ui \
&& rm -r ${OMPP_INSTALL_DIR}/html \
&& mv ${OMPP_INSTALL_DIR}/ompp-ui/dist/spa ${OMPP_INSTALL_DIR}/html \
&& fix-permissions ${OMPP_INSTALL_DIR}

COPY jupyter-ompp-proxy/ /opt/jupyter-ompp-proxy/
RUN pip install /opt/jupyter-ompp-proxy/

# Solarized Theme and Cell Execution Time
COPY jupyterlab-overrides.json /opt/conda/share/jupyter/lab/settings/overrides.json

Expand Down Expand Up @@ -365,6 +394,9 @@ EXPOSE 8888
COPY start-custom.sh /usr/local/bin/
COPY mc-tenant-wrapper.sh /usr/local/bin/mc
COPY trino-wrapper.sh /usr/local/bin/trino
COPY start-oms.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/start-oms.sh

# Add --user to all pip install calls and point pip to Artifactory repository
COPY pip.conf /tmp/pip.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import logging

logger = logging.getLogger(__name__)
logger.setLevel("INFO")

def setup_ompp():

def _get_cmd():

return [
"bash",
"-c",
"/usr/local/bin/start-oms.sh"
]

def _rewrite_response(response):
if 'Location' in response.headers:
response.headers['Location'] = response.headers['Location'].replace('/SASStudio', os.environ.get('NB_PREFIX') + '/sasstudio/SASStudio')

return {
"command": _get_cmd,
"timeout": 60,
"port": 4040,
"launcher_entry": {
"title": "OpenM++",
"icon_path": os.path.join(os.getenv("OMPP_INSTALL_DIR", None), "html", "icons", "openmpp.svg"),
},
"rewrite_response": _rewrite_response,
}
23 changes: 23 additions & 0 deletions output/jupyterlab-cpu/jupyter-ompp-proxy/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import setuptools

setuptools.setup(
name="jupyter-ompp-proxy",
version='0.0.1',
url="https://github.com/StatCan/jupyter-ompp-proxy",
author="Her Majesty The Queen In Right of Canada",
description="Jupyter extension to proxy OpenM++ webui",
packages=setuptools.find_packages(),
keywords=['SAS'],
classifiers=['Framework :: Jupyter'],
install_requires=[
'jupyter-server-proxy>=3.2.0'
],
entry_points={
'jupyter_serverproxy_servers': [
'ompp = jupyter_ompp_proxy:setup_ompp'
]
},
# package_data={
# 'jupyter_sasstudio_proxy': ['icons/sasstudio.svg'],
# },
)
8 changes: 8 additions & 0 deletions output/jupyterlab-cpu/start-custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ if [[ "$KUBERNETES_SERVICE_HOST" =~ ".131." ]]; then
conda config --add channels https://jfrog.aaw.cloud.statcan.ca/artifactory/api/conda/conda-pytorch-remote
fi

# Copy default ompp models on first start up
export OMS_MODELS_DIR="/home/jovyan/models"
if [ ! -d "$OMS_MODELS_DIR" ]; then
echo "Creating ompp default model directory"
mkdir -p "$OMS_MODELS_DIR"
cp -r "$OMPP_INSTALL_DIR/models/." "$OMS_MODELS_DIR"
fi

echo "--------------------starting jupyter--------------------"

/opt/conda/bin/jupyter server --notebook-dir=/home/${NB_USER} \
Expand Down
Loading

0 comments on commit c7a8c55

Please sign in to comment.