-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
407 lines (360 loc) · 13.1 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
##### Splitting installation into controlled parts:
## - Base container setup (all apt-get + system + ldd extension)
## - Python pip3 preparation + First batch of python tools installs
## - Tensorflow build and install (optional)
## - FFmpeg build and install
## - OpenCV build and install (using FFmpeg)
## - Additional python tools installs
## - Magma build and install (GPU only, optional)
## - PyTorch (+ vison + audio) build and install (using FFmpeg + OpenCV, optional)
## - Final steps: /iti setup, ...
# The idea is to have a base Dockerfile that will be tailored to specific builds
# so that each build has their own final Dockerfile available for inspection
ARG CTPO_FROM=ubuntu:22.04
FROM ${CTPO_FROM}
# No CUDA, or no cuDNN bootstrap needed
ARG CTPO_NUMPROC=32
##### Base
# Install system packages
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y --fix-missing\
&& apt-get install -y \
apt-utils \
locales \
wget \
ca-certificates \
&& apt-get clean
# UTF-8
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
# Install system packages
RUN apt-get install -y \
# Base
build-essential \
checkinstall \
cmake \
curl \
g++ \
gcc \
git \
perl \
pkg-config \
protobuf-compiler \
python3-dev \
rsync \
time \
unzip \
wget \
zip \
zlib1g \
zlib1g-dev \
# OpenCV
doxygen \
file \
gfortran \
gnupg \
gstreamer1.0-plugins-good \
imagemagick \
libatk-adaptor \
libatlas-base-dev \
libboost-all-dev \
libcanberra-gtk-module \
libdc1394-dev \
libeigen3-dev \
libfaac-dev \
libfreetype6-dev \
libgflags-dev \
libglew-dev \
libglu1-mesa \
libglu1-mesa-dev \
libgoogle-glog-dev \
libgphoto2-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-bad1.0-0 \
libgstreamer-plugins-base1.0-dev \
libgtk2.0-dev \
libgtk-3-dev \
libhdf5-dev \
libhdf5-serial-dev \
libjpeg-dev \
liblapack-dev \
libmp3lame-dev \
libopenblas-dev \
libopencore-amrnb-dev \
libopencore-amrwb-dev \
libopenjp2-7 \
libopenjp2-7-dev \
libopenjp2-tools \
libopenjpip-server \
libpng-dev \
libpostproc-dev \
libprotobuf-dev \
libtbb2 \
libtbb-dev \
libtheora-dev \
libtiff5-dev \
libv4l-dev \
libvorbis-dev \
libwebp-dev \
libx264-dev \
libx265-dev \
libxi-dev \
libxine2-dev \
libxmu-dev \
libxvidcore-dev \
libzmq3-dev \
v4l-utils \
x11-apps \
x264 \
yasm \
# Torch
libomp-dev \
libsox-dev \
libsox-fmt-all \
libsphinxbase-dev \
sphinxbase-utils \
# FFMpeg (source install, do not install packages: libavcodec-dev libavformat-dev libavresample-dev libavutil-dev libswscale-dev)
libass-dev \
libc6 \
libc6-dev \
libnuma1 \
libnuma-dev \
libopus-dev \
libtool \
libvpx-dev \
&& apt-get clean
ENV CTPO_BUILD=CPU
RUN touch /tmp/.${CTPO_BUILD}_build
# - Avoid "RPC failed; curl 56 GnuTLS" issue on some pulls, while keeping the system installed git
# - Some tools expect a "python" binary
# - Prepare ldconfig
RUN git config --global http.postBuffer 1048576000 \
&& mkdir -p /usr/local/bin && ln -s $(which python3) /usr/local/bin/python \
&& mkdir -p /usr/local/lib && sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/usrlocallib.conf' && ldconfig
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
# Not a GPU build, no path fix to test
# Setup pip
RUN wget -q -O /tmp/get-pip.py --no-check-certificate https://bootstrap.pypa.io/get-pip.py \
&& python3 /tmp/get-pip.py \
&& pip3 install -U pip \
&& rm /tmp/get-pip.py
# Install Python tools (for buiding)
RUN pip3 install -U \
# Base
cmake \
future \
mkl \
mkl-include \
mock \
numpy \
opt_einsum \
packaging \
pyyaml \
requests \
setuptools \
six \
wheel \
# OpenCV
lxml \
Pillow \
# Torch
cffi \
typing \
ninja \
# Extra
scikit-image \
scikit-learn \
autovizwidget \
ipython \
jupyter \
matplotlib \
moviepy \
notebook \
pandas \
&& pip3 install -U keras_preprocessing --no-deps \
&& rm -rf /root/.cache/pip
##### TensorFlow
# https://www.tensorflow.org/install/source
## Download & Building TensorFlow from source in same RUN
ENV LATEST_BAZELISK=1.17.0
ENV CTPO_TENSORFLOW_VERSION=2.12.0
ENV CTPO_TF_CONFIG=""
ENV TF_CUDA_COMPUTE_CAPABILITIES=""
ENV TF_NEED_CUDA=0
ENV TF_CUDA_CLANG=0
ENV TF_NEED_TENSORRT=0
ENV TF_NEED_AWS=0
ENV TF_NEED_COMPUTECPP=0
ENV TF_NEED_GCP=0
ENV TF_NEED_GDR=0
ENV TF_NEED_HDFS=0
ENV TF_NEED_JEMALLOC=0
ENV TF_NEED_KAFKA=0
ENV TF_NEED_MKL=0
ENV TF_NEED_MPI=0
ENV TF_NEED_OPENCL=0
ENV TF_NEED_OPENCL_SYCL=0
ENV TF_NEED_ROCM=0
ENV TF_NEED_S3=0
ENV TF_NEED_VERBS=0
ENV TF_SET_ANDROID_WORKSPACE=0
RUN curl -s -Lo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v${LATEST_BAZELISK}/bazelisk-linux-amd64 \
&& chmod +x /usr/local/bin/bazel \
&& mkdir -p /usr/local/src/tensorflow \
&& cd /usr/local/src \
&& wget -q --no-check-certificate -c https://github.com/tensorflow/tensorflow/archive/v${CTPO_TENSORFLOW_VERSION}.tar.gz -O - | tar --strip-components=1 -xz -C /usr/local/src/tensorflow \
&& cd /usr/local/src/tensorflow \
&& bazel version \
&& ./configure \
&& time bazel build --verbose_failures --config=opt --config=v2 ${CTPO_TF_CONFIG} //tensorflow/tools/pip_package:build_pip_package \
&& ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg \
&& time pip3 install /tmp/tensorflow_pkg/tensorflow-*.whl \
&& rm -rf /usr/local/src/tensorflow /tmp/tensorflow_pkg /tmp/bazel_check.pl /tmp/tf_build.sh /tmp/hsperfdata_root /root/.cache/bazel /root/.cache/pip /root/.cache/bazelisk
RUN python3 -c 'import tensorflow as tf; print(f"{tf.__version__}")' > /tmp/.tensorflow_built
RUN echo "--- Tensorflow Build: Environment variables set --- " > /tmp/tf_env.dump \
&& env | grep TF_ | grep -v CTPO_ | sort >> /tmp/tf_env.dump
##### FFMPEG
ENV CTPO_FFMPEG_VERSION=5.1.2
ENV CTPO_FFMPEG_NONFREE=""
RUN mkdir -p /usr/local/src/builder \
&& cd /usr/local/src \
&& wget -q --no-check-certificate https://ffmpeg.org/releases/ffmpeg-${CTPO_FFMPEG_VERSION}.tar.gz -O - | tar --strip-components=1 -xz -C /usr/local/src/builder \
&& cd /usr/local/src/builder \
&& time ./configure --enable-shared --disable-static --enable-gpl --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxvid --enable-libopus --enable-pic --enable-libass --enable-libx264 --enable-libx265 | tee /tmp/ffmpeg_config.txt \
&& make -j${CTPO_NUMPROC} install \
&& ldconfig \
&& rm -rf /usr/local/src/builder
RUN echo "${CTPO_FFMPEG_VERSION}" > /tmp/.ffmpeg_built
#### OpenCV
# Download & Build OpenCV in same RUN
## FYI: We are removing the OpenCV source and build directory in /usr/local/src to attempt to save additional disk space
# Comment the last line if you want to rerun cmake with additional/modified options. For example:
# cd /usr/local/src/opencv/build
# cmake -DOPENCV_ENABLE_NONFREE=ON -DBUILD_EXAMPLES=ON -DBUILD_DOCS=ON -DBUILD_TESTS=ON -DBUILD_PERF_TESTS=ON .. && make install
ENV CTPO_OPENCV_VERSION=4.7.0
ENV CTPO_OPENCV_CUDA=""
ENV CTPO_OPENCV_NONFREE=""
RUN mkdir -p /usr/local/src/opencv/build /usr/local/src/opencv_contrib \
&& cd /usr/local/src \
&& wget -q --no-check-certificate https://github.com/opencv/opencv/archive/${CTPO_OPENCV_VERSION}.tar.gz -O - | tar --strip-components=1 -xz -C /usr/local/src/opencv \
&& wget -q --no-check-certificate https://github.com/opencv/opencv_contrib/archive/${CTPO_OPENCV_VERSION}.tar.gz -O - | tar --strip-components=1 -xz -C /usr/local/src/opencv_contrib \
&& cd /usr/local/src/opencv/build \
&& time cmake \
-DBUILD_DOCS=0 \
-DBUILD_EXAMPLES=0 \
-DBUILD_PERF_TESTS=0 \
-DBUILD_TESTS=0 \
-DBUILD_opencv_python2=0 \
-DBUILD_opencv_python3=1 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
-DCMAKE_INSTALL_TYPE=Release \
-DENABLE_FAST_MATH=1 \
-DFORCE_VTK=1 \
-DINSTALL_C_EXAMPLES=0 \
-DINSTALL_PYTHON_EXAMPLES=0 \
-DOPENCV_EXTRA_MODULES_PATH=/usr/local/src/opencv_contrib/modules \
-DOPENCV_GENERATE_PKGCONFIG=1 \
-DOPENCV_PC_FILE_NAME=opencv.pc \
-DOPENCV_PYTHON3_INSTALL_PATH=/usr/lib/python3/dist-packages \
-DWITH_CSTRIPES=1 \
-DWITH_EIGEN=1 \
-DWITH_GDAL=1 \
-DWITH_GSTREAMER=1 \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_GTK=1 \
-DWITH_IPP=1 \
-DWITH_OPENCL=1 \
-DWITH_OPENMP=1 \
-DWITH_TBB=1 \
-DWITH_V4L=1 \
-DWITH_WEBP=1 \
-DWITH_XINE=1 \
${CTPO_OPENCV_CUDA} \
${CTPO_OPENCV_NONFREE} \
.. \
&& time make -j${CTPO_NUMPROC} install \
&& ldconfig \
&& rm -rf /usr/local/src/opencv /usr/local/src/opencv_contrib
RUN python3 -c 'import cv2; print(f"{cv2.__version__}")' > /tmp/.opencv_built
# No Magma (PyTorch GPU only)
##### Torch (using FFMpeg + OpenCV)
ENV CTPO_TORCH=2.0.1
RUN mkdir -p /usr/local/src \
&& cd /usr/local/src \
&& git clone --depth 1 --recurse-submodule --branch v${CTPO_TORCH} https://github.com/pytorch/pytorch.git \
&& cd /usr/local/src/pytorch \
&& pip3 install -r requirements.txt \
&& time env USE_CUDA=0 USE_CUDNN=0 USE_MKLDNN=1 USE_FFMPEG=1 USE_OPENCV=1 python3 ./setup.py bdist_wheel | tee /tmp/torch_config.txt \
&& time pip3 install /usr/local/src/pytorch/dist/*.whl \
&& cd /tmp \
&& perl -i.bak -pe 'exit if m%^-- Configuring done%' torch_config.txt \
&& sh -c "cmp --silent torch_config.txt torch_config.txt.bak && exit 1 || rm torch_config.txt.bak" \
&& ldconfig \
&& rm -rf /root/.cache/pip /usr/local/src/pytorch
RUN python3 -c 'import torch; print(f"{torch.__version__}")' > /tmp/.torch_built
ENV CTPO_TORCHVISION=0.15.2
# setup.py options from https://github.com/pytorch/vision/blob/main/setup.py
RUN mkdir -p /usr/local/src \
&& cd /usr/local/src \
&& git clone --depth 1 --recurse-submodule --branch v${CTPO_TORCHVISION} https://github.com/pytorch/vision.git \
&& cd /usr/local/src/vision \
&& time env FORCE_CUDA=0 TORCHVISION_USE_FFMPEG=1 python3 ./setup.py bdist_wheel | tee /tmp/torchvision_config.txt \
&& time pip3 install /usr/local/src/vision/dist/*.whl \
&& cd /tmp \
&& perl -i.bak -pe 'exit if m%^running bdist_wheel%' torchvision_config.txt \
&& sh -c "cmp --silent torchvision_config.txt torchvision_config.txt.bak && exit 1 || rm torchvision_config.txt.bak" \
&& ldconfig \
&& rm -rf /root/.cache/pip /usr/local/src/vision
RUN python3 -c 'import torchvision; print(f"{torchvision.__version__}")' > /tmp/.torchvision_built
ENV CTPO_TORCHAUDIO=2.0.2
# setup.py options from https://github.com/pytorch/audio/blob/main/tools/setup_helpers/extension.py
RUN mkdir -p /usr/local/src \
&& cd /usr/local/src \
&& git clone --depth 1 --recurse-submodule --branch v${CTPO_TORCHAUDIO} https://github.com/pytorch/audio.git \
&& cd /usr/local/src/audio \
&& time env USE_CUDA=0 USE_FFMPEG=1 python3 ./setup.py bdist_wheel | tee /tmp/torchaudio_config.txt \
&& time pip3 install /usr/local/src/audio/dist/*.whl \
&& cd /tmp \
&& perl -i.bak -pe 'exit if m%^-- Configuring done%' torchaudio_config.txt \
&& sh -c "cmp --silent torchaudio_config.txt torchaudio_config.txt.bak && exit 1 || rm torchaudio_config.txt.bak" \
&& ldconfig \
&& rm -rf /root/.cache/pip /usr/local/src/audio
RUN python3 -c 'import torchaudio; print(f"{torchaudio.__version__}")' > /tmp/.torchaudio_built
ENV CTPO_TORCHDATA=0.6.1
RUN mkdir -p /usr/local/src \
&& cd /usr/local/src \
&& git clone --depth 1 --recurse-submodule --branch v${CTPO_TORCHDATA} https://github.com/pytorch/data.git \
&& cd /usr/local/src/data \
&& pip3 install . | tee /tmp/torchdata_config.txt \
&& rm -rf /root/.cache/pip /usr/local/src/data
RUN python3 -c 'import torchdata; print(f"{torchdata.__version__}")' > /tmp/.torchdata_built
ENV CTPO_TORCHTEXT=0.15.2
RUN mkdir -p /usr/local/src \
&& cd /usr/local/src \
&& git clone --depth 1 --recurse-submodule --branch v${CTPO_TORCHTEXT} https://github.com/pytorch/text.git \
&& cd /usr/local/src/text \
&& python3 setup.py clean install | tee /tmp/torchtext_config.txt \
&& cd /tmp \
&& perl -i.bak -pe 'exit if m%^-- Configuring done%' torchtext_config.txt \
&& sh -c "cmp --silent torchtext_config.txt torchtext_config.txt.bak && exit 1 || rm torchtext_config.txt.bak" \
&& rm -rf /root/.cache/pip /usr/local/src/text
RUN python3 -c 'import torchtext; print(f"{torchtext.__version__}")' > /tmp/.torchtext_built
##### Final steps
# Add lab & dataframe display widget
RUN apt-get install -y python3-venv \
&& pip3 install -U \
jupyterlab
# https://jupyterlab.readthedocs.io/en/stable/getting_started/changelog.html
# with v4 extensions are installed using the extension manager, see https://jupyterlab.readthedocs.io/en/stable/user/extensions.html#id11
RUN touch /.within_container
COPY tools/withincontainer_checker.sh /tmp/withincontainer_checker.sh
RUN chmod +x /tmp/withincontainer_checker.sh \
&& /tmp/withincontainer_checker.sh
# Setting up working directory
RUN mkdir /iti
WORKDIR /iti
# Uncomment as needed
#ENV NVIDIA_VISIBLE_DEVICES all
#ENV NVIDIA_DRIVER_CAPABILITIES video,compute,utility
CMD /bin/bash