From cf0bb48fac6e473b1238636371e628216a69859f Mon Sep 17 00:00:00 2001 From: Alireza Vaezi Date: Thu, 7 Aug 2025 21:25:58 -0400 Subject: [PATCH] API Dockerfile: install camera SDK from local tarball under camera_sdk; compose: build API image and set LD_LIBRARY_PATH fallback --- api/Dockerfile | 25 +++++++++++++++++++++++++ docker-compose.yml | 8 ++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 api/Dockerfile diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..885f398 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,25 @@ +# API development image with Huateng Vision SDK (local bundle) +FROM python:3.11-slim + +# Install system dependencies required by SDK and tooling +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates tar \ + libusb-1.0-0 libgl1 libx11-6 libxext6 libxcb1 libgtk-3-0 \ + && rm -rf /var/lib/apt/lists/* + +# Copy SDK bundle placed under api/camera_sdk and install native libs +WORKDIR /app +COPY camera_sdk /tmp/camera_sdk + +RUN set -eux; \ + mkdir -p /opt/mvsdk; \ + TARBALL="$(find /tmp/camera_sdk -maxdepth 1 -type f -name '*.tar.gz' | head -n1)"; \ + if [ -z "$TARBALL" ]; then echo 'No SDK .tar.gz found in camera_sdk'; exit 1; fi; \ + tar -xzf "$TARBALL" -C /opt/mvsdk || true; \ + # Copy any .so library files into /usr/lib so ctypes can load libMVSDK.so + find /opt/mvsdk -type f -name '*.so*' -exec cp -n {} /usr/lib/ \; || true; \ + ldconfig || true + +ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib + +# The actual app code is bind-mounted by docker-compose at runtime diff --git a/docker-compose.yml b/docker-compose.yml index bdb1787..4aadf66 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,15 +2,20 @@ version: "3.9" services: api: - image: python:3.11-slim + build: + context: ./api + dockerfile: Dockerfile working_dir: /app volumes: - ./api:/app - ./api/storage:/storage environment: - PYTHONUNBUFFERED=1 + - LD_LIBRARY_PATH=/usr/local/lib:/app/camera_sdk/lib command: > sh -lc " + apt-get update && apt-get install -y libusb-1.0-0-dev; + if [ -d camera_sdk/lib ]; then cp camera_sdk/lib/* /usr/local/lib/ 2>/dev/null || true; fi; if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; else pip install --no-cache-dir -e .; fi; python main.py --config config.compose.json " @@ -47,4 +52,3 @@ services: volumes: mosquitto-data: mosquitto-conf: -