diff --git a/jupyter/build/sage.Dockerfile b/jupyter/build/sage.Dockerfile new file mode 100644 index 0000000..f5b2b46 --- /dev/null +++ b/jupyter/build/sage.Dockerfile @@ -0,0 +1,65 @@ +ARG BASE_CONTAINER=betalupi/jupyter-base +FROM $BASE_CONTAINER +LABEL maintainer="Mark " + +ARG SAGE_VERSION=9.0 +ARG SAGE_PYTHON_VERSION=3.7 + +USER root + +RUN apt-get update --yes && apt-get install --yes --no-install-recommends \ + dvipng \ + ffmpeg \ + imagemagick \ + texlive \ + tk tk-dev \ + jq && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + + +USER $NB_UID + +# Initialize conda for shell interaction +RUN conda init bash + +# Install Sage conda environment +RUN conda install --quiet --yes -n base -c conda-forge widgetsnbextension && \ + conda create --quiet --yes -n sage -c conda-forge sage=$SAGE_VERSION python=$SAGE_PYTHON_VERSION && \ + conda clean --all -f -y && \ + npm cache clean --force && \ + fix-permissions $CONDA_DIR && \ + fix-permissions /home/$NB_USER + +# Install sagemath kernel and extensions using conda run: +# Create jupyter directories if they are missing +# Add environmental variables to sage kernal using jq +RUN echo ' \ + from sage.repl.ipython_kernel.install import SageKernelSpec; \ + SageKernelSpec.update(prefix=os.environ["CONDA_DIR"]); \ + ' | conda run -n sage sage && \ + echo ' \ + cat $SAGE_ROOT/etc/conda/activate.d/sage-activate.sh | \ + grep -Po '"'"'(?<=^export )[A-Z_]+(?=)'"'"' | \ + jq --raw-input '"'"'.'"'"' | jq -s '"'"'.'"'"' | \ + jq --argfile kernel $SAGE_LOCAL/share/jupyter/kernels/sagemath/kernel.json \ + '"'"'. | map(. as $k | env | .[$k] as $v | {($k):$v}) | add as $vars | $kernel | .env= $vars'"'"' > \ + $CONDA_DIR/share/jupyter/kernels/sagemath/kernel.json \ + ' | conda run -n sage sh && \ + fix-permissions $CONDA_DIR && \ + fix-permissions /home/$NB_USER + +# Install sage's python kernel +RUN echo ' \ + ls /opt/conda/envs/sage/share/jupyter/kernels/ | \ + grep -Po '"'"'python\d'"'"' | \ + xargs -I % sh -c '"'"' \ + cd $SAGE_LOCAL/share/jupyter/kernels/% && \ + cat kernel.json | \ + jq '"'"'"'"'"'"'"'"' . | .display_name = .display_name + " (sage)" '"'"'"'"'"'"'"'"' > \ + kernel.json.modified && \ + mv -f kernel.json.modified kernel.json && \ + ln -s $SAGE_LOCAL/share/jupyter/kernels/% $CONDA_DIR/share/jupyter/kernels/%_sage \ + '"'"' \ + ' | conda run -n sage sh && \ + fix-permissions $CONDA_DIR && \ + fix-permissions /home/$NB_USER \ No newline at end of file