Skip to content

Commit 5d0f9d3

Browse files
author
yi.wu
committed
update docker build scripts and readme
1 parent c9d26cb commit 5d0f9d3

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

paddle/scripts/docker/README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,47 +78,50 @@ The following commands check out the source code to the host and build the devel
7878
```bash
7979
git clone https://github.com/PaddlePaddle/Paddle paddle
8080
cd paddle
81-
docker build -t paddle:dev [--build-arg UBUNTU_MIRROR=mirror://mirrors.ubuntu.com/mirrors.txt] .
81+
docker build -t paddle:dev .
8282
```
8383

84-
The `docker build` command assumes that `Dockerfile` is in the root source tree. Note that in this design, this `Dockerfile` is this only one in our repo. Add `--build-arg UBUNTU_MIRROR=mirror://mirrors.ubuntu.com/mirrors.txt`
85-
if you want to use ubuntu mirrors to speed up the build.
84+
The `docker build` command assumes that `Dockerfile` is in the root source tree. Note that in this design, this `Dockerfile` is this only one in our repo.
8685

86+
Users can specify a Ubuntu mirror server for faster downloading:
87+
88+
```bash
89+
docker build -t paddle:dev --build-arg UBUNTU_MIRROR=mirror://mirrors.ubuntu.com/mirrors.txt .
90+
```
8791

8892
### Build PaddlePaddle from Source Code
8993

9094
Given the development image `paddle:dev`, the following command builds PaddlePaddle from the source tree on the development computer (host):
9195

9296
```bash
93-
docker run -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_AVX=ON" \
94-
-e "TEST=ON" -e "BUILD_AND_INSTALL=ON" [-e "DELETE_BUILD_CACHE=ON"] paddle:dev
97+
docker run -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_AVX=ON" -e "TEST=OFF" \
98+
-e "BUILD_AND_INSTALL=ON" -e "DELETE_BUILD_CACHE=ON" paddle:dev
9599
```
96100

97101
This command mounts the source directory on the host into `/paddle` in the container, so the default entry point of `paddle:dev`, `build.sh`, could build the source code with possible local changes. When it writes to `/paddle/build` in the container, it writes to `$PWD/build` on the host indeed.
98102

99103
`build.sh` builds the following:
100104

101105
- PaddlePaddle binaries,
102-
- `$PWD/build/paddle-<version>.deb` for production installation, and
106+
- `$PWD/dist/<cpu|gpu|cpu-noavx|gpu-noavx>/paddle-<version>.deb` for production installation, and
103107
- `$PWD/build/Dockerfile`, which builds the production Docker image.
104108

105-
Environment varibles(use `ON` and `OFF` to put the switch on and off):
106-
- `WITH_GPU`: build paddle with gpu driver and libraries.
107-
- `WITH_AVX`: only lagacy hardwares without avx or sse or other [SIMD](https://en.wikipedia.org/wiki/SIMD) need to put it to "OFF"
108-
- `TEST`: test after build
109-
- `BUILD_AND_INSTALL`: put this to "OFF" if you don't really want to build, used to generate production Dockerfiles.
110-
- `DELETE_BUILD_CACHE`: put this to "ON" when build paddle for multiple times, third_party will not download and build again.
109+
Users can specify the following Docker build arguments with either "ON" or "OFF" value:
110+
- `WITH_GPU`: ***Required***. Generates NVIDIA CUDA GPU code and relies on CUDA libraries.
111+
- `WITH_AVX`: ***Required***. Set to "OFF" prevents from generating AVX instructions. If you don't know what is AVX, you might want to set "ON".
112+
- `TEST`: ***Optional, default ON***. Build unit tests and run them after building.
113+
- `BUILD_AND_INSTALL`: ***Optional, default ON***. Run `make` and `make install`.
114+
- `DELETE_BUILD_CACHE`: ***Optional, default ON***. If set to "ON", the building script will delete, download, and re-build third party libraries.
111115

112116
### Build the Production Docker Image
113117

114118
The following command builds the production image:
115119

116120
```bash
117-
docker build -t paddle -f build/Dockerfile[.cpu|.gpu|.noavx|.gpu-noavx] .
121+
docker build -t paddle -f build/Dockerfile .
118122
```
119123

120-
There are 4 different branch of the production image: cpu, gpu, noavx and gpu-noavx.
121-
These images are made to minimal size -- they includes binary `paddle`, the shared library `libpaddle.so`, and Python runtime.
124+
This production image is minimal -- it includes binary `paddle`, the shared library `libpaddle.so`, and Python runtime.
122125

123126
### Run PaddlePaddle Applications
124127

paddle/scripts/docker/build.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,32 @@ mkdir -p /paddle/dist/gpu-noavx
1515
if [ ${WITH_GPU} == "ON" ]; then
1616
BASE_IMAGE="nvidia/cuda:7.5-cudnn5-runtime-ubuntu14.04"
1717
# additional packages to install when building gpu images
18-
GPU_DOCKER_PKG="python-pip"
18+
GPU_DOCKER_PKG="python-pip python-dev"
1919
if [ ${WITH_AVX} == "ON" ]; then
2020
DEB_PATH="dist/gpu/"
21-
DOCKER_SUFFIX="gpu"
2221
else
2322
DEB_PATH="dist/gpu-noavx/"
24-
DOCKER_SUFFIX="gpu-noavx"
2523
fi
2624
else
2725
BASE_IMAGE="python:2.7.13-slim"
2826
if [ ${WITH_AVX} == "ON" ]; then
2927
DEB_PATH="dist/cpu/"
30-
DOCKER_SUFFIX="cpu"
3128
else
3229
DEB_PATH="dist/cpu-noavx/"
33-
DOCKER_SUFFIX="noavx"
3430
fi
3531
fi
3632
# If Dockerfile.* sets BUILD_AND_INSTALL to 'ON', it would have copied
3733
# source tree to /paddle, and this scripts should build it into
3834
# /paddle/build.
39-
if [[ ${BUILD_AND_INSTALL:-OFF} == 'ON' ]]; then
35+
if [[ ${BUILD_AND_INSTALL:-ON} == 'ON' ]]; then
4036
if [[ ${WITH_GPU:-OFF} == 'ON' ]]; then
4137
ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so /usr/lib/libcudnn.so
4238
fi
4339

4440
mkdir -p /paddle/build # -p means no error if exists
4541
cd /paddle/build
4642
# clean local cmake and third_party cache
47-
if [ ${DELETE_BUILD_CACHE} == 'ON' ]; then
43+
if [ ${DELETE_BUILD_CACHE:-ON} == 'ON' ]; then
4844
rm -rf * && rm -rf ../third_party
4945
fi
5046
cmake .. \
@@ -54,8 +50,12 @@ if [[ ${BUILD_AND_INSTALL:-OFF} == 'ON' ]]; then
5450
-DWITH_SWIG_PY=ON \
5551
-DCUDNN_ROOT=/usr/ \
5652
-DWITH_STYLE_CHECK=OFF \
53+
-DON_COVERALLS=${TEST:-ON} \
5754
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
5855
make -j `nproc`
56+
if [ ${TEST:-ON} == "ON" ]; then
57+
make coveralls
58+
fi
5959
make install
6060
# generate deb package for current build
6161
# FIXME(typhoonzero): should we remove paddle/scripts/deb ?
@@ -106,7 +106,7 @@ else
106106
MIRROR_UPDATE="\\"
107107
fi
108108

109-
cat > /paddle/build/Dockerfile.${DOCKER_SUFFIX} <<EOF
109+
cat > /paddle/build/Dockerfile <<EOF
110110
FROM ${BASE_IMAGE}
111111
MAINTAINER PaddlePaddle Authors <[email protected]>
112112
@@ -116,7 +116,7 @@ ARG WITH_DOC
116116
ARG WITH_STYLE_CHECK
117117
118118
ENV WITH_GPU=${WITH_GPU}
119-
ENV WITH_AVX=\${WITH_AVX:-ON}
119+
ENV WITH_AVX=${WITH_AVX}
120120
ENV WITH_DOC=\${WITH_DOC:-OFF}
121121
ENV WITH_STYLE_CHECK=\${WITH_STYLE_CHECK:-OFF}
122122
@@ -127,14 +127,14 @@ ENV LANG en_US.UTF-8
127127
128128
RUN ${MIRROR_UPDATE}
129129
apt-get update && \
130-
apt-get install -y libgfortran3 ${GPU_DOCKER_PKG} && \
130+
apt-get install -y libgfortran3 libpython2.7 ${GPU_DOCKER_PKG} && \
131131
apt-get clean -y && \
132132
pip install --upgrade pip && \
133-
pip install -U 'protobuf==3.1.0' requests
134-
RUN pip install numpy
133+
pip install -U 'protobuf==3.1.0' requests numpy
135134
# Use different deb file when building different type of images
136135
ADD \$PWD/${DEB_PATH}*.deb /usr/local/opt/paddle/deb/
137-
RUN dpkg --force-all -i /usr/local/opt/paddle/deb/*.deb && rm -f /usr/local/opt/paddle/deb/*.deb
136+
# run paddle version to install python packages first
137+
RUN dpkg -i /usr/local/opt/paddle/deb/*.deb && rm -f /usr/local/opt/paddle/deb/*.deb && paddle version
138138
139139
ENV PATH="/usr/local/opt/paddle/bin/:${PATH}"
140140
# default command shows the paddle version and exit

0 commit comments

Comments
 (0)