Skip to content

Commit 529be65

Browse files
committed
adding Dockerfile for opencv package
1 parent f30f610 commit 529be65

File tree

2 files changed

+184
-1
lines changed

2 files changed

+184
-1
lines changed

Sandbox/Dockerfile_gpu_opencv

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Copyright 2020 The KNIX Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#FROM ubuntu:18.04
16+
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
17+
18+
# Install (as root)
19+
# Base
20+
RUN apt-get update --fix-missing
21+
RUN apt-get -y --no-install-recommends install build-essential
22+
RUN apt-get -y --no-install-recommends install netbase unzip file libmagic1
23+
24+
25+
# Python
26+
RUN apt-get -y --no-install-recommends install python3 python3-dev
27+
RUN apt-get -y --no-install-recommends install python3-pip
28+
RUN apt-get -y --no-install-recommends install zlib1g libssl1.0 libsasl2-2 ca-certificates
29+
30+
RUN /usr/bin/python3 -m pip install --upgrade pip
31+
32+
RUN /usr/bin/python3 -m pip install setuptools
33+
RUN /usr/bin/python3 -m pip install thrift>=0.12.0
34+
RUN /usr/bin/python3 -m pip install anytree
35+
RUN /usr/bin/python3 -m pip install ujsonpath
36+
RUN /usr/bin/python3 -m pip install requests
37+
RUN /usr/bin/python3 -m pip install retry
38+
# remove warnings from anytree package
39+
RUN /usr/bin/python3 -m pip install fastcache
40+
# Needed for multi-language support (currently just Java)
41+
RUN /usr/bin/python3 -m pip install thriftpy2
42+
43+
# Add components (as mfn)
44+
RUN groupadd -o -g 1000 -r mfn && useradd -d /opt/mfn -u 1000 -m -r -g mfn mfn
45+
RUN mkdir /opt/mfn/logs
46+
47+
RUN /usr/bin/python3 -m pip install redis
48+
ADD build/redis-server.tar.gz /opt/mfn/
49+
ADD frontend/frontend /opt/mfn/frontend
50+
ADD build/SandboxAgent.tar.gz /opt/mfn/
51+
ADD build/FunctionWorker.tar.gz /opt/mfn/
52+
ADD build/LoggingService.tar.gz /opt/mfn/
53+
54+
# CUDA 10.1 dependencies and tools to build dlib
55+
RUN apt-get -y --no-install-recommends install libsm6 libxrender1 libxrender-dev libxext6 libglib2.0-0 git cmake
56+
RUN apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 libnvinfer-dev=6.0.1-1+cuda10.1 libnvinfer-plugin6=6.0.1-1+cuda10.1
57+
58+
# Install dlib for CUDA
59+
#RUN git clone https://github.com/davisking/dlib.git
60+
#RUN mkdir -p /dlib/build
61+
62+
#RUN cmake -H/dlib -B/dlib/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1
63+
#RUN cmake --build /dlib/build
64+
65+
#RUN cd /dlib; python3 /dlib/setup.py install
66+
67+
68+
ENV DEBIAN_FRONTEND noninteractive
69+
70+
ARG OPENCV_VERSION='4.4.0'
71+
ARG GPU_ARCH='6.1'
72+
WORKDIR /opt
73+
74+
# Build tools
75+
RUN apt update && \
76+
apt install -y \
77+
sudo \
78+
tzdata \
79+
git \
80+
cmake \
81+
wget \
82+
unzip \
83+
build-essential
84+
85+
# Media I/O:
86+
RUN apt update && apt install -y \
87+
zlib1g-dev \
88+
libjpeg-dev \
89+
libwebp-dev \
90+
libpng-dev \
91+
libtiff5-dev \
92+
libopenexr-dev \
93+
libgdal-dev \
94+
libgtk2.0-dev
95+
96+
# Video I/O:
97+
RUN apt update && apt install -y \
98+
libdc1394-22-dev \
99+
libavcodec-dev \
100+
libavformat-dev \
101+
libswscale-dev \
102+
libtheora-dev \
103+
libvorbis-dev \
104+
libxvidcore-dev \
105+
libx264-dev \
106+
yasm \
107+
libopencore-amrnb-dev \
108+
libopencore-amrwb-dev \
109+
libv4l-dev \
110+
libxine2-dev \
111+
libgstreamer1.0-dev \
112+
libgstreamer-plugins-base1.0-dev \
113+
libopencv-highgui-dev \
114+
ffmpeg
115+
116+
# Parallelism and linear algebra libraries:
117+
RUN apt update && apt install -y \
118+
libtbb-dev \
119+
libeigen3-dev
120+
121+
# Python:
122+
RUN apt update && apt install -y \
123+
python3-dev \
124+
python3-tk \
125+
python3-numpy
126+
127+
# Build OpenCV
128+
RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
129+
unzip ${OPENCV_VERSION}.zip && rm ${OPENCV_VERSION}.zip && \
130+
mv opencv-${OPENCV_VERSION} OpenCV && \
131+
cd OpenCV && \
132+
wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
133+
unzip ${OPENCV_VERSION}.zip && \
134+
mkdir build && \
135+
cd build && \
136+
cmake \
137+
-D WITH_TBB=ON \
138+
-D CMAKE_BUILD_TYPE=RELEASE \
139+
-D BUILD_EXAMPLES=ON \
140+
-D WITH_FFMPEG=ON \
141+
-D WITH_V4L=ON \
142+
-D WITH_OPENGL=ON \
143+
-D WITH_CUDA=ON \
144+
-D WITH_CUDNN=ON \
145+
-D OPENCV_DNN_CUDA=ON \
146+
-D ENABLE_FAST_MATH=1 \
147+
-D CUDA_FAST_MATH=1 \
148+
-D CUDA_ARCH_BIN=7.0 \
149+
-D CUDA_ARCH_BIN=${GPU_ARCH} \
150+
-D CUDA_ARCH_PTX=${GPU_ARCH} \
151+
-D WITH_CUBLAS=ON \
152+
-D WITH_CUFFT=ON \
153+
-D WITH_EIGEN=ON \
154+
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
155+
-D HAVE_opencv_python3=ON \
156+
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-${OPENCV_VERSION}/modules/ \
157+
.. && \
158+
make all -j$(nproc) && \
159+
make install
160+
161+
#RUN apt-get update && apt-get install -y python3-opencv
162+
#RUN pip install opencv-python
163+
164+
# Install the face recognition package and tensorflow
165+
#RUN /usr/bin/python3 -m pip install face_recognition
166+
#RUN /usr/bin/python3 -m pip install tensorflow==2.1.0
167+
168+
169+
RUN chown mfn:mfn -R /opt/mfn
170+
USER mfn
171+
WORKDIR /opt/mfn
172+
CMD ["python3", "/opt/mfn/SandboxAgent/sandboxagent.py"]

Sandbox/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ include ../build_env.mk
2121
default: build_thrift \
2222
image \
2323
image_gpu \
24+
image_gpu_opencv \
2425
image_java
2526

2627
clean:
@@ -105,6 +106,15 @@ image_gpu: \
105106
build/SandboxAgent.tar.gz
106107
$(call build_image,Dockerfile_gpu,microfn/sandbox_gpu)
107108

109+
image_gpu_opencv: \
110+
Dockerfile_gpu_opencv \
111+
build/redis-server.tar.gz \
112+
frontend/frontend \
113+
build/LoggingService.tar.gz \
114+
build/FunctionWorker.tar.gz \
115+
build/SandboxAgent.tar.gz
116+
$(call build_image,Dockerfile_gpu_opencv,microfn/sandbox_gpu_opencv)
117+
108118

109119
image_java: \
110120
Dockerfile_java \
@@ -116,9 +126,10 @@ image_java: \
116126
build/SandboxAgent.tar.gz
117127
$(call build_image,Dockerfile_java,microfn/sandbox_java)
118128

119-
push: image image_gpu image_java
129+
push: image image_gpu image_java image_gpu_opencv
120130
$(call push_image,microfn/sandbox)
121131
$(call push_image,microfn/sandbox_gpu)
132+
$(call push_image,microfn/sandbox_gpu_opencv)
122133
$(call push_image,microfn/sandbox_java)
123134

124135

0 commit comments

Comments
 (0)