|
| 1 | +FROM ubuntu:20.04 as build-stage |
| 2 | + |
| 3 | +ARG PYTHON_VERSION |
| 4 | +ARG OPENCV_TAG |
| 5 | +ARG NUMPY_VERSION=1.23.5 |
| 6 | + |
| 7 | +RUN apt update && apt install -y software-properties-common curl |
| 8 | + |
| 9 | +RUN add-apt-repository -y 'ppa:deadsnakes/ppa' \ |
| 10 | + && apt update && apt install -y --no-install-recommends \ |
| 11 | + python${PYTHON_VERSION} python${PYTHON_VERSION}-venv python${PYTHON_VERSION}-dev \ |
| 12 | + && rm -rf /var/lib/apt/lists/* \ |
| 13 | + && curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} \ |
| 14 | + && pip install -U pip \ |
| 15 | + && pip --no-cache-dir install numpy==${NUMPY_VERSION} |
| 16 | + |
| 17 | +ENV VENV_ROOT_PREFIX=/opt/venv |
| 18 | +RUN python${PYTHON_VERSION} -m venv ${VENV_ROOT_PREFIX} |
| 19 | + |
| 20 | + |
| 21 | +WORKDIR /opt/ |
| 22 | +RUN apt update && apt install -y git build-essential cmake libopenblas-dev liblapacke-dev libjpeg-dev \ |
| 23 | + # trick to opencv find openblas and numpy headers |
| 24 | + && cp /usr/include/x86_64-linux-gnu/cblas.h /usr/include/ \ |
| 25 | + && ln -s /usr/local/lib/python${PYTHON_VERSION}/dist-packages/numpy/core/include/numpy /usr/include/numpy \ |
| 26 | + && git clone https://github.com/opencv/opencv-python.git \ |
| 27 | + && cd opencv-python \ |
| 28 | + && git checkout ${OPENCV_TAG} \ |
| 29 | + && git submodule update --init --recursive \ |
| 30 | + && export ENABLE_HEADLESS=1 \ |
| 31 | + && MAKEFLAGS='-j2' pip wheel . --verbose |
| 32 | + # trick to pack openblas lib to wheel |
| 33 | + && pip install auditwheel patchelf \ |
| 34 | + && auditwheel repair *.whl --plat manylinux_2_31_x86_64 |
| 35 | + |
| 36 | +FROM scratch AS export-stage |
| 37 | +COPY --from=build-stage /opt/opencv-python/wheelhouse / |
0 commit comments