API Dockerfile: install camera SDK from local tarball under camera_sdk; compose: build API image and set LD_LIBRARY_PATH fallback

This commit is contained in:
Alireza Vaezi
2025-08-07 21:25:58 -04:00
parent 458c04608c
commit cf0bb48fac
2 changed files with 31 additions and 2 deletions

25
api/Dockerfile Normal file
View File

@@ -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

View File

@@ -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: