Skip to content

Commit

Permalink
Baseimage upgrade to support multi-arch builds (#62)
Browse files Browse the repository at this point in the history
* Enable multi-arch builds

* Edit workflow to run builds for separate architectures

* Cross compile using Yocto SDK

* Upgrade run-time base image

* Update baseimage, rename the dockerfiles

* Remove question marks in workflow dispatch inputs

* Update baseimage version to v3.0.0 release

* Fix docker tags of PR

* Upgrade baseimage version to v3.0.1

* Change caching method, add comments as requested

* Parallel build for multiple architectures

---------

Co-authored-by: Jari Hodju <[email protected]>
  • Loading branch information
mehmetkillioglu and jari-hodju authored Oct 10, 2023
1 parent 1e468e8 commit 3b932eb
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 106 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

.circleci/
.vscode/
.github/
.dockerignore
.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
150 changes: 128 additions & 22 deletions .github/workflows/tii-depthai-ctrl.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,162 @@
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

env:
REGISTRY_IMAGE: ghcr.io/tiiuae/tii-depthai-ctrl

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
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
matrix_json="{\"include\": ["
for platform in "${matrix_list[@]}"; do
matrix_json+="{\"platform\":\"$platform\"},"
done
matrix_json="${matrix_json%,}]}"
echo "::set-output name=matrix::$matrix_json"
echo $matrix_json
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
outputs:
short_git_sha: ${{ steps.vars.outputs.SHORT_GIT_SHA }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: docker/setup-buildx-action@v2
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}

- name: Set image tag format without suffix
run: |
echo "IMAGE_TAG_FORMAT=type=sha" >> $GITHUB_ENV
if: github.event_name == 'push'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set image tag format with suffix
# it is possible that run_number should be used instead run_attempt
# run_attempt is unique number on every run and run_attempt resets to 1 if re-build is not used
# content of image_sha_tag_suffix is defined in fog-ros-baseimage dispatcher workflow.
- name: Set short git commit SHA
id: vars
run: |
echo "IMAGE_TAG_FORMAT=type=sha,suffix=-${{ github.event.client_payload.image_sha_tag_suffix }}" >> $GITHUB_ENV
if: github.event_name == 'repository_dispatch'
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "SHORT_GIT_SHA=$calculatedSha" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/tiiuae/tii-depthai-ctrl
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=latest
${{ env.IMAGE_TAG_FORMAT }}
type=ref,event=branch,suffix=-${{ matrix.platform }}
type=ref,event=pr,suffix=-${{ matrix.platform }}
type=semver,pattern={{version}},suffix=-${{ matrix.platform }}
type=sha,suffix=-${{ matrix.platform }}
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) && matrix.platform == 'amd64' }}
- 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: linux/${{ matrix.platform }}
pull: true
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 }}
provenance: false

merge:
runs-on: ubuntu-latest
needs:
- prepare
- build
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create combined image
run : |
AMEND_LIST=""
for platform in $(echo '${{ needs.prepare.outputs.matrix }}' | jq -r '.include[].platform'); do
echo "Adding ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }}-$platform to the amend list"
AMEND_LIST+="--amend ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }}-$platform "
done
docker manifest create ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }} $AMEND_LIST
- name: Push image to the registry
run: |
docker manifest push ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }}
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
Loading

0 comments on commit 3b932eb

Please sign in to comment.