Skip to content

Commit

Permalink
Merge pull request #24 from yacchin1205/fix/my-binder
Browse files Browse the repository at this point in the history
Fixed a problem that did not work on mybinder.org.
  • Loading branch information
yacchin1205 authored Oct 17, 2024
2 parents 86f7894 + 6f95e7b commit aa3f910
Show file tree
Hide file tree
Showing 23 changed files with 3,471 additions and 44 deletions.
40 changes: 26 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM solr:8 AS solr

FROM niicloudoperation/notebook:latest
FROM jupyter/scipy-notebook:latest

USER root

# Install OpenJDK and lsyncd
RUN apt-get update && apt-get install -yq supervisor lsyncd uuid-runtime \
openjdk-11-jre gnupg curl tinyproxy \
openjdk-11-jre gnupg curl tinyproxy netcat \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -32,17 +32,27 @@ RUN mkdir -p /opt/minio/bin/ && \

COPY . /tmp/nbsearch
RUN pip install -e /tmp/nbsearch && \
pip install 'notebook>=7' jupyter_nbextensions_configurator jupyter-server-proxy && \
pip install --no-cache jupyter_nbextensions_configurator \
git+https://github.com/NII-cloud-operation/Jupyter-LC_nblineage.git@feature/lab \
git+https://github.com/NII-cloud-operation/Jupyter-LC_notebook_diff.git@feature/lab \
git+https://github.com/NII-cloud-operation/Jupyter-LC_index.git@feature/lab \
jupyter-server-proxy && \
jupyter server extension enable --sys-prefix jupyter_server_proxy && \
jupyter labextension develop /tmp/nbsearch --overwrite && \
jupyter server extension enable nbsearch
jupyter server extension enable nbsearch && \
jupyter labextension enable nbsearch && \
jupyter labextension enable lc_notebook_diff && \
jupyter labextension enable lc_index

RUN mkdir -p /usr/local/bin/before-notebook.d && \
cp /tmp/nbsearch/example/*.sh /usr/local/bin/before-notebook.d/ && \
cp /tmp/nbsearch/example/00-add-config.sh /usr/local/bin/before-notebook.d/ && \
cp /tmp/nbsearch/example/99-run-supervisor.sh /usr/local/bin/before-notebook.d/ && \
chmod +x /usr/local/bin/before-notebook.d/*.sh && \
cp /tmp/nbsearch/example/update-index /usr/local/bin/ && \
chmod +x /usr/local/bin/update-index && \
mkdir -p /opt/nbsearch/ && \
cp -fr /tmp/nbsearch/solr /opt/nbsearch/
cp -fr /tmp/nbsearch/solr /opt/nbsearch/ && \
mkdir -p /jupyter_notebook_config.d && chown jovyan:users /jupyter_notebook_config.d

# Boot scripts to perform /usr/local/bin/before-notebook.d/* on JupyterHub
RUN mkdir -p /opt/nbsearch/original/bin/ && \
Expand All @@ -54,30 +64,32 @@ RUN mkdir -p /opt/nbsearch/original/bin/ && \
cp /tmp/nbsearch/example/jupyter-notebook /opt/conda/bin/ && \
cp /tmp/nbsearch/example/jupyter-lab /opt/conda/bin/ && \
cp /tmp/nbsearch/example/run-hook.sh /opt/nbsearch/bin/ && \
cp /tmp/nbsearch/example/build-index.sh /opt/nbsearch/bin/ && \
chmod +x /opt/conda/bin/jupyterhub-singleuser /opt/conda/bin/jupyter-notebook /opt/conda/bin/jupyter-lab \
/opt/nbsearch/bin/run-hook.sh
/opt/nbsearch/bin/*.sh

RUN jupyter nbclassic-extension install --py --sys-prefix nbsearch && \
jupyter nbclassic-serverextension enable --py --sys-prefix nbsearch && \
jupyter nbclassic-extension enable --py --sys-prefix nbsearch && \
jupyter nbclassic-extension enable --py --sys-prefix lc_notebook_diff
jupyter nbclassic-extension enable --py --sys-prefix lc_notebook_diff && \
jupyter nblineage quick-setup --sys-prefix

# Configuration for Server Proxy
RUN cat /tmp/nbsearch/example/jupyter_notebook_config.py >> $CONDA_DIR/etc/jupyter/jupyter_notebook_config.py

USER $NB_UID

RUN mkdir -p /home/$NB_USER/.nbsearch && \
cp /tmp/nbsearch/example/config_*.py /home/$NB_USER/.nbsearch/

RUN mkdir /home/$NB_USER/.nbsearch/conf.d && \
cp /tmp/nbsearch/example/config_*.py /home/$NB_USER/.nbsearch/ && \
mkdir /home/$NB_USER/.nbsearch/conf.d && \
cp /tmp/nbsearch/example/supervisor.conf /home/$NB_USER/.nbsearch/supervisor.conf && \
cp /tmp/nbsearch/example/update-index.lua /home/$NB_USER/.nbsearch/update-index.lua
cp /tmp/nbsearch/example/update-index.lua /home/$NB_USER/.nbsearch/update-index.lua && \
cp -fr /tmp/nbsearch/example/notebooks/* /home/$NB_USER/ && \
cp /tmp/nbsearch/images/* /home/$NB_USER/images/ && \
cp /tmp/nbsearch/README.md /home/$NB_USER/

# Create Solr schema
RUN precreate-core jupyter-notebook /opt/nbsearch/solr/jupyter-notebook/ && \
precreate-core jupyter-cell /opt/nbsearch/solr/jupyter-cell/

ENV DOCKER_STACKS_JUPYTER_CMD=lab

VOLUME /var/solr /var/minio
50 changes: 37 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,65 @@
# nbsearch

[![Github Actions Status](https://github.com/NII-cloud-operation/nbsearch//workflows/Build/badge.svg)](https://github.com/NII-cloud-operation/nbsearch//actions/workflows/build.yml)[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/NII-cloud-operation/nbsearch//main?urlpath=lab)
[![Release](https://github.com/NII-cloud-operation/nbsearch/actions/workflows/release.yml/badge.svg)](https://github.com/NII-cloud-operation/nbsearch/actions/workflows/release.yml) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/NII-cloud-operation/nbsearch/feature/lab?urlpath=lab)

nbsearch extension provides search capabilities for Jupyter Notebooks, which you created. It supports search by MEME in addition to search by keywords and modified times like a search engine. Therefore, users can easily find cells of the same origin in sticky notes added by sidestickies.

## Try it out on mybinder.org

You can try out the extension on mybinder.org by clicking the Binder badge above, and refer to the [Usage](#usage) section for more information.

The following software is installed in this environment.

- Services
- JupyterLab
- Jupyter Notebook 7
- [Apache Solr](https://solr.apache.org/)
- [MinIO](https://min.io/)

- Extensions
- nbsearch
- [nblineage](https://github.com/NII-cloud-operation/Jupyter-LC_nblineage)
- [lc_notebook_diff](https://github.com/NII-cloud-operation/Jupyter-LC_notebook_diff)

If you create a Notebook file in this environment, it will be automatically indexed in Solr and you will be able to search for it using the Search. Please refer to the [Usage](#usage) section for more information.

> **Note**: It may take some time for Apache Solr and MinIO to start up. If your search fails, please wait a while and try again.
## Requirements

- JupyterLab >= 4.0.0
- Jupyter Notebook >= 7.0.0

## Install

To install the extension, execute:

*TBD*

```bash
pip install git+https://github.com/NII-cloud-operation/nbsearch
```

To use nbsearch extension, you will also need to install and enable. You can use Jupyter subcommand:

*TBD*

```
jupyter nbextension install --py nbsearch
jupyter serverextension enable --py nbsearch
jupyter nbextension enable --py nbsearch
jupyter server extension enable nbsearch
jupyter labextension enable nbsearch
# If you want to use the extension with the classic notebook,
# you need to install and enable the nbclassic notebook extension.
jupyter nbclassic-extension install --py --sys-prefix nbsearch
jupyter nbclassic-serverextension enable --py --sys-prefix nbsearch
jupyter nbclassic-extension enable --py --sys-prefix nbsearch
```

To compare multiple Notebooks, you need to install [Jupyter-LC_notebook_diff](https://github.com/NII-cloud-operation/Jupyter-LC_notebook_diff), as shown below.

*TBD*

```
pip install git+https://github.com/NII-cloud-operation/Jupyter-LC_notebook_diff
jupyter nbextension install --py lc_notebook_diff
jupyter nbextension enable --py lc_notebook_diff
pip install git+https://github.com/NII-cloud-operation/Jupyter-LC_notebook_diff.git@feature/lab
jupyter labextension enable lc_notebook_diff
# If you want to use the extension with the classic notebook,
# you need to install and enable the nbclassic notebook extension.
jupyter nbclassic-extension enable --py --sys-prefix lc_notebook_diff
```

then restart Jupyter notebook.
Expand Down
8 changes: 6 additions & 2 deletions example/00-add-config.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

set -xe

TARGET_CONFIG_DIR=/jupyter_notebook_config.d

if [[ -f /home/$NB_USER/.nbsearch/config_local.py ]] ; then
cat /home/$NB_USER/.nbsearch/config_local.py >> /home/$NB_USER/.jupyter/jupyter_notebook_config.py
cp /home/$NB_USER/.nbsearch/config_local.py ${TARGET_CONFIG_DIR}/nbsearch-config.py
else
cat /home/$NB_USER/.nbsearch/config_base.py >> /home/$NB_USER/.jupyter/jupyter_notebook_config.py
cp /home/$NB_USER/.nbsearch/config_base.py ${TARGET_CONFIG_DIR}/nbsearch-config.py
fi
24 changes: 13 additions & 11 deletions example/99-run-supervisor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ set -xe
# For Solr
supervisord -c /home/jovyan/.nbsearch/supervisor.conf

if [[ ! -f /home/$NB_USER/.nbsearch/config_local.py ]] ; then
while ! nc -z localhost 8983; do
sleep 0.5
done
while ! nc -z localhost 9000; do
sleep 0.5
done
while ! curl http://localhost:8983/solr/jupyter-cell/admin/ping | grep '"status":"OK"'; do
sleep 0.5
done
jupyter nbsearch update-index --debug /home/$NB_USER/.jupyter/jupyter_notebook_config.py local
if [ ! -z "$WAIT_FOR_SOLR_READY" ]; then
if [[ ! -f /home/$NB_USER/.nbsearch/config_local.py ]] ; then
while ! nc -z localhost 8983; do
sleep 0.5
done
while ! nc -z localhost 9000; do
sleep 0.5
done
while ! curl http://localhost:8983/solr/jupyter-cell/admin/ping | grep '"status":"OK"'; do
sleep 0.5
done
jupyter nbsearch update-index --debug $CONDA_DIR/etc/jupyter/jupyter_notebook_config.py local
fi
fi

export SUPERVISOR_INITIALIZED=1
16 changes: 16 additions & 0 deletions example/build-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -xe

if [[ ! -f /home/$NB_USER/.nbsearch/config_local.py ]] ; then
while ! nc -z localhost 8983; do
sleep 0.5
done
while ! nc -z localhost 9000; do
sleep 0.5
done
while ! curl http://localhost:8983/solr/jupyter-cell/admin/ping | grep '"status":"OK"'; do
sleep 0.5
done
jupyter nbsearch update-index --debug $CONDA_DIR/etc/jupyter/jupyter_notebook_config.py local
fi
11 changes: 11 additions & 0 deletions example/jupyter_notebook_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Solr
import os
import tempfile

def _run_solr_proxy(port):
Expand All @@ -25,3 +26,13 @@ def _run_solr_proxy(port):
'timeout': 30,
}
}

# load additional config files
additional_config_path = os.environ.get('JUPYTER_ADDITIONAL_CONFIG_PATH',
'/jupyter_notebook_config.d')
if os.path.exists(additional_config_path):
for filename in sorted(os.listdir(additional_config_path)):
_, ext = os.path.splitext(filename)
if ext.lower() != '.py':
continue
load_subconfig(os.path.join(additional_config_path, filename))
Loading

0 comments on commit aa3f910

Please sign in to comment.