Skip to content

Commit

Permalink
Merge pull request #42 from KxSystems/licensing_dev
Browse files Browse the repository at this point in the history
Licensing dev
  • Loading branch information
jhanna-kx authored Mar 20, 2019
2 parents 0c0f8a9 + cf1fe98 commit 6981011
Show file tree
Hide file tree
Showing 22 changed files with 644 additions and 203 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ jupyter notebook kdb+Notebooks.ipynb
If you have [Docker installed](https://www.docker.com/community-edition) you can alternatively run:
docker run -it -p 8888:8888 --name myjupyterq kxsys/jupyterq
docker run -it --name myjupyterq -p 8888:8888 kxsys/jupyterq
Now point your browser at http://localhost:8888/notebooks/kdb%2BNotebooks.ipynb.
For subsequent runs, you will not be prompted to redo the license setup when calling:
docker start -ai myjupyterq
**N.B.** [instructions regarding headless/presets are available](https://github.com/KxSystems/embedPy/docker/README.md#headlesspresets)
To change the port or use the image to run your own notebooks, see the docker [README](docker/README.md#runoptions)
**N.B.** [instructions regarding headless/presets are available](https://github.com/KxSystems/embedPy/blob/master/docker/README.md#headlesspresets)
**N.B.** [build instructions for the image are available](docker/README.md)
Expand Down
32 changes: 32 additions & 0 deletions build/doit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
usage=\
"Usage:\n\tdoit.sh [repodir]
\tbuilds conda package, set NOTEST in env to skip tests during conda build (faster)
"

if [ $# -lt 1 ]
then
printf "$usage" >&2
exit 1
elif [ ! -d $1 ]
then
printf "$1 doesn't exist\n\n$usage" >&2
exit 1
fi

: "${JUPYTERQ_VERSION:=local_dev}"
[ -z "$NOTEST" ] && export QLIC="${QLIC:=$QHOME}"

JUPYTERQ_REQS=$(paste -sd "|" $1/requirements.txt)

export JUPYTERQ_REQS
export JUPYTERQ_VERSION
export QLIC

set -x
if [ ! -z "$QLIC" ]
then
conda build -c kx --no-long-test-prefix $1/conda-recipe
else
conda build -c kx --no-test conda-recipe
fi
12 changes: 12 additions & 0 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ copy /Y jupyterq*.q? %QHOME%\ || goto :error
xcopy kxpy %QHOME%\kxpy /I/S/E/H|| goto :error
copy /Y /B w64\jupyterq.dll %QHOME%\w64\ || goto :error
set JK=%PREFIX%\share\jupyter\kernels\qpk
set JL=jupyterq_licensemgr\jupyterq_licensemgr
mkdir %JK%
mkdir %PREFIX%\etc\jupyter\jupyter_notebook_config.d
mkdir %PREFIX%\etc\jupyter\nbconfig\notebook.d
mkdir %PREFIX%\share\jupyter\nbextensions\jupyterq_licensemgr
copy kernelspec\* %JK%

cd jupyterq_licensemgr
python setup.py install
cd ..

copy %JL%\index.js %PREFIX%\share\jupyter\nbextensions\jupyterq_licensemgr
copy %JL%\jupyterq_licensemgr.json %PREFIX%\etc\jupyter\nbconfig\notebook.d
copy %JL%\jupyterq_licensemgr_config.json %PREFIX%\etc\jupyter\jupyter_notebook_config.d

exit /b 0
:error
exit /b %errorlevel%
Expand Down
7 changes: 6 additions & 1 deletion conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ fi
make -f build/makefile jupyterq
mkdir -p $QHOME/$QLIBDIR
JK=$PREFIX/share/jupyter/kernels/qpk
mkdir -p $JK
JL=jupyterq_licensemgr/jupyterq_licensemgr
mkdir -p $JK $PREFIX/etc/jupyter/nbconfig/notebook.d $PREFIX/etc/jupyter/jupyter_notebook_config.d $PREFIX/share/jupyter/nbextensions/jupyterq_licensemgr
cp kernelspec/* $JK
(cd jupyterq_licensemgr && python setup.py install)
cp $JL/index.js $PREFIX/share/jupyter/nbextensions/jupyterq_licensemgr
cp $JL/jupyterq_licensemgr.json $PREFIX/etc/jupyter/nbconfig/notebook.d
cp $JL/jupyterq_licensemgr_config.json $PREFIX/etc/jupyter/jupyter_notebook_config.d
cp jupyterq*.q $QHOME
cp -r kxpy $QHOME
cp $QLIBDIR/jupyterq.so $QHOME/$QLIBDIR
2 changes: 1 addition & 1 deletion conda-recipe/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
if [ -e ${QLIC}/kc.lic ]
if [ -e ${QLIC}/kc.lic ] || [ -e ${QLIC}/k4.lic ]
then
tests/test.sh
else
Expand Down
66 changes: 47 additions & 19 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@ ARG embedpy_img=kxsys/embedpy:latest
####

FROM $embedpy_img AS embedpy

# do not clean here, its cleaned later!
# no upgrade either as it comes from embedPy
RUN apt-get update

####

FROM embedpy AS juypterq

RUN apt-get -yy --option=Dpkg::options::=--force-unsafe-io --no-install-recommends install \
build-essential \
RUN apt-get update \
&& apt-get -yy --option=Dpkg::options::=--force-unsafe-io --no-install-recommends install build-essential \
&& apt-get clean \
&& find /var/lib/apt/lists -type f -delete

COPY build/makefile requirements.txt *.q *.p *.ipynb /opt/kx/jupyterq/
COPY jupyterq_licensemgr/ /opt/kx/jupyterq/jupyterq_licensemgr/
COPY src/c/ /opt/kx/jupyterq/src/c/
COPY kxpy/ /opt/kx/jupyterq/kxpy/
COPY kernelspec/ /opt/kx/jupyterq/kernelspec/
COPY examples/ /opt/kx/jupyterq/examples/
# COPY kdb+Notebooks.ipynb /opt/kx/jupyterq/examples/kdb+Notebooks.ipynb

RUN make -C /opt/kx/jupyterq jupyterq

Expand All @@ -50,32 +45,65 @@ LABEL org.label-schema.schema-version="1.0" \
org.label-schema.build-date="$BUILD_DATE" \
org.label-schema.docker.cmd="docker run -v `pwd`/q:/tmp/q -p $PORT:$PORT kxsys/jupyterq"

RUN apt-get -yy --option=Dpkg::options::=--force-unsafe-io --no-install-recommends install \
libgl1-mesa-glx \
&& apt-get clean \
&& find /var/lib/apt/lists -type f -delete

COPY --from=juypterq /opt/kx/jupyterq /opt/kx/jupyterq
RUN chown kx:kx /opt/kx/jupyterq /opt/kx/jupyterq/kdb+Notebooks.ipynb
RUN find /opt/kx/jupyterq -maxdepth 1 -type f -name 'jupyterq_*.q' | xargs ln -s -t /opt/kx/q \
&& ln -s -t /opt/kx/q /opt/kx/jupyterq/kxpy \
&& ln -s -t /opt/kx/q/l64 /opt/kx/jupyterq/l64/jupyterq.so

RUN apt-get update \
&& apt-get -yy --option=Dpkg::options::=--force-unsafe-io --no-install-recommends install xinetd libgl1-mesa-glx \
&& apt-get clean \
&& find /var/lib/apt/lists -type f -delete

USER kx

RUN . /opt/conda/etc/profile.d/conda.sh \
&& conda activate kx \
&& conda install nomkl \
&& conda install --file /opt/kx/jupyterq/requirements.txt \
&& conda clean -y --all \
&& jupyter kernelspec install --user --name=qpk /opt/kx/jupyterq/kernelspec \
&& jupyter trust /opt/kx/jupyterq/kdb+Notebooks.ipynb
&& conda clean -y --all

USER root

RUN chown -R kx:kx /opt/kx/jupyterq/jupyterq_licensemgr

USER kx

RUN . /opt/conda/etc/profile.d/conda.sh \
&& conda activate kx \
&& cd /opt/kx/jupyterq/jupyterq_licensemgr \
&& python setup.py build \
&& pip install --user --no-deps .

# remove token auth
RUN mkdir ~/.jupyter \
RUN mkdir -p ~/.jupyter \
&& echo "c.NotebookApp.token = u''" > ~/.jupyter/jupyter_notebook_config.py

RUN . /opt/conda/etc/profile.d/conda.sh \
&& conda activate kx \
&& jupyter kernelspec install --user --name=qpk /opt/kx/jupyterq/kernelspec \
&& jupyter nbextension install --user --py jupyterq_licensemgr \
&& jupyter nbextension enable --user --py jupyterq_licensemgr \
&& jupyter serverextension enable --py jupyterq_licensemgr \
&& jupyter trust /opt/kx/jupyterq/kdb+Notebooks.ipynb

USER root
COPY docker/init /init
RUN chmod 0755 /init


## Create new Entry folders
## Notebooks, Data & Scripts can all be mounted to these folders

ARG nbroot=/jqnotebooks
ARG nbdata=/jqdata
ARG nbscripts=/jqscripts

ENV NBROOT=${nbroot}
ENV NBDATA=${nbdata}
ENV NBSCRIPTS=${nbscipts}

VOLUME ${nbroot} ${nbdata} ${nbscripts}

ENTRYPOINT ["/init"]
CMD ["/bin/sh", "-l", "-c", "printf '\npoint your browser at http://127.0.0.1:%s/notebooks/kdb%%2BNotebooks.ipynb\n\n' $PORT && exec jupyter notebook --notebook-dir=/opt/kx/jupyterq --ip='0.0.0.0' --port=$PORT --no-browser"]
24 changes: 23 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ To build the project locally you run:

Once built, you should have a local `jupyterq` image, you can run the following to use it:

docker run -it -p 8888:8888 jupyterq
docker run --rm -it -p 8888:8888 jupyterq


**N.B.** if you wish to use an alternative source for [embedPy](https://github.com/KxSystems/embedPy) then you can append `--build-arg embedpy_img=embedpy` to your argument list.

Other build arguments are supported and you should browse the `Dockerfile` to see what they are.


# Deploy

[travisCI](https://travis-ci.org/) is configured to monitor when tags of the format `/^[0-9]+\./` are added to the [GitHub hosted project](https://github.com/KxSystems/jupyterq), a corresponding Docker image is generated and made available on [Docker Cloud](https://cloud.docker.com/)
Expand All @@ -36,6 +37,27 @@ To do a deploy, you simply tag and push your releases as usual:
git push --tag


## Run Options

These options apply both to a locally build image if you have one or the `kxsys/jupyterq` image

To change the port the container exposes the notebook server on:

docker run --rm -it -p 9000:9000 -e PORT=9000 kxsys/jupyterq

You can use the image to run your own JupyterQ notebooks without building another docker image, the directory with your notebooks should be mounted in the container at /jqnotebooks.

For example if your notebooks are on the host machine in a directory `examples`, then:

On Windows

docker run -it -p 8888:8888 -v %cd%\examples:/jqnotebooks kxsys/jupyterq

Or on Mac / Linux

docker run -it -p 8888:8888 -v $(pwd)/examples:/jqnotebooks kxsys/jupyterq


## Related Links

* [Docker](https://docker.com)
Expand Down
19 changes: 19 additions & 0 deletions docker/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
/usr/sbin/xinetd -d &

HOME=/home/kx
export HOME

target=$NBROOT
if find "$target" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then
echo "Not empty, do nothing"
else
echo "'$NBROOT' is empty, copying default file" && cp -R /opt/kx/jupyterq/examples $NBROOT && cp /opt/kx/jupyterq/kdb+Notebooks.ipynb $NBROOT
fi

chmod -R a+w $NBROOT
chmod -R a+w $NBDATA

printf '\npoint your browser at http://localhost:%s/notebooks/kdb%%2BNotebooks.ipynb\n\n' "$PORT"

exec chpst -u kx /bin/sh -l -c "cd /opt/kx/jupyterq && QLIC=/home/kx exec jupyter notebook --notebook-dir='$NBROOT' --ip='0.0.0.0' --port='$PORT' --no-browser"
Loading

0 comments on commit 6981011

Please sign in to comment.