Skip to content

Commit 1baca7f

Browse files
authored
Move content in the buildtools repo into paddle repo (#7326)
* Import content from the buildtools repo * Renmae Dockerfile-x86_64 into Dockerfile.x64 * yapf * Remove subdirectory root
1 parent ea782e3 commit 1baca7f

File tree

9 files changed

+585
-0
lines changed

9 files changed

+585
-0
lines changed

tools/manylinux1/Dockerfile.android

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM ubuntu:16.04
2+
MAINTAINER PaddlePaddle Authors <[email protected]>
3+
4+
ARG UBUNTU_MIRROR
5+
RUN /bin/bash -c 'if [[ -n ${UBUNTU_MIRROR} ]]; then sed -i 's#http://archive.ubuntu.com/ubuntu#${UBUNTU_MIRROR}#g' /etc/apt/sources.list; fi'
6+
7+
# ENV variables
8+
ARG ANDROID_ABI
9+
ARG ANDROID_API
10+
11+
ENV ANDROID_ABI=${ANDROID_ABI:-"armeabi-v7a"}
12+
ENV ANDROID_API=${ANDROID_API:-21}
13+
14+
ENV HOME=/root \
15+
ANDROID_NDK_HOME=/opt/android-ndk-linux \
16+
ANDROID_TOOLCHAINS_DIR=/opt/toolchains
17+
18+
RUN apt-get update && \
19+
apt-get install -y \
20+
git python-dev python-pip python-numpy \
21+
wget curl tar unzip gcc g++ locales clang-format-3.8 swig cmake && \
22+
apt-get clean -y
23+
24+
# Install Go and glide
25+
RUN wget -qO- go.tgz https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz | \
26+
tar -xz -C /usr/local && \
27+
mkdir /root/gopath && \
28+
mkdir /root/gopath/bin && \
29+
mkdir /root/gopath/src
30+
ENV GOROOT=/usr/local/go GOPATH=/root/gopath
31+
# should not be in the same line with GOROOT definition, otherwise docker build could not find GOROOT.
32+
ENV PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
33+
34+
# git credential to skip password typing
35+
RUN git config --global credential.helper store
36+
37+
# Fix locales to en_US.UTF-8
38+
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
39+
40+
RUN pip install --upgrade pip && \
41+
pip install -U 'protobuf==3.1.0' && \
42+
pip install -U wheel sphinx && \
43+
pip install pre-commit
44+
45+
# Android NDK
46+
RUN mkdir -p ${ANDROID_TOOLCHAINS_DIR} && \
47+
mkdir -p /opt/android-ndk-tmp && \
48+
cd /opt/android-ndk-tmp && \
49+
wget -q https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip && \
50+
unzip -q android-ndk-r14b-linux-x86_64.zip && \
51+
mv android-ndk-r14b ${ANDROID_NDK_HOME} && \
52+
rm -rf /opt/android-ndk-tmp
53+
54+
CMD ["bash", "/paddle/paddle/scripts/docker/build_android.sh"]
55+

tools/manylinux1/Dockerfile.x64

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# NOTE The manylinux1 policy mandates CentOS-5. We replace it with CentOS-6 in
2+
# order to satisfy the build of capnproto library (a nupic.core dependency),
3+
# which requires some headers and symbols not present on CentOS-5 (e.g.,
4+
# signalfd.h, pipe2, O_NONBLOCK, SOCK_NONBLOCK, etc.). See
5+
# https://github.com/sandstorm-io/capnproto/issues/350.
6+
FROM nvidia/cuda:<baseimg>
7+
MAINTAINER Numenta, based on the ManyLinux project
8+
9+
ENV LC_ALL en_US.UTF-8
10+
ENV LANG en_US.UTF-8
11+
ENV LANGUAGE en_US.UTF-8
12+
ENV PATH /opt/rh/devtoolset-2/root/usr/bin:$PATH
13+
ENV LD_LIBRARY_PATH /opt/rh/devtoolset-2/root/usr/lib64:/opt/rh/devtoolset-2/root/usr/lib:/usr/local/lib64:/usr/local/lib:${LD_LIBRARY_PATH}
14+
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
15+
16+
COPY build_scripts /build_scripts
17+
RUN bash build_scripts/build.sh && rm -r build_scripts
18+
19+
ENV SSL_CERT_FILE=/opt/_internal/certs.pem
20+
21+
# for paddle
22+
RUN wget --no-check-certificate -qO- https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz | \
23+
tar -xz -C /usr/local && \
24+
mkdir /root/gopath && \
25+
mkdir /root/gopath/bin && \
26+
mkdir /root/gopath/src
27+
28+
29+
ENV GOROOT=/usr/local/go GOPATH=/root/gopath
30+
ENV PATH=${GOROOT}/bin:${GOPATH}/bin:${PATH}
31+
32+
# protobuf 3.1.0
33+
RUN cd /opt && wget -q --no-check-certificate https://github.com/google/protobuf/releases/download/v3.1.0/protobuf-cpp-3.1.0.tar.gz && \
34+
tar xzf protobuf-cpp-3.1.0.tar.gz && \
35+
cd protobuf-3.1.0 && ./configure && make -j4 && make install && cd .. && rm -f protobuf-cpp-3.1.0.tar.gz
36+
37+
38+
RUN yum install -y sqlite-devel zlib-devel openssl-devel boost boost-devel pcre-devel vim tk-devel tkinter libtool
39+
40+
RUN wget -O /root/requirements.txt https://raw.githubusercontent.com/PaddlePaddle/Paddle/develop/python/requirements.txt
41+
42+
RUN LD_LIBRARY_PATH=/opt/_internal/cpython-2.7.11-ucs4/lib:${LD_LIBRARY_PATH} /opt/python/cp27-cp27mu/bin/pip install -r /root/requirements.txt && \
43+
LD_LIBRARY_PATH=/opt/_internal/cpython-2.7.11-ucs2/lib:${LD_LIBRARY_PATH} /opt/python/cp27-cp27m/bin/pip install -r /root/requirements.txt && \
44+
go get github.com/Masterminds/glide && \
45+
rm -rf /root/requirements.txt
46+
47+
RUN LD_LIBRARY_PATH=/opt/_internal/cpython-2.7.11-ucs4/lib:${LD_LIBRARY_PATH} /opt/python/cp27-cp27mu/bin/pip install pre-commit 'ipython==5.3.0' opencv-python && \
48+
LD_LIBRARY_PATH=/opt/_internal/cpython-2.7.11-ucs2/lib:${LD_LIBRARY_PATH} /opt/python/cp27-cp27m/bin/pip install pre-commit 'ipython==5.3.0' opencv-python
49+
50+
RUN wget -O /opt/swig-2.0.12.tar.gz https://sourceforge.net/projects/swig/files/swig/swig-2.0.12/swig-2.0.12.tar.gz/download && \
51+
cd /opt && tar xzf swig-2.0.12.tar.gz && cd /opt/swig-2.0.12 && ./configure && make && make install && cd /opt && rm swig-2.0.12.tar.gz
52+
53+
RUN mkdir -p /src && cd /src && git clone https://github.com/NVIDIA/nccl.git nccl && cd nccl &&\
54+
make -j `nproc` install <NCCL_MAKE_OPTS> && cd .. && rm -rf nccl

tools/manylinux1/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# buildtools
2+
3+
We release PaddlePaddle and PaddlePaddle Fluid as shared libraries,
4+
which, we hope could be released as wheel packages on PyPI, so we need
5+
to make sure that the build follows the
6+
[manulinux1](https://www.python.org/dev/peps/pep-0513/) standard.
7+
8+
The manylinux standard suggests building Python modules on an old
9+
system, because that a module would anyway depend on some shared
10+
libraries, and Linux's shared library standard states that those built
11+
with newer version compilers cannot work with those with older
12+
versions. The suggested building environment is as old as CentOS 5.
13+
However, PaddlePaddle relies on CUDA, and the earlies version of
14+
[CentOS works with CUDA is 6](https://hub.docker.com/r/nvidia/cuda/).
15+
So, here we provide a Docker image basing on CentOS 6 and CUDA for
16+
building PaddlePaddle and making the release supports "as-manylinux as
17+
possible." or "sufficiently many Linux" according to [this
18+
discussion](https://mail.python.org/pipermail/wheel-builders/2016-July/000175.html).
19+
20+
The build output of our Docker image includes multiple wheel files --
21+
some contain the CPU-only binary, some others support CUDA; some are
22+
compatible with the cp27m Python ABI, some others with cp27.
23+
24+
To build these wheels, please run the following commands:
25+
26+
```bash
27+
git clone https://github.com/paddlepaddle/paddle
28+
cd paddle/tools/manylinux1
29+
REPO=[yourrepo] ./build_all.sh
30+
```

tools/manylinux1/build_all.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -xe
3+
4+
REPO="${REPO:-typhoon1986}"
5+
6+
# NOTE: version matches are determined!
7+
sed 's/<baseimg>/7.5-cudnn5-devel-centos6/g' Dockerfile.x64 | \
8+
sed 's/<NCCL_MAKE_OPTS>/NVCC_GENCODE="-gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52"/g'> Dockerfile.tmp
9+
docker build -t ${REPO}/paddle_manylinux_devel:cuda7.5_cudnn5 -f Dockerfile.tmp .
10+
docker push ${REPO}/paddle_manylinux_devel:cuda7.5_cudnn5
11+
12+
sed 's/<baseimg>/8.0-cudnn5-devel-centos6/g' Dockerfile.x64 | \
13+
sed 's/<NCCL_MAKE_OPTS>/NVCC_GENCODE="-gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_60,code=compute_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_62,code=sm_62"/g'> Dockerfile.tmp
14+
docker build -t ${REPO}/paddle_manylinux_devel:cuda8.0_cudnn5 -f Dockerfile.tmp .
15+
docker push ${REPO}/paddle_manylinux_devel:cuda8.0_cudnn5
16+
17+
sed 's/<baseimg>/8.0-cudnn7-devel-centos6/g' Dockerfile.x64 | \
18+
sed 's/<NCCL_MAKE_OPTS>/NVCC_GENCODE="-gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_60,code=compute_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_62,code=sm_62"/g'> Dockerfile.tmp
19+
20+
docker build -t ${REPO}/paddle_manylinux_devel:cuda8.0_cudnn7 -f Dockerfile.tmp .
21+
docker push ${REPO}/paddle_manylinux_devel:cuda8.0_cudnn7
22+
23+
sed 's/<baseimg>/9.0-cudnn7-devel-centos6/g' Dockerfile.x64 | \
24+
sed 's/<NCCL_MAKE_OPTS>/NVCC_GENCODE="-gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_60,code=compute_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_62,code=sm_62 -gencode=arch=compute_70,code=sm_70"/g'> Dockerfile.tmp
25+
docker build -t ${REPO}/paddle_manylinux_devel:cuda9.0_cudnn7 -f Dockerfile.tmp .
26+
docker push ${REPO}/paddle_manylinux_devel:cuda9.0_cudnn7
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
# Top-level build script called from Dockerfile
3+
4+
# Stop at any error, show all commands
5+
set -ex
6+
7+
# Python versions to be installed in /opt/$VERSION_NO
8+
# NOTE Only need python 2.7.11 for nupic.core/nupic.bindings at this time, so
9+
# remove others to expedite build and reduce docker image size. The original
10+
# manylinux docker image project builds many python versions.
11+
# NOTE We added back 3.5.1, since auditwheel requires python 3.3+
12+
CPYTHON_VERSIONS="2.7.11 3.5.1"
13+
14+
# openssl version to build, with expected sha256 hash of .tar.gz
15+
# archive
16+
OPENSSL_ROOT=openssl-1.0.2l
17+
OPENSSL_HASH=ce07195b659e75f4e1db43552860070061f156a98bb37b672b101ba6e3ddf30c
18+
EPEL_RPM_HASH=e5ed9ecf22d0c4279e92075a64c757ad2b38049bcf5c16c4f2b75d5f6860dc0d
19+
DEVTOOLS_HASH=a8ebeb4bed624700f727179e6ef771dafe47651131a00a78b342251415646acc
20+
PATCHELF_HASH=d9afdff4baeacfbc64861454f368b7f2c15c44d245293f7587bbf726bfe722fb
21+
CURL_ROOT=curl-7.49.1
22+
CURL_HASH=eb63cec4bef692eab9db459033f409533e6d10e20942f4b060b32819e81885f1
23+
AUTOCONF_ROOT=autoconf-2.69
24+
AUTOCONF_HASH=954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969
25+
26+
# Dependencies for compiling Python that we want to remove from
27+
# the final image after compiling Python
28+
PYTHON_COMPILE_DEPS="zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel"
29+
30+
# Libraries that are allowed as part of the manylinux1 profile
31+
MANYLINUX1_DEPS="glibc-devel libstdc++-devel glib2-devel libX11-devel libXext-devel libXrender-devel mesa-libGL-devel libICE-devel libSM-devel ncurses-devel"
32+
33+
# Get build utilities
34+
MY_DIR=$(dirname "${BASH_SOURCE[0]}")
35+
source $MY_DIR/build_utils.sh
36+
37+
# EPEL support
38+
yum -y install wget curl
39+
curl -sLO https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
40+
check_sha256sum epel-release-6-8.noarch.rpm $EPEL_RPM_HASH
41+
42+
# Dev toolset (for LLVM and other projects requiring C++11 support)
43+
curl -sLO http://people.centos.org/tru/devtools-2/devtools-2.repo
44+
check_sha256sum devtools-2.repo $DEVTOOLS_HASH
45+
mv devtools-2.repo /etc/yum.repos.d/devtools-2.repo
46+
rpm -Uvh --replacepkgs epel-release-6*.rpm
47+
rm -f epel-release-6*.rpm
48+
49+
# Development tools and libraries
50+
yum -y install bzip2 make git patch unzip bison yasm diffutils \
51+
automake which file \
52+
kernel-devel-`uname -r` \
53+
devtoolset-2-binutils devtoolset-2-gcc \
54+
devtoolset-2-gcc-c++ devtoolset-2-gcc-gfortran \
55+
${PYTHON_COMPILE_DEPS}
56+
57+
# Install more recent version of cmake
58+
# curl -O https://cmake.org/files/v3.8/cmake-3.8.1-Linux-x86_64.sh
59+
# /bin/sh cmake-3.8.1-Linux-x86_64.sh --prefix=/usr/local --skip-license
60+
# rm cmake-3.8.1-Linux-x86_64.sh
61+
62+
wget -q https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz && tar xzf cmake-3.5.2.tar.gz && \
63+
cd cmake-3.5.2 && ./bootstrap && \
64+
make -j4 && make install && cd .. && rm cmake-3.5.2.tar.gz
65+
66+
67+
# Install newest autoconf
68+
build_autoconf $AUTOCONF_ROOT $AUTOCONF_HASH
69+
autoconf --version
70+
71+
# Compile the latest Python releases.
72+
# (In order to have a proper SSL module, Python is compiled
73+
# against a recent openssl [see env vars above], which is linked
74+
# statically. We delete openssl afterwards.)
75+
build_openssl $OPENSSL_ROOT $OPENSSL_HASH
76+
mkdir -p /opt/python
77+
build_cpythons $CPYTHON_VERSIONS
78+
79+
PY35_BIN=/opt/python/cp35-cp35m/bin
80+
# NOTE Since our custom manylinux image builds pythons with shared
81+
# libpython, we need to add libpython's dir to LD_LIBRARY_PATH before running
82+
# python.
83+
ORIGINAL_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
84+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}:$(dirname ${PY35_BIN})/lib"
85+
86+
# Our openssl doesn't know how to find the system CA trust store
87+
# (https://github.com/pypa/manylinux/issues/53)
88+
# And it's not clear how up-to-date that is anyway
89+
# So let's just use the same one pip and everyone uses
90+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}:$(dirname ${PY35_BIN})/lib" $PY35_BIN/pip install certifi
91+
ln -s $($PY35_BIN/python -c 'import certifi; print(certifi.where())') \
92+
/opt/_internal/certs.pem
93+
# If you modify this line you also have to modify the versions in the
94+
# Dockerfiles:
95+
export SSL_CERT_FILE=/opt/_internal/certs.pem
96+
97+
# Install newest curl
98+
build_curl $CURL_ROOT $CURL_HASH
99+
rm -rf /usr/local/include/curl /usr/local/lib/libcurl* /usr/local/lib/pkgconfig/libcurl.pc
100+
hash -r
101+
curl --version
102+
curl-config --features
103+
104+
# Now we can delete our built SSL
105+
rm -rf /usr/local/ssl
106+
107+
# Install patchelf (latest with unreleased bug fixes)
108+
curl -sLO https://nipy.bic.berkeley.edu/manylinux/patchelf-0.9njs2.tar.gz
109+
check_sha256sum patchelf-0.9njs2.tar.gz $PATCHELF_HASH
110+
tar -xzf patchelf-0.9njs2.tar.gz
111+
(cd patchelf-0.9njs2 && ./configure && make && make install)
112+
rm -rf patchelf-0.9njs2.tar.gz patchelf-0.9njs2
113+
114+
# Install latest pypi release of auditwheel
115+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}:$(dirname ${PY35_BIN})/lib" $PY35_BIN/pip install auditwheel
116+
ln -s $PY35_BIN/auditwheel /usr/local/bin/auditwheel
117+
118+
# Clean up development headers and other unnecessary stuff for
119+
# final image
120+
yum -y erase wireless-tools gtk2 libX11 hicolor-icon-theme \
121+
avahi freetype bitstream-vera-fonts \
122+
${PYTHON_COMPILE_DEPS} > /dev/null 2>&1
123+
yum -y install ${MANYLINUX1_DEPS}
124+
yum -y clean all > /dev/null 2>&1
125+
yum list installed
126+
# we don't need libpython*.a, and they're many megabytes
127+
find /opt/_internal -name '*.a' -print0 | xargs -0 rm -f
128+
# Strip what we can -- and ignore errors, because this just attempts to strip
129+
# *everything*, including non-ELF files:
130+
find /opt/_internal -type f -print0 \
131+
| xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true
132+
# We do not need the Python test suites, or indeed the precompiled .pyc and
133+
# .pyo files. Partially cribbed from:
134+
# https://github.com/docker-library/python/blob/master/3.4/slim/Dockerfile
135+
find /opt/_internal \
136+
\( -type d -a -name test -o -name tests \) \
137+
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
138+
-print0 | xargs -0 rm -f
139+
140+
for PYTHON in /opt/python/*/bin/python; do
141+
# Add matching directory of libpython shared library to library lookup path
142+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}:$(dirname $(dirname ${PYTHON}))/lib"
143+
144+
# Smoke test to make sure that our Pythons work, and do indeed detect as
145+
# being manylinux compatible:
146+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}:$(dirname $(dirname ${PYTHON}))/lib" $PYTHON $MY_DIR/manylinux1-check.py
147+
# Make sure that SSL cert checking works
148+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}:$(dirname $(dirname ${PYTHON}))/lib" $PYTHON $MY_DIR/ssl-check.py
149+
done
150+
151+
# Restore LD_LIBRARY_PATH
152+
LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}"

0 commit comments

Comments
 (0)