Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit f26e388

Browse files
authored
Merge pull request #122 from facebookresearch/docker-jenkins
Refactor dockerfiles and install jenkins user
2 parents 4569d12 + 9cad8b7 commit f26e388

File tree

16 files changed

+502
-7
lines changed

16 files changed

+502
-7
lines changed

.jenkins/build.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
source /etc/lsb-release
6+
7+
# condition: if 14.04 and conda, conda install pytorch and build
8+
# condition: if 16.04 and conda, conda install pytorch and build
9+
# condition: if any and non-conda, simply build TC from scratch
10+
11+
if [[ "$DISTRIB_RELEASE" == 14.04 ]]; then
12+
if which conda &> /dev/null; then
13+
echo "Building TC in conda env"
14+
conda install -y -c pytorch pytorch
15+
conda install -y pyyaml
16+
WITH_PYTHON_C2=OFF CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 BUILD_TYPE=Release ./build.sh --all
17+
else
18+
echo "Building TC in non-conda env"
19+
WITH_PYTHON_C2=OFF CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 BUILD_TYPE=Release ./build.sh --all
20+
fi
21+
fi
22+
23+
if [[ "$DISTRIB_RELEASE" == 16.04 ]]; then
24+
if which conda &> /dev/null; then
25+
echo "Building TC in conda env"
26+
conda install -y pytorch cuda90 -c pytorch
27+
conda install -y pyyaml
28+
WITH_PYTHON_C2=OFF CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 BUILD_TYPE=Release ./build.sh --all
29+
else
30+
echo "Building TC in non-conda env"
31+
WITH_PYTHON_C2=OFF CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 BUILD_TYPE=Release ./build.sh --all
32+
fi
33+
fi

.jenkins/run_test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
source /etc/lsb-release
6+
7+
# condition: if 14.04 and conda, also run python tests
8+
# condition: if 16.04 and conda, run only python tests
9+
# condition: if any and non-conda, run test.sh only
10+
11+
if [[ "$DISTRIB_RELEASE" == 14.04 ]]; then
12+
echo "Running TC backend tests"
13+
./test.sh
14+
if which conda &> /dev/null; then
15+
source activate
16+
echo "Running TC PyTorch tests"
17+
./test_python/run_test.sh
18+
fi
19+
fi
20+
21+
if [[ "$DISTRIB_RELEASE" == 16.04 ]]; then
22+
if which conda &> /dev/null; then
23+
echo "Running TC PyTorch tests"
24+
source activate
25+
./test_python/run_test.sh
26+
else
27+
echo "Running TC backend tests"
28+
./test.sh
29+
fi
30+
fi

docker/README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
11
# How to build Tensor Comprehensions docker images
22

33
Tensor Comprehensions supports gcc4.8, gcc5, cuda8-cudnn6, cuda9-cudnn7, Xenial, Trusty
4-
and building in Conda vs no conda environment. Below are the steps you can follow
5-
to build the images for various combinations. The docker image is built in a ladder
6-
manner so as to reuse the images. Steps:
4+
and building in Conda/ Non-conda environment. Below are the steps you can follow
5+
to build the images for various combinations. This directory contains everything needed to build the Docker images that are used in our CI as well. The `Dockerfile`s are parameterized to build the image based on the build environment. The different configurations are identified by a freeform string that we call a build environment. This string is persisted in each image as the BUILD_ENVIRONMENT environment variable.
6+
7+
## Supported Build environments
8+
9+
Non-conda env and no python installs:
10+
11+
`linux-trusty-gcc4.8-cuda8-cudnn7-py3`
12+
13+
`linux-xenial-gcc5-cuda9-cudnn7-py3`
14+
15+
Conda env with PyTorch conda install:
16+
17+
`linux-trusty-gcc4.8-cuda8-cudnn7-py3-conda` [Run both C++ and Python tests]
18+
19+
`linux-xenial-gcc5-cuda9-cudnn7-py3-conda` [Run only Python tests for now]
20+
21+
See `docker_build.sh` for a full list of terms that are extracted from the build environment into parameters for the image build.
22+
23+
## Contents
24+
25+
`docker_build.sh` -- dispatch script to launch all builds
26+
27+
`common` -- scripts used to execute individual Docker build stages
28+
29+
`ubuntu-cuda` -- Dockerfile for Ubuntu image with CUDA support in non-conda env
30+
31+
`ubuntu-cuda-conda` -- Dockerfile for Ubuntu image with CUDA support in non-conda env
32+
33+
## Steps to build docker image
734

835
**NOTE**: You need to have docker installed on your system. Follow the instructions
936
on docker website to install it, if you don't have docker already.
@@ -34,20 +61,23 @@ need to build images for some other combination, the steps are still valid, just
3461
make sure to change the paths below to fit your case.
3562

3663
```Shell
37-
docker build -t tensorcomprehensions/linux-trusty-gcc4.8-cuda8-cudnn6-py3-conda .
64+
image=linux-trusty-gcc4.8-cuda8-cudnn7-py3-conda ./docker_build.sh
3865
```
3966

4067
This will build the image for the above permutation and then we can test this image
4168

4269
6. Test the image
4370

71+
run `docker images` and get the `IMAGE_ID` for the image we just built.
72+
4473
```Shell
45-
docker run --runtime=nvidia -i -t tensorcomprehensions/linux-trusty-gcc4.8-cuda8-cudnn6-py3-conda:2
74+
docker run --runtime=nvidia -i -t ${IMAGE_ID}
4675
# now clone the TC repo
4776
cd $HOME && git clone https://github.com/facebookresearch/TensorComprehensions.git --recursive && cd TensorComprehensions
4877
# build TC
78+
conda install -y -c pytorch pytorch
4979
WITH_PYTHON_C2=OFF CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 ./build.sh --all
5080
# Test the TC build is fine
51-
./test_cpu.sh
5281
./test.sh
82+
./test_python/run_test.sh
5383
```

docker/linux-xenial-gcc5-cuda9-cudnn7-py3-conda/Dockerfile renamed to docker/archive/linux-xenial-gcc5-cuda9-cudnn7-py3-conda/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ RUN ln -s /usr/local/cuda/targets/x86_64-linux/lib/stubs/libcuda.so /usr/local/c
4141
ENV LD_LIBRARY_PATH /usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib/stubs/:$LD_LIBRARY_PATH
4242
ENV PATH /usr/local/bin:/usr/local/cuda/bin:$PATH
4343

44-
# Conda setup
44+
# Anaconda3 setup
4545
WORKDIR /conda-install
4646
RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh &&\
4747
wget --quiet https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh -O anaconda.sh && \

docker/common/add_jenkins_user.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# Mirror jenkins user in container
6+
echo "jenkins:x:$JENKINS_UID:$JENKINS_GID::/var/lib/jenkins:" >> /etc/passwd
7+
echo "jenkins:x:$JENKINS_GID:" >> /etc/group
8+
9+
# Create $HOME
10+
mkdir -p /var/lib/jenkins
11+
chown jenkins:jenkins /var/lib/jenkins
12+
mkdir -p /var/lib/jenkins/.ccache
13+
chown jenkins:jenkins /var/lib/jenkins/.ccache
14+
15+
# Allow writing to /usr/local (for make install)
16+
chown jenkins:jenkins /usr/local
17+
18+
# Allow sudo
19+
echo 'jenkins ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/jenkins

docker/common/install_base.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# Install common dependencies
6+
apt-get update
7+
apt-get install -y --no-install-recommends \
8+
curl \
9+
make \
10+
git \
11+
ssh \
12+
realpath \
13+
wget \
14+
unzip \
15+
vim \
16+
automake \
17+
libtool \
18+
valgrind \
19+
subversion \
20+
libgtest-dev \
21+
libz-dev \
22+
libgmp3-dev \
23+
libyaml-dev \
24+
libgoogle-glog-dev \
25+
ca-certificates \
26+
software-properties-common \
27+
build-essential
28+
29+
# setup gcc
30+
add-apt-repository ppa:ubuntu-toolchain-r/test
31+
apt-get update
32+
apt-get install -y --no-install-recommends libcilkrts5 gcc-$GCC_VERSION g++-$GCC_VERSION
33+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 50
34+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION 50
35+
36+
export CC=/usr/bin/gcc
37+
export CXX=/usr/bin/g++
38+
39+
# install cmake - this unifies trusty/xenial cmake version > 3.4.3
40+
[ -n "$CMAKE_VERSION" ]
41+
42+
# Turn 3.6.3 into v3.6
43+
path=$(echo "${CMAKE_VERSION}" | sed -e 's/\([0-9].[0-9]\+\).*/v\1/')
44+
file="cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz"
45+
# Download and install specific CMake version in /usr/local
46+
pushd /tmp
47+
curl -Os "https://cmake.org/files/${path}/${file}"
48+
tar -C /usr/local --strip-components 1 --no-same-owner -zxf cmake-*.tar.gz
49+
rm -f cmake-*.tar.gz
50+
popd
51+
52+
53+
# LLVM+Clang-Tapir5.0
54+
export LLVM_SOURCES=/tmp/llvm_sources-tapir5.0
55+
mkdir -p $LLVM_SOURCES
56+
pushd $LLVM_SOURCES
57+
58+
export CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0
59+
export CMAKE_VERSION=cmake
60+
61+
git clone --recursive https://github.com/wsmoses/Tapir-LLVM llvm && \
62+
mkdir -p ${LLVM_SOURCES}/llvm_build && cd ${LLVM_SOURCES}/llvm_build && \
63+
${CMAKE_VERSION} -DLLVM_ENABLE_EH=ON \
64+
-DLLVM_ENABLE_OCAMLDOC=OFF \
65+
-DLLVM_INSTALL_OCAMLDOC_HTML_DIR=/tmp \
66+
-DLLVM_OCAML_INSTALL_PATH=/tmp \
67+
-DCMAKE_INSTALL_PREFIX=${CLANG_PREFIX} \
68+
-DLLVM_TARGETS_TO_BUILD=X86 \
69+
-DCOMPILER_RT_BUILD_CILKTOOLS=OFF \
70+
-DLLVM_ENABLE_CXX1Y=ON \
71+
-DLLVM_ENABLE_TERMINFO=OFF \
72+
-DLLVM_BUILD_TESTS=OFF \
73+
-DLLVM_ENABLE_ASSERTIONS=ON \
74+
-DCMAKE_BUILD_TYPE=Release \
75+
-DLLVM_BUILD_LLVM_DYLIB=ON \
76+
-DLLVM_ENABLE_RTTI=ON ../llvm/
77+
78+
make -j"$(nproc)" -s && make install -j"$(nproc)" -s
79+
80+
popd
81+
rm -Rf ${LLVM_SOURCES}
82+
83+
# Cleanup package manager
84+
apt-get autoclean && apt-get clean
85+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

docker/common/install_conda.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
export TEMP_INSTALL=/tmp/conda-install
6+
mkdir -p $TEMP_INSTALL
7+
8+
pushd $TEMP_INSTALL
9+
10+
echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh
11+
wget --quiet https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh -O anaconda.sh
12+
chmod +x anaconda.sh
13+
/bin/bash ./anaconda.sh -b -p /opt/conda
14+
15+
rm anaconda.sh
16+
17+
popd
18+
19+
export PATH=/opt/conda/bin:$PATH
20+
21+
/opt/conda/bin/conda install numpy decorator six future cmake pyyaml
22+
23+
which conda
24+
conda --version
25+
which python
26+
python --version
27+
28+
# Cleanup package manager
29+
apt-get autoclean && apt-get clean
30+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

0 commit comments

Comments
 (0)