Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseimage upgrade to support multi-arch builds #62

Merged
merged 12 commits into from
Oct 10, 2023
Merged
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
.gitignore
**Dockerfile
**.Dockerfile
Dockerfile.**
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ updates:
directory: "/"
schedule:
interval: "daily"
groups:
baseimage-dependencies:
patterns:
- "tiiuae/fog-ros-sdk"
- "tiiuae/fog-ros-baseimage-builder"
- "tiiuae/fog-ros-baseimage"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
81 changes: 74 additions & 7 deletions .github/workflows/tii-depthai-ctrl.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,81 @@
name: tii-depthai-ctrl

on:
repository_dispatch:
types: [fog-ros-baseimage-update]
push:
pull_request:
workflow_dispatch:
inputs:
build_amd64:
description: 'Build for AMD64'
required: true
default: true
type: boolean
build_arm64:
description: 'Build for ARM64'
required: true
default: false
type: boolean
build_riscv64:
description: 'Build for RISCV64'
required: true
default: false
type: boolean

permissions:
contents: read
packages: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: docker/setup-buildx-action@v2
- name: Determine platforms
id: platforms
run: |
qemu_platforms=""
docker_platforms=""
default_branch="${{ github.event.repository.default_branch }}"

matrix_list=()

if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/$default_branch" ]]; then
matrix_list=("amd64" "arm64" "riscv64")
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.base_ref }}" == "$default_branch" ]]; then
matrix_list=("amd64" "arm64" "riscv64")
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event.inputs.build_amd64 }}" == 'true' ]]; then
matrix_list+=("amd64")
fi
if [[ "${{ github.event.inputs.build_arm64 }}" == 'true' ]]; then
matrix_list+=("arm64")
fi
if [[ "${{ github.event.inputs.build_riscv64 }}" == 'true' ]]; then
matrix_list+=("riscv64")
fi
else
# Maybe push or some other trigger
matrix_list=("amd64")
fi
for platform in "${matrix_list[@]}"; do
qemu_platforms+="$platform,"
docker_platforms+="linux/$platform,"
done

echo "qemu=${qemu_platforms%?}" >> $GITHUB_OUTPUT
echo "docker=${docker_platforms%?}" >> $GITHUB_OUTPUT
echo "Building for $qemu_platforms"

- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ steps.platforms.outputs.qemu }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set image tag format without suffix
run: |
Expand All @@ -31,26 +92,32 @@ jobs:

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/tiiuae/tii-depthai-ctrl
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=latest
${{ env.IMAGE_TAG_FORMAT }}
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build container image and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: ${{ steps.platforms.outputs.docker }}
push: true
no-cache: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
64 changes: 40 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
cmake_minimum_required(VERSION 3.5)

# Without enabling languages, find_package(depthai) fails when it is found in the system
# It then tries to run find_package(Threads) and that causes an error.
# Can't define the project(..) here as well, because it then makes hunter to fail
enable_language(C)
enable_language(C CXX)
set(CMAKE_BUILD_TYPE Release)

# all these settings are needed to properly compile depthai-core as subdirectory
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_definitions(-DSPDLOG_ACTIVE_LEVEL=6)
add_definitions(-DSPDLOG_HEADER_ONLY=1)
add_definitions(-DFMT_HEADER_ONLY=1)
set(HUNTER_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE}) # makes possible to compile also Debug build
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/depthai-core ${CMAKE_CURRENT_BINARY_DIR}/depthai-core EXCLUDE_FROM_ALL)
message(STATUS "-*-*-*- trying to find depthai library -*-*-*-")
find_package(depthai QUIET)
if(depthai_FOUND)
message(STATUS "-*-*-*- depthai found -*-*-*-")
else()
message(STATUS "-*-*-*- depthai not found -*-*-*-")
add_definitions(-DSPDLOG_ACTIVE_LEVEL=6)
add_definitions(-DSPDLOG_HEADER_ONLY=1)
add_definitions(-DFMT_HEADER_ONLY=1)
set(HUNTER_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE}) # makes possible to compile also Debug build
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/depthai-core ${CMAKE_CURRENT_BINARY_DIR}/depthai-core EXCLUDE_FROM_ALL)
endif()

option(BUILD_GSTREAMER "enable building gstreamer" OFF)
if(DEFINED ENV{BUILD_GSTREAMER})
set(BUILD_GSTREAMER "$ENV{BUILD_GSTREAMER}")
endif()

project(depthai_ctrl)
project(depthai_ctrl LANGUAGES CXX C)

# pkg-config configurations path.
if(NOT DEFINED ENV{PKG_CONFIG_PATH})
set(ENV{PKG_CONFIG_PATH} "/usr/lib/x86_64-linux-gnu/pkgconfig/")
else()
string(FIND "/usr/lib/x86_64-linux-gnu/pkgconfig/" $ENV{PKG_CONFIG_PATH} POS_INC_PATH)
if(${POS_INC_PATH} STREQUAL "-1")
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig/")
endif()
endif()
# # pkg-config configurations path.
# if(NOT DEFINED ENV{PKG_CONFIG_PATH})
# set(ENV{PKG_CONFIG_PATH} "/usr/lib/x86_64-linux-gnu/pkgconfig/")
# else()
# string(FIND "/usr/lib/x86_64-linux-gnu/pkgconfig/" $ENV{PKG_CONFIG_PATH} POS_INC_PATH)
# if(${POS_INC_PATH} STREQUAL "-1")
# set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig/")
# endif()
# endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -44,7 +58,11 @@ if(NOT OpenCV_FOUND)
find_package(OpenCV ${opencv_version} REQUIRED COMPONENTS imgproc highgui)
endif()

#find_package(ament_cmake REQUIRED)
find_package(ament_cmake REQUIRED)
# find_package(libyaml_vendor REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(yaml REQUIRED)

find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(image_transport REQUIRED)
Expand All @@ -54,8 +72,6 @@ find_package(sensor_msgs REQUIRED)
find_package(stereo_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(vision_msgs REQUIRED)
find_package(PkgConfig REQUIRED)


find_package(nlohmann_json REQUIRED)

Expand Down Expand Up @@ -104,13 +120,13 @@ target_link_libraries(depthai_bridge PUBLIC depthai-core opencv_imgproc opencv_h
message(STATUS "--------------------------$ENV{ROS_DISTRO} ---")
message(STATUS $ENV{ROS_DISTRO})

if($ENV{ROS_DISTRO} STREQUAL "galactic" OR ($ENV{ROS_DISTRO} STREQUAL "rolling" AND "${ubuntu_version}" STREQUAL "20.04\n"))
target_compile_definitions(depthai_bridge PRIVATE IS_GALACTIC)
endif()
# if($ENV{ROS_DISTRO} STREQUAL "galactic" OR ($ENV{ROS_DISTRO} STREQUAL "rolling" AND "${ubuntu_version}" STREQUAL "20.04\n"))
# target_compile_definitions(depthai_bridge PRIVATE IS_GALACTIC)
# endif()

if($ENV{ROS_DISTRO} STREQUAL "humble")
# if($ENV{ROS_DISTRO} STREQUAL "humble")
target_compile_definitions(depthai_bridge PRIVATE IS_HUMBLE)
endif()
# endif()

# DepthAI Camera as Component library
add_library(depthai_camera SHARED src/depthai_camera.cpp)
Expand Down
96 changes: 41 additions & 55 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
FROM ghcr.io/tiiuae/fog-ros-baseimage-builder:v2.1.0 AS builder
ARG BUILD_GSTREAMER
# TODO: not sure how many of these deps are actually needed for building. at least this:
# libusb-1.0-0-dev
# gstreamer-1.0 (<-- but not sure which package brings this)
RUN apt-get update -y && apt-get install -y --no-install-recommends \
libusb-1.0-0-dev \
nlohmann-json3-dev \
libopencv-dev \
&& rm -rf /var/lib/apt/lists/*
FROM --platform=${BUILDPLATFORM:-linux/amd64} ghcr.io/tiiuae/fog-ros-sdk:v3.0.0-${TARGETARCH:-amd64} AS builder

ARG TARGETARCH

RUN if [ -n "$BUILD_GSTREAMER" ]; then \
apt-get update -y && apt-get install -y --no-install-recommends \
libgstreamer1.0-0 \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
libgstreamer-plugins-good1.0-dev \
libgstrtspserver-1.0-dev \
libgstreamer-plugins-base1.0-0 \
libgstreamer-plugins-good1.0-0 \
gstreamer1.0-x \
&& rm -rf /var/lib/apt/lists/*; \
fi
RUN apt update \
&& apt install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN curl https://artifacts.luxonis.com/artifactory/luxonis-depthai-data-local/network/yolo-v4-tiny-tf_openvino_2021.4_6shave.blob \
-o /tmp/yolo-v4-tiny-tf_openvino_2021.4_6shave.blob

COPY . /main_ws/src/

RUN if [ -n "$BUILD_GSTREAMER" ]; then \
mv /main_ws/src/debian/control.em.gstreamer /main_ws/src/debian/control.em; \
fi
# There is a file at /sdk_install/sysroots/core2-64-oe-linux/usr/include/depthai-shared/common/optional.hpp which has the
# which has the line '#include "tl/optional.hpp"', change it to this with sed: '#include "depthai-shared/3rdparty/tl/optional.hpp"'
RUN YOCTO_TARGET_ARCH=$(/packaging/arch_translation.sh ${TARGETARCH:-amd64}) && \
sed -i 's/#include "tl\/optional.hpp"/#include "depthai-shared\/3rdparty\/tl\/optional.hpp"/g' /sdk_install/sysroots/${YOCTO_TARGET_ARCH}-oe-linux/usr/include/depthai-shared/common/optional.hpp && \
sed -i 's/#include "tl\/optional.hpp"/#include "depthai-shared\/3rdparty\/tl\/optional.hpp"/g' /sdk_install/sysroots/${YOCTO_TARGET_ARCH}-oe-linux/usr/include/depthai/pipeline/Node.hpp

# CV Bridge cmake file has host contamination, which leads to failure in the build.
# This hardcoded path will be different for each of the build. So, the sed command should find the place using OpenCV_CONFIG_PATH and OpenCV_INSTALL_PATH tags
RUN YOCTO_TARGET_ARCH=$(/packaging/arch_translation.sh ${TARGETARCH:-amd64}) && \
sed -i 's/set(OpenCV_CONFIG_PATH .*)/set(OpenCV_CONFIG_PATH \/sdk_install\/sysroots\/${YOCTO_TARGET_ARCH}-oe-linux\/usr\/lib\/cmake\/opencv4)/g' /sdk_install/sysroots/${YOCTO_TARGET_ARCH}-oe-linux/usr/share/cv_bridge/cmake/cv_bridge-extras.cmake && \
sed -i 's/set(OpenCV_INSTALL_PATH .*)/set(OpenCV_INSTALL_PATH \/sdk_install\/sysroots\/${YOCTO_TARGET_ARCH}-oe-linux\/usr)/g' /sdk_install/sysroots/${YOCTO_TARGET_ARCH}-oe-linux/usr/share/cv_bridge/cmake/cv_bridge-extras.cmake

WORKDIR /main_ws

# this:
# 1) builds the application
# 2) packages the application as .deb in /main_ws/
RUN BUILD_GSTREAMER=$BUILD_GSTREAMER /packaging/build.sh
RUN /packaging/build_colcon_sdk.sh ${TARGETARCH:-amd64}

# ▲ runtime ──┐
# └── build ▼

FROM ghcr.io/tiiuae/fog-ros-baseimage:v2.1.0
ARG BUILD_GSTREAMER
FROM ghcr.io/tiiuae/fog-ros-baseimage:v3.0.0

RUN mkdir /depthai_configs
COPY --from=builder /main_ws/src/params /depthai_configs/.
Expand All @@ -53,29 +44,24 @@ ENTRYPOINT [ "/entrypoint.sh" ]

COPY entrypoint.sh /entrypoint.sh

COPY --from=builder /main_ws/ros-*-depthai-ctrl_*_amd64.deb /depthai.deb
# need update because ROS people have a habit of removing old packages pretty fast
RUN apt-get update -y && apt-get install -y --no-install-recommends \
libusb-1.0-0-dev \
libopencv-dev \
ros-${ROS_DISTRO}-vision-msgs \
ros-${ROS_DISTRO}-camera-info-manager \
ros-${ROS_DISTRO}-cv-bridge \
ros-${ROS_DISTRO}-robot-state-publisher \
ros-${ROS_DISTRO}-image-transport \
ros-$ROS_DISTRO-xacro \
RUN apt update \
&& apt install -y --no-install-recommends \
libusb-1.0-0 \
eudev-staticdev \
nlohmann-json-dev \
yaml-cpp-vendor \
cv-bridge \
vision-msgs \
camera-info-manager \
camera-calibration-parsers \
xacro \
image-transport \
libyaml-cpp0.6 \
libyaml-0-staticdev \
libyaml-vendor \
libopencv-ts \
opencv-staticdev \
libdepthai-core20 \
&& rm -rf /var/lib/apt/lists/*

RUN if [ -n "$BUILD_GSTREAMER" ]; then \
apt-get update -y && apt-get install -y --no-install-recommends \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gir1.2-gst-rtsp-server-1.0 \
gstreamer1.0-libav \
gstreamer1.0-rtsp \
&& rm -rf /var/lib/apt/lists/*; \
fi

RUN ln -s /usr/bin/true /usr/bin/udevadm \
&& dpkg -i /depthai.deb && rm /depthai.deb \
&& rm -f /usr/bin/udevadm
COPY --from=builder $INSTALL_DIR $INSTALL_DIR
Loading
Loading