build.sh 4.2 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7 8 9
#!/bin/bash

function abort(){
    echo "An error occurred. Exiting..." 1>&2
    exit 1
}

trap 'abort' 0
set -e
Y
yi.wu 已提交
10 11 12 13 14 15 16
mkdir -p /paddle/dist/cpu
mkdir -p /paddle/dist/gpu
mkdir -p /paddle/dist/cpu-noavx
mkdir -p /paddle/dist/gpu-noavx
# Set BASE_IMAGE and DEB_PATH according to env variables
if [ ${WITH_GPU} == "ON" ]; then
  BASE_IMAGE="nvidia/cuda:7.5-cudnn5-runtime-ubuntu14.04"
Y
yi.wu 已提交
17
  # additional packages to install when building gpu images
Y
yi.wu 已提交
18
  GPU_DOCKER_PKG="python-pip python-dev"
Y
yi.wu 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31
  if [ ${WITH_AVX} == "ON" ]; then
    DEB_PATH="dist/gpu/"
  else
    DEB_PATH="dist/gpu-noavx/"
  fi
else
  BASE_IMAGE="python:2.7.13-slim"
  if [ ${WITH_AVX} == "ON" ]; then
    DEB_PATH="dist/cpu/"
  else
    DEB_PATH="dist/cpu-noavx/"
  fi
fi
32 33 34
# If Dockerfile.* sets BUILD_AND_INSTALL to 'ON', it would have copied
# source tree to /paddle, and this scripts should build it into
# /paddle/build.
Y
yi.wu 已提交
35
if [[ ${BUILD_AND_INSTALL:-ON} == 'ON' ]]; then
36 37 38 39 40
    if [[ ${WITH_GPU:-OFF} == 'ON' ]]; then
	ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so /usr/lib/libcudnn.so
    fi

    mkdir -p /paddle/build # -p means no error if exists
41
    cd /paddle/build
L
liaogang 已提交
42
    # clean local cmake and third_party cache
Y
yi.wu 已提交
43
    if [ ${DELETE_BUILD_CACHE:-ON} == 'ON' ]; then
44 45
      rm -rf * && rm -rf ../third_party
    fi
46
    cmake .. \
L
liaogang 已提交
47
	  -DWITH_DOC=${WITH_DOC:-OFF} \
48 49 50 51 52
	  -DWITH_GPU=${WITH_GPU:-OFF} \
	  -DWITH_AVX=${WITH_AVX:-OFF} \
	  -DWITH_SWIG_PY=ON \
	  -DCUDNN_ROOT=/usr/ \
	  -DWITH_STYLE_CHECK=OFF \
Y
yi.wu 已提交
53
    -DON_COVERALLS=${TEST:-ON} \
54 55
	  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
    make -j `nproc`
Y
yi.wu 已提交
56 57 58
    if [ ${TEST:-ON} == "ON" ]; then
      make coveralls
    fi
59
    make install
Y
yi.wu 已提交
60 61
    # generate deb package for current build
    # FIXME(typhoonzero): should we remove paddle/scripts/deb ?
62 63 64
    # FIXME: CPACK_DEBIAN_PACKAGE_DEPENDS removes all dev dependencies, must
    # install them in docker
    cpack -D CPACK_GENERATOR='DEB' -D CPACK_DEBIAN_PACKAGE_DEPENDS="" ..
Y
yi.wu 已提交
65
    mv /paddle/build/*.deb /paddle/${DEB_PATH}
66

L
liaogang 已提交
67
    if [[ ${BUILD_WOBOQ:-OFF} == 'ON' ]]; then
Y
yi.wu 已提交
68
        apt-get install -y clang-3.8 llvm-3.8 libclang-3.8-dev
L
liaogang 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        # Install woboq_codebrowser.
        git clone https://github.com/woboq/woboq_codebrowser /woboq
        cd /woboq
        cmake -DLLVM_CONFIG_EXECUTABLE=/usr/bin/llvm-config-3.8 \
        -DCMAKE_BUILD_TYPE=Release \
        .
        make

        export WOBOQ_OUT=/usr/share/nginx/html/paddle
        export BUILD_DIR=/paddle/build
        mkdir -p $WOBOQ_OUT
        cp -rv /woboq/data $WOBOQ_OUT/../data
        /woboq/generator/codebrowser_generator \
        -b /paddle/build \
        -a \
        -o $WOBOQ_OUT \
        -p paddle:/paddle
        /woboq/indexgenerator/codebrowser_indexgenerator $WOBOQ_OUT
        cd /woboq
        make clean
    fi

    pip install /usr/local/opt/paddle/share/wheels/py_paddle*linux*.whl
    pip install /usr/local/opt/paddle/share/wheels/paddle*.whl
93
    paddle version
94 95 96 97 98 99

    if [[ ${DOCKER_BUILD:-FALSE} == 'TRUE' ]]; then
	# reduce docker image size
	rm -rf /paddle/build
	rm -rf /usr/local/opt/paddle/share/wheels/
    fi
Z
zhangjinchao01 已提交
100
fi
Y
yuyang18 已提交
101

Y
yi.wu 已提交
102 103 104 105 106 107 108
# generate production docker image Dockerfile
if [ ${USE_MIRROR} ]; then
  MIRROR_UPDATE="sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \\"
else
  MIRROR_UPDATE="\\"
fi

Y
yi.wu 已提交
109
cat > /paddle/build/Dockerfile <<EOF
Y
yi.wu 已提交
110 111 112 113 114 115 116 117 118
FROM ${BASE_IMAGE}
MAINTAINER PaddlePaddle Authors <paddle-dev@baidu.com>

# ENV variables
ARG WITH_AVX
ARG WITH_DOC
ARG WITH_STYLE_CHECK

ENV WITH_GPU=${WITH_GPU}
Y
yi.wu 已提交
119
ENV WITH_AVX=${WITH_AVX}
Y
yi.wu 已提交
120 121 122 123 124 125 126 127 128 129
ENV WITH_DOC=\${WITH_DOC:-OFF}
ENV WITH_STYLE_CHECK=\${WITH_STYLE_CHECK:-OFF}

ENV HOME /root
ENV LANG en_US.UTF-8

# Use Fix locales to en_US.UTF-8

RUN ${MIRROR_UPDATE}
    apt-get update && \
Y
yi.wu 已提交
130
    apt-get install -y libgfortran3 libpython2.7 ${GPU_DOCKER_PKG} && \
Y
yi.wu 已提交
131 132
    apt-get clean -y && \
    pip install --upgrade pip && \
Y
yi.wu 已提交
133
    pip install -U 'protobuf==3.1.0' requests numpy
Y
yi.wu 已提交
134 135
# Use different deb file when building different type of images
ADD \$PWD/${DEB_PATH}*.deb /usr/local/opt/paddle/deb/
Y
yi.wu 已提交
136 137
# run paddle version to install python packages first
RUN dpkg -i /usr/local/opt/paddle/deb/*.deb && rm -f /usr/local/opt/paddle/deb/*.deb && paddle version
Y
yi.wu 已提交
138 139 140 141 142 143

ENV PATH="/usr/local/opt/paddle/bin/:${PATH}"
# default command shows the paddle version and exit
CMD ["paddle", "version"]
EOF

Z
zhangjinchao01 已提交
144
trap : 0