Skip to content

Commit

Permalink
Merge pull request #3 from ethz-asl/pr-container-readme
Browse files Browse the repository at this point in the history
Devcontainer + README + learning models / interface
  • Loading branch information
marcojob authored Nov 5, 2024
2 parents 5b6e0bb + 4c03a36 commit 42d78a0
Show file tree
Hide file tree
Showing 19 changed files with 737 additions and 763 deletions.
67 changes: 67 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Base Stage: ROS and CUDA Installation
FROM ros:noetic-ros-core AS base

ARG TZ=Europe/Zurich
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="${PATH}:/opt/hpcx/ompi/bin"

# All apt packages
COPY .devcontainer/devcontainer_all_packages.sh /tmp/devcontainer_all_packages.sh
RUN /tmp/devcontainer_all_packages.sh && rm -f /tmp/devcontainer_all_packages.sh

ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US:en" \
LC_ALL="en_US.UTF-8"

# Add user "asl" with sudo rights
RUN groupadd -r asl && \
useradd --create-home --gid asl --groups dialout,plugdev --shell /bin/bash asl && \
mkdir -p /etc/sudoers.d && \
echo 'asl ALL=NOPASSWD: ALL' > /etc/sudoers.d/asl

# CUDA: Install
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb && \
sudo dpkg -i cuda-keyring_1.1-1_all.deb && \
sudo apt update && \
sudo apt -y install cuda-toolkit-12-6 cudnn9-cuda-12

# CUDA: Add PATH and LD_LIBRARY_PATH to .bash_aliases
RUN echo 'export PATH=$PATH:/usr/local/cuda/bin' >> /home/asl/.bash_aliases && \
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64' >> /home/asl/.bash_aliases

# TensorRT: Install from .deb file
COPY resources/nv-tensorrt-repo-ubuntu2004-cuda11.6-trt8.4.3.1-ga-20220813_1-1_amd64.deb /tmp/
RUN sudo dpkg -i /tmp/resources/nv-tensorrt-repo-ubuntu2004-cuda11.6-trt8.4.3.1-ga-20220813_1-1_amd64.deb || sudo apt-get install -f -y
# RUN sudo cp /var/nv-tensorrt-repo-ubuntu2004-cuda11.6-trt8.4.3.1-ga-20220813/*-keyring.gpg /usr/share/keyrings/ && sudo apt update && sudo apt install -y tensorrt
RUN sudo apt update && sudo apt install -y tensorrt

# OpenCV Build Stage
FROM base AS opencv_build

# OpenCV 4.10.0 install
COPY .devcontainer/build_opencv.sh /tmp/build_opencv.sh
RUN bash /tmp/build_opencv.sh && rm -rf /tmp/build_opencv.sh

# Final Stage: Combine ROS, CUDA, and OpenCV
FROM base AS final

# Copy OpenCV installation from the build stage
COPY --from=opencv_build /usr/local /usr/local

# Git-prompt: Source
RUN echo 'if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then GIT_PROMPT_ONLY_IN_REPO=1; source "$HOME/.bash-git-prompt/gitprompt.sh"; fi' >> /home/asl/.bash_aliases

# ROS: Source
RUN echo "source /opt/ros/noetic/setup.bash" >> /home/asl/.bash_aliases

# ROS: rosdep install (TODO: maybe not so clean?)
RUN sudo rosdep init
USER asl
RUN rosdep update
COPY package.xml /tmp/
RUN rosdep install --from-paths /tmp/ --ignore-src -r -y -v
USER root

# Clean up
RUN rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* /var/cache/apt/archives/*
ENTRYPOINT ["/bin/bash"]
1 change: 1 addition & 0 deletions .devcontainer/build_and_push_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker buildx build --tag omavteam/v4l2_camera:latest -f .devcontainer/Dockerfile --push .
77 changes: 61 additions & 16 deletions scripts/build_opencv.sh → .devcontainer/build_opencv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
readonly PREFIX=/usr/local # install prefix, (can be ~/.local for a user install)
readonly DEFAULT_VERSION=4.10.0 # controls the default version (gets reset by the first argument)
readonly CPUS=$(nproc) # controls the number of jobs
readonly BUILD_DIR="/home/asl/Downloads"
readonly BUILD_DIR="/tmp"

# better board detection. if it has 6 or more cpus, it probably has a ton of ram too
if [[ $CPUS -gt 5 ]]; then
Expand All @@ -26,7 +26,7 @@ cleanup () {
echo "(Doing so may make running tests on the build later impossible)"
fi
# read -p "Y/N " yn
yn="n"
yn="n"
case ${yn} in
[Yy]* ) rm -rf $BUILD_DIR/build_opencv ; break;;
[Nn]* ) break ;;
Expand Down Expand Up @@ -102,19 +102,62 @@ install_dependencies () {
zlib1g-dev
}

configure () {
# Automatically detect installed CUDA version
detect_cuda_version() {
if command -v /usr/local/cuda/bin/nvcc &> /dev/null; then
CUDA_VERSION=$(/usr/local/cuda/bin/nvcc --version | grep -oP 'release \K[0-9]+\.[0-9]+')
else
echo "CUDA not found. Please install CUDA before running this script."
exit 1
fi
}

# Automatically detect installed cuDNN version
detect_cudnn_version() {
if [[ -f "/usr/include/cudnn_version.h" ]]; then
CUDNN_MAJOR=$(grep -oP '(?<=#define CUDNN_MAJOR )\d+' /usr/include/cudnn_version.h)
CUDNN_MINOR=$(grep -oP '(?<=#define CUDNN_MINOR )\d+' /usr/include/cudnn_version.h)
CUDNN_PATCHLEVEL=$(grep -oP '(?<=#define CUDNN_PATCHLEVEL )\d+' /usr/include/cudnn_version.h)
CUDNN_VERSION="${CUDNN_MAJOR}.${CUDNN_MINOR}.${CUDNN_PATCHLEVEL}"
else
echo "cuDNN not found. Please install cuDNN before running this script."
exit 1
fi
}

# Set CUDA compute capabilities based on detected CUDA version
set_cuda_arch_bin() {
case "$CUDA_VERSION" in
11.*)
CUDA_ARCH_BIN="5.3,6.1,6.2,7.0,7.5,8.0"
;;
12.*)
CUDA_ARCH_BIN="6.1,6.2,7.5,8.0,8.6,8.7"
;;
*)
echo "Unsupported CUDA version detected: $CUDA_VERSION"
exit 1
;;
esac
}

# Update the configure function to use dynamic CUDA and cuDNN version detection
configure() {
detect_cuda_version
detect_cudnn_version
set_cuda_arch_bin

local CMAKEFLAGS="
-D BUILD_EXAMPLES=OFF
-D BUILD_opencv_python2=ON
-D BUILD_opencv_python3=ON
-D BUILD_opencv_python2=OFF
-D BUILD_opencv_python3=OFF
-D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=${PREFIX}
-D CUDA_ARCH_BIN=5.3,6.2,7.2,8.7
-D CUDA_ARCH_PTX=
-D CUDA_ARCH_BIN=${CUDA_ARCH_BIN}
-D CUDA_FAST_MATH=ON
-D CUDNN_VERSION='8.4.1'
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3
-D ENABLE_NEON=ON
-D CUDNN_VERSION='${CUDNN_VERSION}'
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3
-D ENABLE_NEON=OFF
-D OPENCV_DNN_CUDA=ON
-D OPENCV_ENABLE_NONFREE=ON
-D OPENCV_EXTRA_MODULES_PATH=$BUILD_DIR/build_opencv/opencv_contrib/modules
Expand All @@ -133,9 +176,11 @@ configure () {
-D BUILD_TESTS=OFF"
fi

echo "CUDA version: $CUDA_VERSION"
echo "cuDNN version: $CUDNN_VERSION"
echo "CUDA_ARCH_BIN: $CUDA_ARCH_BIN"
echo "cmake flags: ${CMAKEFLAGS}"

cd opencv
cd $BUILD_DIR/build_opencv/opencv
mkdir -p build
cd build
cmake ${CMAKEFLAGS} .. 2>&1 | tee -a configure.log
Expand All @@ -156,10 +201,10 @@ main () {

# prepare for the build:
setup
install_dependencies
if [[ ! -d "$BUILD_DIR/build_opencv" ]] ; then
git_source ${VER}
fi
# install_dependencies
# if [[ ! -d "$BUILD_DIR/build_opencv" ]] ; then
git_source ${VER}
# fi

if [[ ${DO_TEST} ]] ; then
configure test
Expand Down
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"image": "omavteam/v4l2_camera:latest",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python"
],
"settings": {
"files.hotExit": "off",
"window.restoreWindows": "none",
"workbench.startupEditor": "none"
}
}
},
"remoteEnv": {
"DISPLAY": "${localEnv:DISPLAY}"
},
"remoteUser": "asl",
"initializeCommand": ".devcontainer/devcontainer_optional_mounts.sh",
"mounts": [
{
"source": "${localEnv:HOME}/.bash-git-prompt",
"target": "/home/asl/.bash-git-prompt",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.cache",
"target": "/home/asl/.cache",
"type": "bind"
}
],
"runArgs": [
"--gpus",
"all",
"--privileged",
"--device=/dev/dri:/dev/dri",
"-v",
"/tmp/.X11-unix:/tmp/.X11-unix",
"-v",
"/dev/bus/usb:/dev/bus/usb",
"--net=host"
]
}
87 changes: 87 additions & 0 deletions .devcontainer/devcontainer_all_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

set -eux
export DEBIAN_FRONTEND=noninteractive

main() {
local pkgs=(
apt-transport-https
build-essential
ca-certificates
ccache
cmake
curl
gfortran
git
gnupg
htop
libatlas-base-dev
libavcodec-dev
libavformat-dev
libavresample-dev
libcanberra-gtk3-module
libdc1394-22-dev
libeigen3-dev
libglew-dev
libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev
libgstreamer1.0-dev
libgtk-3-dev
libjpeg-dev
libjpeg-turbo8-dev
libjpeg8-dev
liblapack-dev
liblapacke-dev
libopenblas-dev
libpng-dev
libpostproc-dev
libswscale-dev
libtbb-dev
libtbb2
libtesseract-dev
libtiff-dev
libv4l-dev
libx264-dev
libxine2-dev
libxvidcore-dev
locales
net-tools
pkg-config
python-dev
python-numpy
python3-dev
python3-matplotlib
python3-numpy
python3-rosdep
qv4l2
software-properties-common
ssh
sudo
udev
unzip
v4l-utils
vim
wget
zlib1g
zlib1g-dev
)

apt-get update
apt-get upgrade -y
apt-get -y --quiet --no-install-recommends install "${pkgs[@]}"

mkdir -p /root/.ssh \
&& chmod 0700 /root/.ssh \
&& ssh-keyscan github.com > /root/.ssh/known_hosts

ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone
sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen
locale-gen en_US.UTF-8
dpkg-reconfigure locales

apt-get -y autoremove
apt-get clean autoclean
rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
}

main "$@"
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer_optional_mounts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [ ! -d "$HOME/.bash-git-prompt" ]; then
mkdir "$HOME/.bash-git-prompt"
fi

if [ ! -d "$HOME/.cache" ]; then
mkdir "$HOME/.cache"
fi
59 changes: 0 additions & 59 deletions .github/actions/generate-doxybook/action.yml

This file was deleted.

Loading

0 comments on commit 42d78a0

Please sign in to comment.