diff --git a/docker/jupyter/Dockerfile b/docker/jupyter/Dockerfile index 5beec32469..faf0c6b528 100644 --- a/docker/jupyter/Dockerfile +++ b/docker/jupyter/Dockerfile @@ -1,32 +1,23 @@ # This Dockerfile containers Jupyter Notebook server with many # SQLFlow tutorials and SQLFlow magic command. -FROM jupyter/base-notebook +FROM alpine:3.12 -# using root user to avoid permission deni -USER root -# Choose fastest mirrors for apt-get and pip -COPY docker/dev/find_fastest_resources.sh /usr/local/bin/find_fastest_resources.sh -RUN /bin/bash -c 'source find_fastest_resources.sh \ - && echo "Choose the fastest APT source ..." \ - && choose_fastest_apt_source \ - && echo "Choose the fastest PIP source ..." \ - && choose_fastest_pip_source' +COPY docker/dev/find_fastest_resources.sh /usr/local/bin/ +RUN /bin/sh -c "source find_fastest_resources.sh && \ + choose_fastest_alpine_source && \ + choose_fastest_pip_source" -# Install dependencies. -COPY docker/jupyter/js /jupyter/js - -RUN apt-get -qq update - -COPY docker/jupyter/install-jupyter.bash /jupyter -RUN /jupyter/install-jupyter.bash - -# switch back to the default user to avoid accidental container runs as root, -# this env comes from base Dockerfile: https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile#L13 -USER $NB_UID +RUN apk add --no-cache python3 py3-pip py3-pyzmq py3-grpcio # Install IPythono Notebook tutorials +COPY /docker/jupyter/js /jupyter/js/ COPY build/tutorial /workspace +COPY docker/jupyter/install-jupyter.sh /jupyter/install-jupyter.sh +RUN /bin/sh /jupyter/install-jupyter.sh + +# Cleanup +RUN apk del --purge py3-pip # The following SQLFlow gRPC server endpoint implies the server runs in a container, # and if container has the option --net=container:sqlflow_server_container, SQLFlow magic diff --git a/docker/jupyter/install-jupyter.bash b/docker/jupyter/install-jupyter.sh similarity index 75% rename from docker/jupyter/install-jupyter.bash rename to docker/jupyter/install-jupyter.sh index 31a8a37a15..f1e69e5fe6 100755 --- a/docker/jupyter/install-jupyter.bash +++ b/docker/jupyter/install-jupyter.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Copyright 2020 The SQLFlow Authors. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +15,18 @@ set -e -# This file depends on install-python.bash. # install jupyterhub Python package so that this image can be used as jupyterhub # singleuser notebook server, ref: https://github.com/jupyterhub/jupyterhub/tree/master/singleuser -pip install --quiet \ - jupyterhub==1.1.0 \ - sqlflow==0.10.0 # sqlflow is the Python client of SQLFlow server. +# Install pandas pre-compiled apk, we do not want to build +# this python package locally because it relies on gcc and +# other build tools, which make the image very large +wget -q http://cdn.sqlflow.tech/alpine/py3-pandas-1.0.3-r0.apk +wget -q -P /etc/apk/keys/ http://cdn.sqlflow.tech/alpine/sqlflow-5ef80180.rsa.pub +apk add py3-pandas-1.0.3-r0.apk && rm py3-pandas-1.0.3-r0.apk + +pip -q install \ + notebook \ + sqlflow==0.10.0 # Load SQLFlow's Jupyter magic command # automatically. c.f. https://stackoverflow.com/a/32683001. @@ -33,7 +39,7 @@ mkdir -p /workspace >> "$IPYTHON_STARTUP"/00-first.py # Enable highlighting, see https://stackoverflow.com/questions/43641362 -NOTEBOOK_DIR=$(python -c "print(__import__('notebook').__path__[0])") +NOTEBOOK_DIR=$(python3 -c "print(__import__('notebook').__path__[0])") CODE_MIRROR_MODE_PATH=$NOTEBOOK_DIR/static/components/codemirror/mode mkdir -p "$HOME"/.jupyter/custom/ mkdir -p "$CODE_MIRROR_MODE_PATH"/sqlflow