-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Thinner docker image #1598
Changes from 3 commits
a6eec02
f66fd44
1b269db
12a3af1
3298d30
c1d5aaa
1ab419a
653c981
0b4d456
e8d33be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
*.DS_Store | ||
build/ | ||
build/paddle/math | ||
build/paddle/utils | ||
build/paddle/gserver | ||
*.user | ||
|
||
.vscode | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/bin/bash | ||
set -e | ||
ARCH=$(uname -i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 什么时候会调用这个脚本呢?我看Dockerfile里调用的是 paddle/scripts/docker/build.sh 。 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ~ | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不删除build文件夹有坏处吗?好处应该可以加速build过程。好像make可以自动追踪什么文件被改变了,感觉不会有问题? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 之前编译遇到不删除build和thirdparty,导致protobuf的依赖没被cmake找到。或许可以只删除CmakeCache? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里这些变量都写死了,那如果要支持 GPU怎么办呢? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个脚本是会用 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 * | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不是很了解cpack怎么工作的,这里和以后的几处 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. build的结果是不是就放在host的文件系统里就行了? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
``` |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 然后命令结束的时候对应的返回码应该也是正确的( There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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"] |
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"] |
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"] |
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"] |
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"] |
There was a problem hiding this comment.
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目录。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
改错了。现在使用deb包安装,所以可以忽略build目录了。