Skip to content

Commit af4b5d7

Browse files
authored
Add DevContainer CUDA support (#7)
* adding devcontainer cuda support * clean up autogenerated code * update gitignore * pre-commit
1 parent 08f4a9d commit af4b5d7

File tree

9 files changed

+356
-82
lines changed

9 files changed

+356
-82
lines changed

.devcontainer/.env

Lines changed: 0 additions & 4 deletions
This file was deleted.

.devcontainer/Dockerfile

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
1-
# Multi-version ROS2 development container
1+
# Multi-stage ROS2 development container (CPU/GPU compatible)
22
ARG ROS_DISTRO=humble
3-
FROM ros:${ROS_DISTRO}-ros-base
3+
ARG CUDA_VERSION=12.4.0
4+
ARG UBUNTU_VERSION=22.04
5+
6+
# ===============================================
7+
# CPU Base - Standard ROS2 image
8+
# ===============================================
9+
FROM ros:${ROS_DISTRO}-ros-base as cpu-base
10+
11+
# ===============================================
12+
# GPU Base - CUDA with manual ROS2 install
13+
# ===============================================
14+
FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION} as gpu-base
15+
ARG ROS_DISTRO
16+
17+
# Install ROS2 manually since we're not using the ros: base image
18+
# Set non-interactive to avoid geographic area prompts
19+
ENV DEBIAN_FRONTEND=noninteractive
20+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
21+
RUN apt-get update && apt-get install -y --no-install-recommends \
22+
curl \
23+
gnupg2 \
24+
lsb-release \
25+
tzdata \
26+
&& ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime \
27+
&& dpkg-reconfigure --frontend noninteractive tzdata \
28+
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \
29+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo "$UBUNTU_CODENAME") main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null \
30+
&& apt-get update && apt-get install -y --no-install-recommends \
31+
ros-${ROS_DISTRO}-ros-base \
32+
&& rm -rf /var/lib/apt/lists/*
33+
ENV DEBIAN_FRONTEND=interactive
34+
35+
# ===============================================
36+
# Install Common Development Tools from Either Base
37+
# ===============================================
38+
FROM ${TARGETARCH:-cpu}-base as dev-tools
439

540
# Install development tools not in base image
641
RUN apt-get update && apt-get install -y --no-install-recommends \
742
python3-pip \
843
python3-colcon-common-extensions \
944
python3-rosdep \
1045
openssh-client \
46+
git \
1147
curl \
1248
&& rm -rf /var/lib/apt/lists/*
1349

@@ -21,17 +57,23 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
2157
rm -rf /var/lib/apt/lists/*
2258

2359
# Install Claude Code CLI via npm
24-
RUN npm install -g @anthropic-ai/claude-code@1.0.0
60+
# hadolint ignore=DL3016
61+
RUN npm install -g @anthropic-ai/claude-code
2562

2663
# Initialize rosdep
2764
RUN rosdep init || true
2865

2966
# Set working dir (matches VSCode workspace)
3067
WORKDIR /deep_ros_ws
3168

32-
# Cater image to user
69+
# ===============================================
70+
# Add User Configuration
71+
# ===============================================
72+
FROM dev-tools as user-conf
3373
ARG USERNAME
74+
ARG ROS_DISTRO
3475

76+
# Cater image to user
3577
SHELL ["/bin/bash", "-c"]
3678
COPY .env /tmp/.env
3779
# hadolint ignore=SC2086

.devcontainer/devcontainer.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

.devcontainer/gen_env.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2025-present WATonomous. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
# generate_devcontainer.sh
17+
# Usage:
18+
# ./generate_devcontainer.sh <ros_distro> <container_type> [cuda_version] [ubuntu_version]
19+
20+
set -e
21+
22+
ROS_DISTRO=${1:-humble}
23+
CONTAINER_TYPE=${2:-cpu}
24+
CUDA_VERSION=${3:-12.4.0}
25+
UBUNTU_VERSION=${4:-22.04}
26+
USERNAME=${USER:-vscode}
27+
28+
echo "Generating devcontainer configuration..."
29+
echo "ROS Distribution: $ROS_DISTRO"
30+
echo "Container Type: $CONTAINER_TYPE"
31+
32+
if [ "$CONTAINER_TYPE" = "gpu" ]; then
33+
echo "CUDA Version: $CUDA_VERSION"
34+
echo "Ubuntu Version: $UBUNTU_VERSION"
35+
fi
36+
37+
# Generate container name and build args based on type
38+
if [ "$CONTAINER_TYPE" = "gpu" ]; then
39+
CONTAINER_NAME="ROS2 Development Container (GPU)"
40+
BUILD_ARGS='"ROS_DISTRO": "'$ROS_DISTRO'",
41+
"USERNAME": "'$USERNAME'",
42+
"TARGETARCH": "gpu",
43+
"CUDA_VERSION": "'$CUDA_VERSION'",
44+
"UBUNTU_VERSION": "'$UBUNTU_VERSION'",
45+
"USER_UID": "'$(id -u)'",
46+
"USER_GID": "'$(id -g)'"'
47+
RUN_ARGS='"--network=host",
48+
"--gpus=all"'
49+
else
50+
CONTAINER_NAME="ROS2 Development Container (CPU)"
51+
BUILD_ARGS='"ROS_DISTRO": "'$ROS_DISTRO'",
52+
"USERNAME": "'$USERNAME'",
53+
"TARGETARCH": "cpu",
54+
"USER_UID": "'$(id -u)'",
55+
"USER_GID": "'$(id -g)'"'
56+
RUN_ARGS='"--network=host"'
57+
fi
58+
59+
# Generate the devcontainer.json with shared structure
60+
cat > .devcontainer/devcontainer.json << EOF
61+
{
62+
"name": "$CONTAINER_NAME",
63+
"build": {
64+
"dockerfile": "Dockerfile",
65+
"args": {
66+
$BUILD_ARGS
67+
}
68+
},
69+
"runArgs": [
70+
$RUN_ARGS
71+
],
72+
"mounts": [
73+
"source=\${localWorkspaceFolder},target=/deep_ros_ws,type=bind,consistency=cached"
74+
],
75+
"customizations": {
76+
"vscode": {
77+
"extensions": [
78+
"ms-vscode.cpptools",
79+
"ms-python.python",
80+
"ms-vscode.cmake-tools",
81+
"redhat.vscode-yaml",
82+
"ms-iot.vscode-ros"
83+
],
84+
"settings": {
85+
"python.defaultInterpreterPath": "/usr/bin/python3",
86+
"terminal.integrated.shell.linux": "/bin/bash"
87+
}
88+
}
89+
},
90+
"remoteUser": "$USERNAME"
91+
}
92+
EOF
93+
94+
echo "Devcontainer configuration generated successfully!"
95+
echo "Files created:"
96+
echo " - .devcontainer/devcontainer.json"
97+
echo ""
98+
echo "Environment variables set for this session"
99+
echo ""
100+
echo "You can now:"
101+
echo " 1. Open the command palette (Ctrl+Shift+P)"
102+
echo " 2. Run 'Dev Containers: Rebuild and Reopen in Container'"

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
.claude/
1+
# ROS2 build artifacts
22
build/
33
install/
44
log/
5+
6+
# Autogenerated devcontainer files
7+
.devcontainer/devcontainer.json
8+
.devcontainer/.env
9+
10+
# Claude helpers
11+
.claude/
12+
CLAUDE.md

.vscode/c_cpp_properties.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "ROS2 Humble",
5+
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
6+
"includePath": [
7+
"${workspaceFolder}/**",
8+
"${workspaceFolder}/onnx_example_node/include/**",
9+
"${workspaceFolder}/onnx_example_node/third_party/onnxruntime-linux-x64-1.16.3/include/**",
10+
"${workspaceFolder}/deep_core/include/**",
11+
"${workspaceFolder}/deep_backends/**/include/**",
12+
"/opt/ros/humble/include/**"
13+
],
14+
"defines": [],
15+
"compilerPath": "/usr/bin/g++",
16+
"cStandard": "c99",
17+
"cppStandard": "c++17",
18+
"intelliSenseMode": "linux-gcc-x64",
19+
"browse": {
20+
"path": [
21+
"${workspaceFolder}",
22+
"/opt/ros/humble/include"
23+
],
24+
"limitSymbolsToIncludedHeaders": true,
25+
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
26+
}
27+
}
28+
],
29+
"version": 4
30+
}

.vscode/settings.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
3+
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
4+
"C_Cpp.intelliSenseEngine": "default",
5+
"C_Cpp.errorSquiggles": "enabled",
6+
"C_Cpp.autocomplete": "default",
7+
"files.associations": {
8+
"*.hpp": "cpp",
9+
"*.h": "cpp",
10+
"cctype": "cpp",
11+
"clocale": "cpp",
12+
"cmath": "cpp",
13+
"csignal": "cpp",
14+
"cstdarg": "cpp",
15+
"cstddef": "cpp",
16+
"cstdio": "cpp",
17+
"cstdlib": "cpp",
18+
"cstring": "cpp",
19+
"ctime": "cpp",
20+
"cwchar": "cpp",
21+
"cwctype": "cpp",
22+
"array": "cpp",
23+
"atomic": "cpp",
24+
"strstream": "cpp",
25+
"bit": "cpp",
26+
"*.tcc": "cpp",
27+
"bitset": "cpp",
28+
"chrono": "cpp",
29+
"compare": "cpp",
30+
"concepts": "cpp",
31+
"condition_variable": "cpp",
32+
"cstdint": "cpp",
33+
"deque": "cpp",
34+
"list": "cpp",
35+
"map": "cpp",
36+
"set": "cpp",
37+
"string": "cpp",
38+
"unordered_map": "cpp",
39+
"unordered_set": "cpp",
40+
"vector": "cpp",
41+
"exception": "cpp",
42+
"algorithm": "cpp",
43+
"functional": "cpp",
44+
"iterator": "cpp",
45+
"memory": "cpp",
46+
"memory_resource": "cpp",
47+
"numeric": "cpp",
48+
"optional": "cpp",
49+
"random": "cpp",
50+
"ratio": "cpp",
51+
"regex": "cpp",
52+
"string_view": "cpp",
53+
"system_error": "cpp",
54+
"tuple": "cpp",
55+
"type_traits": "cpp",
56+
"utility": "cpp",
57+
"fstream": "cpp",
58+
"future": "cpp",
59+
"initializer_list": "cpp",
60+
"iomanip": "cpp",
61+
"iosfwd": "cpp",
62+
"iostream": "cpp",
63+
"istream": "cpp",
64+
"limits": "cpp",
65+
"mutex": "cpp",
66+
"new": "cpp",
67+
"numbers": "cpp",
68+
"ostream": "cpp",
69+
"semaphore": "cpp",
70+
"shared_mutex": "cpp",
71+
"sstream": "cpp",
72+
"stdexcept": "cpp",
73+
"stop_token": "cpp",
74+
"streambuf": "cpp",
75+
"thread": "cpp",
76+
"cinttypes": "cpp",
77+
"typeindex": "cpp",
78+
"typeinfo": "cpp",
79+
"variant": "cpp"
80+
},
81+
"cmake.configureOnOpen": false,
82+
"cmake.buildDirectory": "${workspaceFolder}/build",
83+
"ros.distro": "humble"
84+
}

0 commit comments

Comments
 (0)