Skip to content

Commit

Permalink
Add DepthAI PreV3 Support for Robothub based on docker image setup
Browse files Browse the repository at this point in the history
  • Loading branch information
psauxo committed Jan 26, 2024
1 parent 7b0ceeb commit ba164f7
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 133 deletions.
51 changes: 51 additions & 0 deletions context/install-depthai-from-git
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -Eeux

# Check if the correct number of arguments is provided
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <depthai-git-version>"
exit 1
fi

DEPTHAI_GIT_VERSION=$1
echo "Received DepthAI Git version: $DEPTHAI_GIT_VERSION"

# Verify that the version starts with 'git+'
if [[ $DEPTHAI_GIT_VERSION != git+* ]]; then
echo "Error: DepthAI version must be a Git URL"
exit 1
fi

# Install necessary build tools and dependencies for compiling the DepthAI Python package from source
apt-get update -qq && \
apt-get install -qq --no-install-recommends \
python3 python3-dev python3-pip \
ca-certificates \
git \
wget \
cmake \
make \
build-essential && \
pip3 install mypy && \
rm -rf /var/lib/apt/lists/*

# Parse the Git URL and Branch from the version string
GIT_URL=${DEPTHAI_GIT_VERSION/git+/}
BRANCH=${GIT_URL##*@}
GIT_URL=${GIT_URL%@*}
echo "Cloning from Git URL: $GIT_URL, Branch: $BRANCH"


# Clone the DepthAI Git repository
echo "Cloning DepthAI from Git..."
git clone --branch "$BRANCH" --recurse-submodules "$GIT_URL" depthai-python || { echo "Git clone failed"; exit 1; }

# Navigate to the cloned directory
echo "Navigating to cloned directory..."
cd depthai-python || { echo "Failed to enter depthai-python directory"; exit 1; }

# Build and install the package
echo "Building and installing the DepthAI package..."
pip3 install . --verbose || { echo "DepthAI installation failed"; exit 1; }

echo "DepthAI installation from Git completed successfully."
2 changes: 1 addition & 1 deletion context/install-depthai-version
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi
DEPTHAI_VERSION=$1

echo "Installing depthai version: ${DEPTHAI_VERSION}"
pip3 install --no-deps --no-cache-dir --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/ depthai==${DEPTHAI_VERSION}
pip3 install --no-deps --no-cache-dir --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/ depthai=="${DEPTHAI_VERSION}"

echo "Patching depthai installation..."
find /usr/local/lib/python3.10/dist-packages/depthai.libs -type f -name "libusb*.so" -print -exec cp /lib/libusb-1.0.so {} \;
19 changes: 11 additions & 8 deletions context/install-luxonis-packages
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/bin/bash

# Check for correct number of arguments
if [[ $# -ne 3 ]]; then
echo "Usage: $0 [robotics-vision-core] [depthai-sdk-version] [robothub-version]"
echo "robotics-vision-core: rvc2, rvc3"
echo "Usage: $0 <robotics-vision-core> <robothub-version> <depthai-sdk-version>"
echo "robotics-vision-core: rvc2, rvc3, rvc2-depthaiV3"
exit 1
fi

ROBOTICS_VISION_CORE=$1
DEPTHAI_SDK_VERSION=$2
ROBOTHUB_VERSION=$3
ROBOTHUB_VERSION=$2
DEPTHAI_SDK_VERSION=$3

if [[ "$ROBOTICS_VISION_CORE" == "rvc2" ]]; then
pip3 install --no-deps --no-cache-dir depthai-sdk==${DEPTHAI_SDK_VERSION}
pip3 install --no-deps --no-cache-dir robothub==${ROBOTHUB_VERSION}
# Install robothub
pip3 install --no-deps --no-cache-dir "robothub==${ROBOTHUB_VERSION}"

# Install depthai-sdk based on the robotics-vision-core
if [[ "$ROBOTICS_VISION_CORE" == "rvc2" || "$ROBOTICS_VISION_CORE" == "rvc2-depthaiV3" ]]; then
pip3 install --no-deps --no-cache-dir "depthai-sdk==${DEPTHAI_SDK_VERSION}"
elif [[ "$ROBOTICS_VISION_CORE" == "rvc3" ]]; then
pip3 install --no-deps --no-cache-dir "git+https://github.com/luxonis/depthai.git@${DEPTHAI_SDK_VERSION}#subdirectory=depthai_sdk"
pip3 install --no-deps --no-cache-dir robothub==${ROBOTHUB_VERSION}
else
echo "Unknown ROBOTICS_VISION_CORE: ${ROBOTICS_VISION_CORE}"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion dockerfiles/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN /tmp/download-patched-libusb ${TARGETARCH}

# Install luxonis packages
COPY install-luxonis-packages /tmp/
RUN /tmp/install-luxonis-packages ${ROBOTICS_VISION_CORE} ${DEPTHAI_SDK_VERSION} ${ROBOTHUB_VERSION}
RUN /tmp/install-luxonis-packages ${ROBOTICS_VISION_CORE} ${ROBOTHUB_VERSION} ${DEPTHAI_SDK_VERSION}

# Install python3 packages
COPY requirements-${VARIANT}.txt /tmp/
Expand All @@ -49,4 +49,5 @@ COPY --from=build /usr/local/lib/python3.10/dist-packages /usr/local/lib/python3
# Install depthai
COPY --from=build /lib/libusb-1.0.so /lib/libusb-1.0.so
COPY install-depthai-version /usr/local/bin

RUN install-depthai-version ${DEPTHAI_VERSION}
50 changes: 50 additions & 0 deletions dockerfiles/depthai-v3-git/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ARG BASE_IMAGE

FROM ${BASE_IMAGE} AS base

ARG DEBIAN_FRONTEND=noninteractive

ENV PYTHONPATH=/lib \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

# Install python3
RUN apt-get update -qq && \
apt-get install -qq --no-install-recommends python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

FROM base AS build

ARG DEBIAN_FRONTEND=noninteractive
ARG TARGETARCH
ARG DEPTHAI_VERSION
ARG ROBOTICS_VISION_CORE
ARG DEPTHAI_VERSION
ARG DEPTHAI_SDK_VERSION
ARG ROBOTHUB_VERSION
ARG VARIANT

COPY install-depthai-from-git /tmp/
RUN /tmp/install-depthai-from-git ${DEPTHAI_VERSION}

# Download patched libusb
COPY download-patched-libusb /tmp/
RUN /tmp/download-patched-libusb ${TARGETARCH}

# Install luxonis packages: depthai-sdk, robothub
COPY install-luxonis-packages /tmp/
RUN /tmp/install-luxonis-packages ${ROBOTICS_VISION_CORE} ${ROBOTHUB_VERSION} ${DEPTHAI_SDK_VERSION}

# Install python3 packages
COPY requirements-${VARIANT}.txt /tmp/
RUN pip3 install --no-cache-dir --only-binary=:all: -r /tmp/requirements-${VARIANT}.txt

FROM base

ARG DEPTHAI_VERSION

# Copy python3 packages
COPY --from=build /usr/local/lib/python3.10/dist-packages /usr/local/lib/python3.10/dist-packages

# Install depthai
COPY --from=build /lib/libusb-1.0.so /lib/libusb-1.0.so
40 changes: 40 additions & 0 deletions dockerfiles/depthai-v3-git/builtin-app.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:22.04 AS base

ARG DEBIAN_FRONTEND=noninteractive

ENV PYTHONPATH=/lib \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

# Install python3
RUN apt-get update -qq && \
apt-get install -qq --no-install-recommends python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

FROM base AS build

ARG DEBIAN_FRONTEND=noninteractive
ARG TARGETARCH
ARG DEPTHAI_VERSION

# Install dependencies
RUN apt-get update -qq && \
apt-get install -qq --no-install-recommends ca-certificates wget && \
rm -rf /var/lib/apt/lists/*

# Download patched libusb
COPY download-patched-libusb /tmp/
RUN /tmp/download-patched-libusb ${TARGETARCH}

# Install depthai
COPY install-depthai-from-git /usr/local/bin
RUN install-depthai-from-git ${DEPTHAI_VERSION}

# Install python3 packages
COPY requirements-builtin-app.txt /tmp/
RUN pip3 install --no-cache-dir --only-binary=:all: -r /tmp/requirements-builtin-app.txt

FROM base

# Copy python3 packages
COPY --from=build /usr/local/lib/python3.10/dist-packages /usr/local/lib/python3.10/dist-packages
148 changes: 91 additions & 57 deletions scripts/build-images-base.sh
Original file line number Diff line number Diff line change
@@ -1,71 +1,105 @@
#!/bin/bash
set -Eeux

declare -a elems=(
"rvc2 ubuntu:22.04 minimal"
"rvc2 ubuntu:22.04 regular"
"rvc2 ros:humble-ros-core minimal"
"rvc2 ros:humble-ros-base regular"
"rvc3 ubuntu:22.04 minimal"
"rvc3 ubuntu:22.04 regular"
"rvc3 ros:humble-ros-core minimal"
"rvc3 ros:humble-ros-base regular"
)
declare -A versions
CONFIG_FILE="scripts/versions.conf"
if [ ! -f "${CONFIG_FILE}" ]; then
echo "The file ${CONFIG_FILE} does not exist."
exit 1
fi

for elem in "${elems[@]}"; do
# Define base parameters
read -a strarr <<<"$elem"
ROBOTICS_VISION_CORE=${strarr[0]}
BASE_IMAGE=${strarr[1]}
VARIANT=${strarr[2]}

# Derive remaining parameters
DEPTHAI_VERSION=""
DEPTHAI_SDK_VERSION=""
if [[ "${ROBOTICS_VISION_CORE}" == "rvc2" ]]; then
DEPTHAI_VERSION="2.22.0.0.dev0+4f65e787340f0c83f8c03619d240bbb8af1260df"
DEPTHAI_SDK_VERSION="1.12.1"
elif [[ "${ROBOTICS_VISION_CORE}" == "rvc3" ]]; then
DEPTHAI_VERSION="2.22.0.0.dev0+8b9eceb316ce60d57d9157ecec48534b548e8904"
DEPTHAI_SDK_VERSION="d188eec84fded7ea10a3dc124db7da433a2a3578"
else
echo "Unknown ROBOTICS_VISION_CORE: ${ROBOTICS_VISION_CORE}"
continue
echo "Reading versions from ${CONFIG_FILE}..."
while IFS='=' read -r key value; do
versions[$key]=$value
done < "${CONFIG_FILE}"

# Define base parameters
ROBOTHUB_VERSION="2.4.0"

build_and_push_image() {
local robotics_vision_core=$1
local base_image=$2
local variant=$3
local dockerfile=$4

IFS=',' read -r depthai_version depthai_sdk_version <<< "${versions[${robotics_vision_core}]}"
if [ -z "${depthai_version}" ]; then
echo "No version found for ${robotics_vision_core} in ${CONFIG_FILE}"
return
fi
ROBOTHUB_VERSION="2.4.0"

TAG="${BASE_TAG}-${ROBOTICS_VISION_CORE}-${VARIANT}"
if [[ "${BASE_IMAGE}" == "ros:humble-ros-core" || "${BASE_IMAGE}" == "ros:humble-ros-base" ]]; then
TAG="${TAG}-ros2humble"
local tag="${BASE_TAG}-${robotics_vision_core}-${variant}"
if [[ "${base_image}" == "ros:humble-ros-core" || "${base_image}" == "ros:humble-ros-base" ]]; then
tag="${tag}-ros2humble"
fi

# Build
echo "================================"
echo "Building '${TAG}'..."
echo "=> Depthai version: ${DEPTHAI_VERSION}"
echo "=> Depthai SDK version: ${DEPTHAI_SDK_VERSION}"
echo "Building '${tag}'..."
echo "=> Depthai version: ${depthai_version}"
echo "=> Depthai SDK version: ${depthai_sdk_version}"
echo "=> RobotHub version: ${ROBOTHUB_VERSION}"
echo "================================"

LABELS=(
"--label" "org.opencontainers.image.source=https://github.com/luxonis/robothub-images"
"--label" "org.opencontainers.image.version=${tag}"
"--label" "org.opencontainers.image.vendor=Luxonis"
"--label" "org.opencontainers.image.ref.name=${IMAGE_REF_NAME}"
"--label" "org.opencontainers.image.title=RobotHub App base image"
"--label" "org.opencontainers.image.description=DepthAI version: ${depthai_version}"
"--label" "com.luxonis.rh.depthai.version=${depthai_version}"
"--label" "com.luxonis.rh.robothub.version=${ROBOTHUB_VERSION}"
)

BUILD_ARGS=(
"--build-arg" "BASE_IMAGE=${base_image}"
"--build-arg" "ROBOTICS_VISION_CORE=${robotics_vision_core}"
"--build-arg" "DEPTHAI_SDK_VERSION=${depthai_sdk_version}"
"--build-arg" "DEPTHAI_VERSION=${depthai_version}"
"--build-arg" "ROBOTHUB_VERSION=${ROBOTHUB_VERSION}"
"--build-arg" "VARIANT=${variant}"
)

# Check if the Robotics Vision Core version is not rvc2-depthaiV3
if [[ "${robotics_vision_core}" != "rvc2-depthaiV3" ]]; then
LABELS+=("--label" "com.luxonis.rh.depthai-sdk.version=${depthai_sdk_version}")
fi

docker buildx build \
--build-arg "BASE_IMAGE=${BASE_IMAGE}" \
--build-arg "ROBOTICS_VISION_CORE=${ROBOTICS_VISION_CORE}" \
--build-arg "DEPTHAI_VERSION=${DEPTHAI_VERSION}" \
--build-arg "DEPTHAI_SDK_VERSION=${DEPTHAI_SDK_VERSION}" \
--build-arg "ROBOTHUB_VERSION=${ROBOTHUB_VERSION}" \
--build-arg "VARIANT=${VARIANT}" \
--label "org.opencontainers.image.source=https://github.com/luxonis/robothub-images" \
--label "org.opencontainers.image.version=${IMAGE_VERSION}" \
--label "org.opencontainers.image.vendor=Luxonis" \
--label "org.opencontainers.image.ref.name=${IMAGE_REF_NAME}" \
--label "org.opencontainers.image.title=RobotHub App base image" \
--label "org.opencontainers.image.description=DepthAI version: ${DEPTHAI_VERSION}" \
--label "com.luxonis.rh.depthai.version=${DEPTHAI_VERSION}" \
--label "com.luxonis.rh.depthai-sdk.version=${DEPTHAI_SDK_VERSION}" \
--label "com.luxonis.rh.robothub.version=${ROBOTHUB_VERSION}" \
--tag "${TAG}" \
--push \
--provenance=false \
--file dockerfiles/base.Dockerfile \
context/
"${BUILD_ARGS[@]}" \
"${LABELS[@]}" \
--tag "${tag}" \
--provenance=false \
--push \
--file "dockerfiles/${dockerfile}" \
context/
}

# Define base parameters
BASE_DOCKERFILE="base.Dockerfile"
DEPTHAI_V3_DOCKERFILE_CONTEXT="depthai-v3-git"

declare -a elems=(
# RVC2 - DepthAI from registry:
"rvc2 ubuntu:22.04 minimal ${BASE_DOCKERFILE}"
"rvc2 ubuntu:22.04 regular ${BASE_DOCKERFILE}"
"rvc2 ros:humble-ros-core minimal ${BASE_DOCKERFILE}"
"rvc2 ros:humble-ros-base regular ${BASE_DOCKERFILE}"

# RVC3 - DepthAI from registry:
"rvc3 ubuntu:22.04 minimal ${BASE_DOCKERFILE}"
"rvc3 ubuntu:22.04 regular ${BASE_DOCKERFILE}"
"rvc3 ros:humble-ros-core minimal ${BASE_DOCKERFILE}"
"rvc3 ros:humble-ros-base regular ${BASE_DOCKERFILE}"

# RVC2 - DepthAI V3 - built from source:
"rvc2-depthaiV3 ubuntu:22.04 minimal ${DEPTHAI_V3_DOCKERFILE_CONTEXT}/${BASE_DOCKERFILE}"
"rvc2-depthaiV3 ubuntu:22.04 regular ${DEPTHAI_V3_DOCKERFILE_CONTEXT}/${BASE_DOCKERFILE}"
"rvc2-depthaiV3 ros:humble-ros-core minimal ${DEPTHAI_V3_DOCKERFILE_CONTEXT}/${BASE_DOCKERFILE}"
"rvc2-depthaiV3 ros:humble-ros-base regular ${DEPTHAI_V3_DOCKERFILE_CONTEXT}/${BASE_DOCKERFILE}"
)

for elem in "${elems[@]}"; do
read -ra strarr <<<"$elem"
build_and_push_image "${strarr[0]}" "${strarr[1]}" "${strarr[2]}" "${strarr[3]}"
done
2 changes: 1 addition & 1 deletion scripts/build-images-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ docker buildx build \
--label "org.opencontainers.image.ref.name=${IMAGE_REF_NAME}" \
--label "org.opencontainers.image.title=RobotHub App core image" \
--tag "${CORE_TAG}" \
--push \
--provenance=false \
--push \
--file dockerfiles/core.Dockerfile \
context/
Loading

0 comments on commit ba164f7

Please sign in to comment.