|
| 1 | +# syntax=docker/dockerfile:1.6 |
| 2 | + |
| 3 | +ARG DEBIAN_FRONTEND=noninteractive |
| 4 | + |
| 5 | +# Build Python wheels |
| 6 | +FROM wheels AS h8l-wheels |
| 7 | + |
| 8 | +COPY docker/main/requirements-wheels.txt /requirements-wheels.txt |
| 9 | +COPY docker/hailo8l/requirements-wheels-h8l.txt /requirements-wheels-h8l.txt |
| 10 | + |
| 11 | +RUN sed -i "/https:\/\//d" /requirements-wheels.txt |
| 12 | + |
| 13 | +# Create a directory to store the built wheels |
| 14 | +RUN mkdir /h8l-wheels |
| 15 | + |
| 16 | +# Build the wheels |
| 17 | +RUN pip3 wheel --wheel-dir=/h8l-wheels -c /requirements-wheels.txt -r /requirements-wheels-h8l.txt |
| 18 | + |
| 19 | +# Build HailoRT and create wheel |
| 20 | +FROM deps AS build-hailort |
| 21 | + |
| 22 | +# Install necessary APT packages |
| 23 | +RUN apt-get update && apt-get install -y \ |
| 24 | + build-essential \ |
| 25 | + cmake \ |
| 26 | + git \ |
| 27 | + wget \ |
| 28 | + python3-dev \ |
| 29 | + gcc-9 \ |
| 30 | + g++-9 \ |
| 31 | + libzmq3-dev \ |
| 32 | + pciutils \ |
| 33 | + rsync \ |
| 34 | + && rm -rf /var/lib/apt/lists/* |
| 35 | + |
| 36 | +# Extract Python version and set environment variables |
| 37 | +RUN PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}' | cut -d. -f1,2) && \ |
| 38 | + PYTHON_VERSION_NO_DOT=$(echo $PYTHON_VERSION | sed 's/\.//') && \ |
| 39 | + echo "PYTHON_VERSION=$PYTHON_VERSION" > /etc/environment && \ |
| 40 | + echo "PYTHON_VERSION_NO_DOT=$PYTHON_VERSION_NO_DOT" >> /etc/environment |
| 41 | + |
| 42 | +#ENV PYTHON_VER=$PYTHON_VERSION |
| 43 | +#ENV PYTHON_VER_NO_DOT=$PYTHON_VERSION_NO_DOT |
| 44 | + |
| 45 | +# Clone and build HailoRT |
| 46 | +RUN . /etc/environment && \ |
| 47 | + git clone https://github.com/hailo-ai/hailort.git /opt/hailort && \ |
| 48 | + cd /opt/hailort && \ |
| 49 | + git checkout v4.17.0 && \ |
| 50 | + cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release -DHAILO_BUILD_PYBIND=1 -DPYBIND11_PYTHON_VERSION=${PYTHON_VERSION} && \ |
| 51 | + cmake --build build --config release --target libhailort && \ |
| 52 | + cmake --build build --config release --target _pyhailort && \ |
| 53 | + cp build/hailort/libhailort/bindings/python/src/_pyhailort.cpython-${PYTHON_VERSION_NO_DOT}-aarch64-linux-gnu.so hailort/libhailort/bindings/python/platform/hailo_platform/pyhailort/ && \ |
| 54 | + cp build/hailort/libhailort/src/libhailort.so hailort/libhailort/bindings/python/platform/hailo_platform/pyhailort/ |
| 55 | + |
| 56 | +RUN ls -ahl /opt/hailort/build/hailort/libhailort/src/ |
| 57 | +RUN ls -ahl /opt/hailort/hailort/libhailort/bindings/python/platform/hailo_platform/pyhailort/ |
| 58 | + |
| 59 | +# Remove the existing setup.py if it exists in the target directory |
| 60 | +RUN rm -f /opt/hailort/hailort/libhailort/bindings/python/platform/setup.py |
| 61 | + |
| 62 | +# Copy generate_wheel_conf.py and setup.py |
| 63 | +COPY docker/hailo8l/pyhailort_build_scripts/generate_wheel_conf.py /opt/hailort/hailort/libhailort/bindings/python/platform/generate_wheel_conf.py |
| 64 | +COPY docker/hailo8l/pyhailort_build_scripts/setup.py /opt/hailort/hailort/libhailort/bindings/python/platform/setup.py |
| 65 | + |
| 66 | +# Run the generate_wheel_conf.py script |
| 67 | +RUN python3 /opt/hailort/hailort/libhailort/bindings/python/platform/generate_wheel_conf.py |
| 68 | + |
| 69 | +# Create a wheel file using pip3 wheel |
| 70 | +RUN cd /opt/hailort/hailort/libhailort/bindings/python/platform && \ |
| 71 | + python3 setup.py bdist_wheel --dist-dir /hailo-wheels |
| 72 | + |
| 73 | +# Use deps as the base image |
| 74 | +FROM deps AS h8l-frigate |
| 75 | + |
| 76 | +# Copy the wheels from the wheels stage |
| 77 | +COPY --from=h8l-wheels /h8l-wheels /deps/h8l-wheels |
| 78 | +COPY --from=build-hailort /hailo-wheels /deps/hailo-wheels |
| 79 | +COPY --from=build-hailort /etc/environment /etc/environment |
| 80 | +RUN CC=$(python3 -c "import sysconfig; import shlex; cc = sysconfig.get_config_var('CC'); cc_cmd = shlex.split(cc)[0]; print(cc_cmd[:-4] if cc_cmd.endswith('-gcc') else cc_cmd)") && \ |
| 81 | + echo "CC=$CC" >> /etc/environment |
| 82 | + |
| 83 | +# Install the wheels |
| 84 | +RUN pip3 install -U /deps/h8l-wheels/*.whl |
| 85 | +RUN pip3 install -U /deps/hailo-wheels/*.whl |
| 86 | + |
| 87 | +RUN . /etc/environment && \ |
| 88 | + mv /usr/local/lib/python${PYTHON_VERSION}/dist-packages/hailo_platform/pyhailort/libhailort.so /usr/lib/${CC} && \ |
| 89 | + cd /usr/lib/${CC}/ && \ |
| 90 | + ln -s libhailort.so libhailort.so.4.17.0 |
| 91 | + |
| 92 | +# Copy base files from the rootfs stage |
| 93 | +COPY --from=rootfs / / |
| 94 | + |
| 95 | +# Set environment variables for Hailo SDK |
| 96 | +ENV PATH="/opt/hailort/bin:${PATH}" |
| 97 | +ENV LD_LIBRARY_PATH="/usr/lib/aarch64-linux-gnu:${LD_LIBRARY_PATH}" |
| 98 | + |
| 99 | +# Set workdir |
| 100 | +WORKDIR /opt/frigate/ |
0 commit comments