diff --git a/docker/server/Dockerfile b/docker/server/Dockerfile index 3d19c01ed7..86d40bcd3c 100644 --- a/docker/server/Dockerfile +++ b/docker/server/Dockerfile @@ -1,23 +1,25 @@ # NOTE: The docker build context directory must be the root of the source tree. # NOTE: To build the release image, SQLFlow must be built into ./build -FROM ubuntu:18.04 +FROM alpine:3.12 # Choose faster mirrors for apt-get and pip COPY docker/dev/find_fastest_resources.sh /usr/local/bin/ -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' +RUN /bin/sh -c 'source find_fastest_resources.sh && \ + echo "Choose the fastest Alpine source ..." && \ + choose_fastest_alpine_source && \ + echo "Choose the fastest PIP source ..." && \ + choose_fastest_pip_source' # Install Python and JRE. SQLFlow server requires Couler/Fluid to generate YAML # files, and Couler/Fluid depends on Python. The external parsers are in Java. -RUN apt-get -qq install -y \ - python3-dev python3-pip openjdk-8-jre-headless > /dev/null \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get -qq clean -y -RUN ln -s /usr/bin/python3 /usr/local/bin/python -RUN ln -s /usr/bin/pip3 /usr/local/bin/pip +RUN apk update \ + && apk add --no-cache python3 py3-pip openjdk8-jre-base axel sudo bash && \ + wget -q -O /etc/apk/keys/sgerrand.rsa.pub http://cdn.sqlflow.tech/alpine/sgerrand.rsa.pub.txt && \ + wget -q http://cdn.sqlflow.tech/alpine/glibc-2.31-r0.apk && \ + apk add glibc-2.31-r0.apk && \ + rm glibc-2.31-r0.apk && \ + ln -s /usr/bin/python3 /usr/local/bin/python && \ + ln -s /usr/bin/pip3 /usr/local/bin/pip # Install the SQLFlow Python source code, which includes template code. COPY python /usr/local/sqlflow/python @@ -27,13 +29,14 @@ ENV PYTHONPATH=/usr/local/sqlflow/python:$PYTHONPATH COPY build /build ENV SQLFLOW_PARSER_SERVER_PORT=12300 ENV SQLFLOW_PARSER_SERVER_LOADING_PATH="/usr/local/sqlflow/java" -RUN python3 -m pip install --quiet /build/couler*.whl /build/fluid*.whl \ - && mv /build/sqlflowserver /build/sqlflow /build/step /usr/local/bin/ \ - && mkdir -p $SQLFLOW_PARSER_SERVER_LOADING_PATH \ - && mv /build/*.jar $SQLFLOW_PARSER_SERVER_LOADING_PATH +RUN python3 -m pip install --quiet /build/couler*.whl /build/fluid*.whl && \ + mv /build/sqlflowserver /build/sqlflow /build/step /usr/local/bin/ && \ + mkdir -p $SQLFLOW_PARSER_SERVER_LOADING_PATH && \ + mv /build/*.jar $SQLFLOW_PARSER_SERVER_LOADING_PATH && \ + apk del --purge py3-pip && \ + rm -rf /build # Install kubectl for submitting argo workflow -RUN apt-get -qq update && apt-get -qq install -y axel sudo COPY scripts/travis/export_k8s_vars.sh /usr/local/bin/ COPY scripts/travis/install_kubectl.sh /usr/local/bin/ RUN bin/bash -c 'source export_k8s_vars.sh && install_kubectl.sh' diff --git a/docker/step/Dockerfile b/docker/step/Dockerfile index 07052ec41c..b6d652a432 100644 --- a/docker/step/Dockerfile +++ b/docker/step/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:18.04 +FROM ubuntu:18.04 as base # This script assume we are at sqlflow root directory and the directory is already built by sqlflow:dev # The default source archive.ubuntu.com is busy and slow. We use the following source makes docker build running faster. @@ -11,35 +11,56 @@ RUN /bin/bash -c 'source find_fastest_resources.sh \ && echo "Choose the fastest PIP source ..." \ && choose_fastest_pip_source' && \ apt-get update && \ - apt-get -qq install -y openjdk-8-jre-headless wget unzip build-essential libmysqlclient-dev python3 python3-pip && \ - wget -q http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/119096/cn_zh/1557995455961/odpscmd_public.zip && \ - unzip -qq odpscmd_public.zip -d /usr/local/odpscmd && \ - ln -s /usr/local/odpscmd/bin/odpscmd /usr/local/bin/odpscmd && \ - rm -rf odpscmd_public.zip && \ + apt-get -qq install -y --no-install-recommends openjdk-8-jre-headless python3 libmysqlclient20 python3-idna libgomp1 python3-setuptools && \ ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime && \ apt-get install -y tzdata > /dev/null && \ dpkg-reconfigure --frontend noninteractive tzdata && \ - ln -s /usr/bin/python3 /usr/bin/python && \ + ln -s /usr/bin/python3 /usr/bin/python + +# Build python wheels in sub stage so we can +# keep the outcome and discard the build tool-chain +FROM base as builder +RUN mkdir /install +WORKDIR /install + +ENV PATH="${PATH}:/install/bin" +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get -qq install -y wget unzip build-essential libmysqlclient-dev python3-pip && \ ln -s /usr/bin/pip3 /usr/bin/pip && \ - bash -c "pip install numpy==1.16.1 \ - tensorflow==2.0.0b1 \ + pip install --upgrade pip && \ + wget -q http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/119096/cn_zh/1557995455961/odpscmd_public.zip && \ + mkdir -p /install/local/odpscmd && \ + unzip -qq odpscmd_public.zip -d /install/local/odpscmd && \ + rm -rf odpscmd_public.zip + +ADD build/sqlflow_models-0.0.1-py3-none-any.whl / +RUN bash -c 'pip install --no-cache-dir --prefix=/install \ + /sqlflow_models-0.0.1-py3-none-any.whl \ + six==1.15.0 \ mysqlclient==1.4.4 \ impyla==0.16.0 \ pyodps==0.8.3 \ oss2==2.9.0 \ xgboost==0.90 \ - shap==0.30.1 \ plotille==3.7 \ seaborn==0.9.0 \ dill==0.3.0 \ - sklearn2pmml==0.56.0" + sklearn2pmml==0.56.0 \ + shap==0.30.1' + +RUN py3clean /install /usr/lib/python3.6 +# Copy last stage's output, mostly python libs, to /usr +FROM base +COPY --from=builder /install /usr/ ADD build/step /usr/bin/ ADD build/*.jar /opt/sqlflow/parser/ ADD python/sqlflow_submitter /opt/sqlflow/python/sqlflow_submitter/ ADD python/symbol_extractor.py /opt/sqlflow/python/ ADD python/plotille_text_backend.py /opt/sqlflow/python/ -ADD build/models/sqlflow_models /opt/sqlflow/python/sqlflow_models/ -ENV PYTHONPATH /opt/sqlflow/python + +ENV PATH "${PATH}:/usr/local/odpscmd/bin" +ENV PYTHONPATH "${PYTHONPATH}:/usr/lib/python3.6/site-packages:/opt/sqlflow/python" +