Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thinner docker image #1598

Merged
merged 10 commits into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.DS_Store
build/
build/paddle/math
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git必须忽略整个build目录吧。

.dockerignore 也应该忽略整个build目录,因为实际上使用的是host上的build目录。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

改错了。现在使用deb包安装,所以可以忽略build目录了。

build/paddle/utils
build/paddle/gserver
*.user

.vscode
Expand Down
18 changes: 13 additions & 5 deletions paddle/scripts/deb/build_scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -e
ARCH=$(uname -i)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么时候会调用这个脚本呢?我看Dockerfile里调用的是 paddle/scripts/docker/build.sh 。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑在别的PR中删除"deb"这个目录了 @helinwang

apt-get update
apt-get install -y dh-make
cd ~
Expand All @@ -8,28 +9,35 @@ mkdir -p ~/dist/cpu
mkdir -p ~/dist/cpu-noavx
mkdir -p ~/dist/gpu-noavx
cd paddle
mkdir build

# clean build dir and third_party dir cache
rm -rf build third_party
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不删除build文件夹有坏处吗?好处应该可以加速build过程。好像make可以自动追踪什么文件被改变了,感觉不会有问题?
要是用户想要clean build可以执行build.sh之前rm -rf build或者有个参数./build.sh clean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前编译遇到不删除build和thirdparty,导致protobuf的依赖没被cmake找到。或许可以只删除CmakeCache?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白了,没事,这个不影响merge。

mkdir -p build
cd build
cmake .. -DWITH_GPU=OFF -DWITH_SWIG_PY=ON -DWITH_AVX=ON
cmake .. -DWITH_GPU=OFF -DWITH_SWIG_PY=ON -DWITH_AVX=ON -DWITH_SWIG_PY=ON -DWITH_STYLE_CHECK=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里这些变量都写死了,那如果要支持 GPU怎么办呢?

Copy link
Contributor Author

@typhoonzero typhoonzero Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个脚本是会用cpack打包4个deb包,分别对应cpu, cpu-noavx, gpu, gpu-noavx,在制作dockerimage的时候决定使用哪个

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外,后文说到要去掉 paddle/scripts/deb 目录。那这个文件是不是就不需要了?

make -j `nproc`
# FIXME(typhoonzero): add ARCH gpu noavx flag to CPACK_SYSTEM_NAME. Why -D not affect anything?
cpack -D CPACK_GENERATOR='DEB' ..
mv *.deb ~/dist/cpu

rm -rf *
Copy link
Contributor

@helinwang helinwang Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是很了解cpack怎么工作的,这里和以后的几处rm -rf *需要吗?。cmake好像不会受干扰,而且不删掉反而能加速编译过程?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据 #1625 ,考虑直接去掉paddle/scripts/deb目录了,使用docker目录下的build.sh完成

cmake .. -DWITH_GPU=ON -DWITH_SWIG_PY=ON -DWITH_AVX=ON -DCUDNN_ROOT=/usr/
ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so /usr/lib/libcudnn.so
cmake .. -DWITH_GPU=ON -DWITH_SWIG_PY=ON -DWITH_AVX=ON -DCUDNN_ROOT=/usr/ -DWITH_SWIG_PY=ON -DWITH_STYLE_CHECK=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
make -j `nproc`
cpack -D CPACK_GENERATOR='DEB' ..
mv *.deb ~/dist/gpu


rm -rf *
cmake .. -DWITH_GPU=OFF -DWITH_SWIG_PY=ON -DWITH_AVX=OFF
rm -f /usr/lib/libcudnn.so
cmake .. -DWITH_GPU=OFF -DWITH_SWIG_PY=ON -DWITH_AVX=OFF -DWITH_SWIG_PY=ON -DWITH_STYLE_CHECK=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
make -j `nproc`
cpack -D CPACK_GENERATOR='DEB' ..
mv *.deb ~/dist/cpu-noavx

rm -rf *
cmake .. -DWITH_GPU=ON -DWITH_SWIG_PY=ON -DWITH_AVX=OFF -DCUDNN_ROOT=/usr/
ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so /usr/lib/libcudnn.so
cmake .. -DWITH_GPU=ON -DWITH_SWIG_PY=ON -DWITH_AVX=OFF -DCUDNN_ROOT=/usr/ -DWITH_SWIG_PY=ON -DWITH_STYLE_CHECK=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
make -j `nproc`
cpack -D CPACK_GENERATOR='DEB' ..
mv *.deb ~/dist/gpu-noavx
9 changes: 9 additions & 0 deletions paddle/scripts/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Build docker image

We use a docker environment to build paddle binaries and put it into a runtime image `paddle-core` for uses of most cases
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build的结果是不是就放在host的文件系统里就行了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前已经改成这样了,是mount host的目录来build的


***Notice***: do **not** run in this directory, run under the top level of this project like:

```
sh paddle/scripts/docker/buildall.sh
```
31 changes: 31 additions & 0 deletions paddle/scripts/docker/buildall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

BUILD_DIR=$PWD/build
DEB_DIST_DIR=$PWD/dist
VERSION=latest

function build_in_docker() {
if [ ! -d $BUILD_DIR ]; then
mkdir -p $BUILD_DIR
fi
if [ ! -d $DEB_DIST_DIR ]; then
mkdir -p $DEB_DIST_DIR
fi
docker build . -t paddle-build-env -f paddle/scripts/docker/paddle-dev/Dockerfile
# FIXME: need to wait a signal not sleeping
BUILDER=$(docker run -d -v ${PWD}:/root/paddle -v ${DEB_DIST_DIR}:/root/dist paddle-build-env sleep 3600)
# NOTICE: build deb files for real paddle image
docker exec $BUILDER /bin/bash -c "/root/paddle/paddle/scripts/deb/build_scripts/build.sh"
Copy link
Contributor

@helinwang helinwang Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以上两句是不是可以改成

docker run --rm -v ${PWD}:/root/paddle -v ${DEB_DIST_DIR}:/root/dist paddle-build-env bash /root/paddle/paddle/scripts/deb/build_scripts/build.sh

然后命令结束的时候对应的返回码应该也是正确的(docker run ... ; echo $?),
接下来的docker stop $BUILDER && docker rm $BUILDER也可以删掉了。

Copy link
Contributor Author

@typhoonzero typhoonzero Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据 #1625 去掉了buildall.sh 自动build image的过程新开一个PR,使用travis ci完成


docker stop $BUILDER && docker rm $BUILDER
}

function build_paddle_core() {
docker build . -t paddle-core:$VERSION -f paddle/scripts/docker/paddle-core/Dockerfile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reyoung and I worked hard and reduced the number of Docker images. Why we'd need this many Docker images here? That is core for? This differs from the two images as described in our design doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will rename "paddle-core" to paddle. It is the production image

docker build . -t paddle-core:gpu-$VERSION -f paddle/scripts/docker/paddle-core/Dockerfile.gpu
docker build . -t paddle-core:cpu-noavx-$VERSION -f paddle/scripts/docker/paddle-core/Dockerfile.noavx
docker build . -t paddle-core:gpu-noavx-$VERSION -f paddle/scripts/docker/paddle-core/Dockerfile.gpunoavx
}

build_in_docker
build_paddle_core
32 changes: 32 additions & 0 deletions paddle/scripts/docker/paddle-core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:2.7.13-slim
MAINTAINER PaddlePaddle Authors <[email protected]>

# ENV variables
ARG WITH_AVX
ARG WITH_DOC
ARG WITH_STYLE_CHECK

ENV WITH_GPU=OFF
ENV WITH_AVX=${WITH_AVX:-ON}
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 sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \
apt-get update && \
apt-get install -y libgfortran3 && \
apt-get clean -y && \
pip install --upgrade pip && \
pip install -U 'protobuf==3.1.0'
RUN pip install numpy
# Use different deb file when building different type of images
ADD dist/cpu/*.deb /usr/local/opt/paddle/deb/cpu/
RUN dpkg --force-all -i /usr/local/opt/paddle/deb/cpu/*.deb && rm -f /usr/local/opt/paddle/deb/cpu/*.deb

ENV PATH="/usr/local/opt/paddle/bin/:${PATH}"
# default command shows the paddle version and exit
CMD ["paddle", "version"]
32 changes: 32 additions & 0 deletions paddle/scripts/docker/paddle-core/Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM nvidia/cuda:7.5-cudnn5-runtime-ubuntu14.04
MAINTAINER PaddlePaddle Authors <[email protected]>

# ENV variables
ARG WITH_AVX
ARG WITH_DOC
ARG WITH_STYLE_CHECK

ENV WITH_GPU=OFF
ENV WITH_AVX=${WITH_AVX:-ON}
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 sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \
apt-get update && \
apt-get install -y python python-pip libgfortran3 && \
apt-get clean -y && \
pip install --upgrade pip && \
pip install -U 'protobuf==3.1.0'
RUN pip install numpy
# Use different deb file when building different type of images
ADD dist/gpu/*.deb /usr/local/opt/paddle/deb/gpu/
RUN dpkg --force-all -i /usr/local/opt/paddle/deb/gpu/*.deb && rm -f /usr/local/opt/paddle/deb/gpu/*.deb

ENV PATH="/usr/local/opt/paddle/bin/:${PATH}"
# default command shows the paddle version and exit
CMD ["paddle", "version"]
33 changes: 33 additions & 0 deletions paddle/scripts/docker/paddle-core/Dockerfile.gpunoavx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM python:2.7.13-slim
MAINTAINER PaddlePaddle Authors <[email protected]>

# ENV variables
ARG WITH_AVX
ARG WITH_DOC
ARG WITH_STYLE_CHECK

ENV WITH_GPU=OFF
ENV WITH_AVX=${WITH_AVX:-ON}
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 sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \
apt-get update && \
apt-get install -y libgfortran3 && \
apt-get clean -y && \
pip install --upgrade pip && \
pip install -U 'protobuf==3.1.0'
RUN pip install numpy
# Use different deb file when building different type of images
ADD dist/gpu-noavx/*.deb /usr/local/opt/paddle/deb/gpu-noavx/
RUN dpkg --force-all -i /usr/local/opt/paddle/deb/gpu-noavx/*.deb && rm -f /usr/local/opt/paddle/deb/gpu-noavx/*.deb


ENV PATH="/usr/local/opt/paddle/bin/:${PATH}"
# default command shows the paddle version and exit
CMD ["paddle", "version"]
32 changes: 32 additions & 0 deletions paddle/scripts/docker/paddle-core/Dockerfile.noavx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM nvidia/cuda:7.5-cudnn5-runtime-ubuntu14.04
MAINTAINER PaddlePaddle Authors <[email protected]>

# ENV variables
ARG WITH_AVX
ARG WITH_DOC
ARG WITH_STYLE_CHECK

ENV WITH_GPU=OFF
ENV WITH_AVX=${WITH_AVX:-ON}
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 sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \
apt-get update && \
apt-get install -y python python-pip libgfortran3 && \
apt-get clean -y && \
pip install --upgrade pip && \
pip install -U 'protobuf==3.1.0'
RUN pip install numpy
# Use different deb file when building different type of images
ADD dist/cpu-noavx/*.deb /usr/local/opt/paddle/deb/cpu-noavx/
RUN dpkg --force-all -i /usr/local/opt/paddle/deb/cpu-noavx/*.deb && rm -f /usr/local/opt/paddle/deb/cpu-noavx/*.deb

ENV PATH="/usr/local/opt/paddle/bin/:${PATH}"
# default command shows the paddle version and exit
CMD ["paddle", "version"]
53 changes: 53 additions & 0 deletions paddle/scripts/docker/paddle-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# A image for building paddle binaries
# Use cuda devel base image for both cpu and gpu environment
FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
MAINTAINER PaddlePaddle Authors <[email protected]>

ARG DEBIAN_FRONTEND=noninteractive
ARG UBUNTU_MIRROR
RUN /bin/bash -c 'if [[ -n ${UBUNTU_MIRROR} ]]; then sed -i 's#http://archive.ubuntu.com#${UBUNTU_MIRROR}#g' /etc/apt/sources.list; fi'

# ENV variables
ARG BUILD_WOBOQ
ARG BUILD_AND_INSTALL
ARG WITH_AVX
ARG WITH_DOC
ARG WITH_STYLE_CHECK

ENV BUILD_WOBOQ=${BUILD_WOBOQ:-OFF}
ENV BUILD_AND_INSTALL=${BUILD_AND_INSTALL:-OFF}
ENV WITH_GPU=OFF
ENV WITH_AVX=${WITH_AVX:-ON}
ENV WITH_DOC=${WITH_DOC:-OFF}
ENV WITH_STYLE_CHECK=${WITH_STYLE_CHECK:-OFF}

ENV HOME /root

RUN apt-get update && \
apt-get install -y git python-pip python-dev openssh-server bison && \
apt-get install -y wget unzip tar xz-utils bzip2 gzip coreutils && \
apt-get install -y curl sed grep graphviz libjpeg-dev zlib1g-dev && \
apt-get install -y python-numpy python-matplotlib gcc g++ gfortran && \
apt-get install -y automake locales clang-format-3.8 && \
apt-get clean -y

# git credential to skip password typing
RUN git config --global credential.helper store

# Fix locales to en_US.UTF-8
RUN localedef -i en_US -f UTF-8 en_US.UTF-8

RUN pip install --upgrade pip && \
pip install -U 'protobuf==3.1.0' && \
pip install -U wheel pillow BeautifulSoup && \
pip install -U docopt PyYAML sphinx && \
pip install -U sphinx-rtd-theme==0.1.9 recommonmark && \
pip install -U pre-commit 'requests==2.9.2' jupyter

RUN curl -sSL https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz | tar -xz && \
cd cmake-3.4.1 && ./bootstrap && make -j `nproc` && make install && \
cd .. && rm -rf cmake-3.4.1

RUN apt-get install -y swig
# FIXME: wait a long time is OK
CMD ["sleep", "3600"]