-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
Copy pathDockerfile.manylinux_2_28_x86_64
103 lines (86 loc) · 4.85 KB
/
Dockerfile.manylinux_2_28_x86_64
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
# Copyright 2025 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A docker image that contains the PyPA manylinux2014 toolchain and
# bazel 6.5.0 and opencv 4.10 static libraries. The image produces MediaPipe
# manylinux wheels and puts the output wheel files in /wheelhouse/.
#
# Usage:
# $ DOCKER_BUILDKIT=1 docker build -f Dockerfile.manylinux_2_28_x86_64 -t mp_manylinux . --build-arg "PYTHON_BIN=/opt/python/cp312-cp312/bin/python3.12"
# $ docker create -ti --name mp_pip_package_container mp_manylinux:latest
# $ docker cp mp_pip_package_container:/wheelhouse/. wheelhouse/
# $ docker rm -f mp_pip_package_container
# Make a container for MediaPipe
FROM quay.io/pypa/manylinux_2_28_x86_64
ARG MEDIAPIPE_DISABLE_GPU=1
ENV MEDIAPIPE_DISABLE_GPU=${MEDIAPIPE_DISABLE_GPU}
RUN yum install -y java-11-openjdk-devel zip
WORKDIR /tmp/bazel_build
ADD https://github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-dist.zip bazel.zip
RUN unzip bazel.zip
RUN rm -f bazel.zip
ENV PATH="/opt/python/cp36-cp36m/bin:${PATH}"
ENV EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk"
ENV BAZEL_LINKLIBS=-lm:-lstdc++
RUN ./compile.sh
RUN cp /tmp/bazel_build/output/bazel /bin/bazel
# Install Clang 18
RUN --mount=type=cache,target=/var/cache/dnf dnf install -y wget gcc-c++ && dnf clean all
RUN mkdir /tmp/llvm-project && wget -qO - https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-18.1.8.tar.gz | tar -xz -C /tmp/llvm-project --strip-components 1 && \
mkdir /tmp/llvm-project/build && cd /tmp/llvm-project/build && cmake -DLLVM_ENABLE_PROJECTS='clang;lld' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-18/ ../llvm && \
make -j$(nproc) && make -j$(nproc) install && rm -rf /tmp/llvm-project
# Install OpenGL
RUN yum install -y mesa-libGL mesa-libGL-devel mesa-libEGL mesa-libEGL-devel
RUN yum install -y mesa-libGLES-devel
# Install Java, zip, emacs, and portaudio.
RUN yum install -y epel-release && yum install -y java-11-openjdk \
java-11-openjdk-devel zip emacs portaudio-devel
# Copy Protobuf Compiler binary
ARG PROTOC_ZIP=protoc-25.1-linux-x86_64.zip
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.1/$PROTOC_ZIP
RUN unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
RUN unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
RUN rm -f $PROTOC_ZIP
# Install OpenCV.
RUN yum install -y cmake
WORKDIR /tmp/bazel_build
RUN git clone https://github.com/opencv/opencv.git
RUN mkdir opencv/release
RUN cd /tmp/bazel_build/opencv && git checkout 4.10.0 && cd release && cmake .. \
-DCMAKE_C_COMPILER=/usr/lib/llvm-18/bin/clang -DCMAKE_CXX_COMPILER=/usr/lib/llvm-18/bin/clang++ \
-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_SHARED_LIBS=OFF -DBUILD_LIST=imgproc,core \
-DWITH_ITT=OFF -DWITH_IPP=OFF -DBUILD_EXAMPLES=OFF \
-DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_ts=OFF \
-DCV_ENABLE_INTRINSICS=ON -DWITH_EIGEN=ON -DWITH_PTHREADS=ON -DWITH_PTHREADS_PF=ON
RUN cd /tmp/bazel_build/opencv/release && make -j 16 && make install
COPY . /mediapipe/
WORKDIR /mediapipe
# Set version number
RUN export MP_VERSION_NUMBER=$(awk '/MEDIAPIPE_FULL_VERSION/ {split($0, a, "="); print a[2]}' version.bzl | sed 's/[" ]//g') && \
sed -i "s/__version__ = 'dev'/__version__ = '${MP_VERSION_NUMBER}'/g" setup.py
# Set build flags for MediaPipe and OpenCV.
RUN echo "build --client_env=CC=/usr/lib/llvm-18/bin/clang++" >> .bazelrc && \
echo "build --define=xnn_enable_avxvnniint8=false" >> .bazelrc && \
echo 'cc_library(name = "opencv", srcs = ["local/lib64/libopencv_imgproc.a", "local/lib64/libopencv_core.a"],hdrs = glob(["local/include/opencv4/opencv2/**/*.h*"]), includes = ["local/include/opencv4/"], linkstatic = 1, visibility = ["//visibility:public"])' > third_party/opencv_linux.BUILD && \
sed -i "s|bazel_command.append('--define=OPENCV=source')|pass|g" setup.py
# Apply diff to reduce the number of OpenCV dependencies.
RUN patch -p1 < mediapipe_python_build.diff
ARG PYTHON_BIN="/opt/python/cp312-cp312/bin/python3.12"
RUN $PYTHON_BIN -m pip install --upgrade pip setuptools
RUN $PYTHON_BIN -m pip install wheel "numpy<2" auditwheel torch pyaudio
RUN ln -sf $PYTHON_BIN /usr/bin/python && \
ln -sf $PYTHON_BIN /usr/bin/python3 && \
$PYTHON_BIN setup.py bdist_wheel clean --all
RUN auditwheel repair dist/*-cp312-cp312-linux_x86_64.whl
RUN mkdir /wheelhouse/ && cp dist/* /wheelhouse/