├── .gitignore ├── README.md ├── ros1 ├── .devcontainer │ ├── Dockerfile │ ├── devcontainer.json │ ├── initialize.sh │ └── postCreate.sh ├── .gitignore ├── .vscode │ ├── c_cpp_properties.json │ ├── launch.json │ └── settings.json ├── compile_debug.sh ├── compile_release.sh ├── initialize_workspace.sh └── merge_compile_commands.sh └── ros2 ├── .devcontainer ├── Dockerfile ├── devcontainer.json ├── initialize.sh └── postCreate.sh ├── .gitignore ├── .vscode ├── c_cpp_properties.json └── settings.json └── compile_release.sh /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/ 2 | /ros1/src/ 3 | /ros2/src/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ROS devcontainer 2 | 3 | Provides an easy setup of ROS with the Dev Container extension of VS Code. 4 | The setup was originally created using the [VS Code Docker Guide](https://docs.ros.org/en/humble/How-To-Guides/Setup-ROS-2-with-VSCode-and-Docker-Container.html) in the ROS 2 documentation, but has been modified. 5 | 6 | ## Prerequisites 7 | 8 | You have to install VS Code, Docker, and the Dev Container extension for VS Code. 9 | The installation of VS Code on Ubuntu is described [here](https://code.visualstudio.com/docs/setup/linux). 10 | For a guide to set up dev containers, check out [this tutorial](https://code.visualstudio.com/docs/devcontainers/tutorial). 11 | For installing docker on Ubuntu, you can use the docker apt repository, as described in the [docker docs](https://docs.docker.com/engine/install/ubuntu/). 12 | The official docker packages of Ubuntu may also work, but may be older versions. 13 | 14 | ## NVIDIA GPU acceleration 15 | 16 | To enable GPU acceleration in the containers, make sure you also install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html). Note: If you already have the CUDA apt repository set up, it includes the nvidia-container-toolkit package, so you don't need to add the nvidia-container apt repository. Run: 17 | 18 | ``` 19 | sudo apt-get install -y nvidia-container-toolkit 20 | sudo nvidia-ctk runtime configure --runtime=docker 21 | sudo systemctl restart docker 22 | ``` 23 | 24 | In devcontainer.json, make sure "--gpus", "all" is added to runArgs (this is already the case for the workspaces in this repository), or configure it to use a specific device. 25 | 26 | ## Workspace setup 27 | 28 | The ros1 and ros2 folders contain a hidden .devcontainer folder with the configuration files for the container. 29 | To start up the container, you can press F1 and search for "Dev Containers: Open Folder in Container...", then select either ros1 or ros2. 30 | Alternatively, you can navigate to the folder in a terminal and open it with "code .". 31 | VS Code should recognize the .devcontainer configuration and ask you if you want to reopen the folder in the container. 32 | If it doesn't, you can also press F1 and search for "Dev Containers: Rebuild and Reopen in Container". 33 | If you change your configuration while being inside of the container and need to rebuild it, select "Dev Containers: Rebuild Container". 34 | 35 | You may want to modify the files for your setup: 36 | 37 | ### devcontainer.json 38 | 39 | The entry point for the devcontainer. 40 | You may want to change the DOCKER_REPO, ROS_DISTRO and IMAGE_SUFFIX variables. 41 | More information on which base image to choose can be found in the README of the [OSRF docker images repository](https://github.com/osrf/docker_images). 42 | It also by default mounts the .ssh directory from your home folder into the docker home directory, so that you can use your keys from within. 43 | This may not be necessary depending on your use case (devcontainers also have a [built-in functionality](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials) to share git credentials and ssh keys). 44 | 45 | ### Dockerfile 46 | 47 | Pulls the docker image for the specified distribution. 48 | Note that there are different versions of docker images with preinstalled packages available, so depending on your use case, you might want to switch to one of those (see devcontainer.json). 49 | Also installs some basic packages. 50 | You can add additional packages or remove the ones you don't need. 51 | Workspace dependencies will be installed via rosdep when the container is started via the postCreateCommand, but these packages might have to be reinstalled if you change the workspace and have additional dependencies. 52 | So it could be worth it to manually check your dependencies and add those here. 53 | These will then be cached by Docker, so as long as you don't change the Dockerfile, you will not need to reinstall them. 54 | 55 | ### initialize.sh 56 | 57 | This file is executed on the host machine during initialization. 58 | Currently not used. 59 | 60 | ### postCreate.sh 61 | 62 | This file is executed after the container has been created. 63 | It installs missing workspace dependencies via rosdep and gives the container user ownership of the mounted workspace folder. 64 | It also initializes and builds the workspace. 65 | 66 | ## Create a workspace for a specific setup 67 | 68 | This repository is meant to provide the base configurations to create a ROS workspace. 69 | It is not meant to contain any packages. 70 | To create a workspace for a specific setup, e.g. a robot or a set of packages, copy either the contents of ros1 or ros2 into a new git repository. 71 | Then, you can add the required packages as submodules into the src folder of that directory. -------------------------------------------------------------------------------- /ros1/.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG DOCKER_REPO 2 | ARG ROS_DISTRO 3 | ARG IMAGE_SUFFIX 4 | FROM $DOCKER_REPO:$ROS_DISTRO$IMAGE_SUFFIX 5 | ARG USERNAME 6 | ARG USER_UID=1000 7 | ARG USER_GID=$USER_UID 8 | 9 | # Create the user 10 | RUN groupadd --gid $USER_GID $USERNAME \ 11 | && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ 12 | && apt-get update \ 13 | && apt-get install -y sudo \ 14 | && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ 15 | && chmod 0440 /etc/sudoers.d/$USERNAME 16 | # Install additonal packages - add any that you need 17 | RUN apt-get update && apt-get upgrade -y && \ 18 | apt-get install -y python3-pip python-is-python3 python3-catkin-tools jq ssh neovim git 19 | ENV SHELL /bin/bash 20 | 21 | # Source ROS environment automatically 22 | RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /home/$USERNAME/.bashrc 23 | RUN echo "source /home/ws/devel_release/setup.bash" >> /home/$USERNAME/.bashrc 24 | 25 | # Set the default user 26 | USER $USERNAME 27 | CMD ["/bin/bash"] 28 | -------------------------------------------------------------------------------- /ros1/.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ROS Development Container", 3 | "privileged": true, 4 | "remoteUser": "${localEnv:USER}", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | "args": { 8 | "USERNAME": "${localEnv:USER}", 9 | "DOCKER_REPO": "osrf/ros", 10 | "ROS_DISTRO": "noetic", 11 | "IMAGE_SUFFIX": "-desktop-full" 12 | } 13 | }, 14 | "workspaceFolder": "/home/ws", 15 | "workspaceMount": "source=${localWorkspaceFolder},target=/home/ws,type=bind", 16 | "customizations": { 17 | "vscode": { 18 | "extensions":[ 19 | "ms-vscode.cpptools", 20 | "ms-vscode.cpptools-themes", 21 | "twxs.cmake", 22 | "donjayamanne.python-extension-pack", 23 | "eamodio.gitlens", 24 | "ms-iot.vscode-ros" 25 | ] 26 | } 27 | }, 28 | "containerEnv": { 29 | "DISPLAY": "unix:0", 30 | "ROS_LOCALHOST_ONLY": "1", 31 | "ROS_DOMAIN_ID": "42" 32 | }, 33 | "runArgs": [ 34 | "--net=host", 35 | "-e", "DISPLAY=${env:DISPLAY}", 36 | "--gpus", "all" 37 | ], 38 | "mounts": [ 39 | "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached", 40 | "source=/dev/dri,target=/dev/dri,type=bind,consistency=cached", 41 | "source=${localEnv:HOME}/.ssh,target=/home/${localEnv:USER}/.ssh,type=bind" 42 | ], 43 | "initializeCommand": "sh ./.devcontainer/initialize.sh", 44 | "postCreateCommand": "sh ./.devcontainer/postCreate.sh" 45 | } 46 | -------------------------------------------------------------------------------- /ros1/.devcontainer/initialize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -------------------------------------------------------------------------------- /ros1/.devcontainer/postCreate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p src 3 | sudo rosdep update 4 | sudo rosdep install --from-paths /home/ws/src --ignore-src -y 5 | sudo chown -R $(whoami) /home/ws/ 6 | ./initialize_workspace.sh 7 | ./compile_release.sh 8 | ./merge_compile_commands.sh -------------------------------------------------------------------------------- /ros1/.gitignore: -------------------------------------------------------------------------------- 1 | /.catkin_tools/ 2 | /build_debug/ 3 | /devel_debug/ 4 | /logs_debug/ 5 | /build_release/ 6 | /devel_release/ 7 | /logs_release/ 8 | -------------------------------------------------------------------------------- /ros1/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "browse": { 5 | "databaseFilename": "${default}", 6 | "limitSymbolsToIncludedHeaders": false 7 | }, 8 | "includePath": [ 9 | "/opt/ros/noetic/include/**", 10 | "/usr/include/**" 11 | ], 12 | "name": "ROS", 13 | "intelliSenseMode": "gcc-x64", 14 | "compilerPath": "/usr/bin/gcc", 15 | "cStandard": "gnu11", 16 | "cppStandard": "c++14", 17 | "compileCommands": "${workspaceFolder}/build_release/compile_commands.json" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /ros1/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "ROS: Attach", 9 | "request": "attach", 10 | "type": "ros" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /ros1/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.autoComplete.extraPaths": [ 3 | "/opt/ros/noetic/lib/python3/dist-packages" 4 | ], 5 | "python.analysis.extraPaths": [ 6 | "/opt/ros/noetic/lib/python3/dist-packages" 7 | ] 8 | } -------------------------------------------------------------------------------- /ros1/compile_debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | catkin profile set debug 3 | catkin build 4 | ./merge_compile_commands.sh -------------------------------------------------------------------------------- /ros1/compile_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | catkin profile set release 3 | catkin build 4 | ./merge_compile_commands.sh -------------------------------------------------------------------------------- /ros1/initialize_workspace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | catkin config --profile release -x _release --extend /opt/ros/noetic --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 3 | catkin config --profile debug -x _debug --extend /opt/ros/noetic --cmake-args -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 4 | catkin profile set release -------------------------------------------------------------------------------- /ros1/merge_compile_commands.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -d build_release ]; then 3 | jq -s 'map(.[])' build_release/**/compile_commands.json > build_release/compile_commands.json 4 | fi 5 | if [ -d build_debug ]; then 6 | jq -s 'map(.[])' build_debug/**/compile_commands.json > build_debug/compile_commands.json 7 | fi -------------------------------------------------------------------------------- /ros2/.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG DOCKER_REPO 2 | ARG ROS_DISTRO 3 | ARG IMAGE_SUFFIX 4 | FROM $DOCKER_REPO:$ROS_DISTRO$IMAGE_SUFFIX 5 | ARG USERNAME 6 | ARG USER_UID=1000 7 | ARG USER_GID=$USER_UID 8 | 9 | # Create the user 10 | RUN groupadd --gid $USER_GID $USERNAME \ 11 | && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ 12 | && apt-get update \ 13 | && apt-get install -y sudo \ 14 | && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ 15 | && chmod 0440 /etc/sudoers.d/$USERNAME 16 | # Install additonal packages - add any that you need 17 | RUN apt-get update && apt-get upgrade -y && \ 18 | apt-get install -y python3-pip python-is-python3 ssh neovim git 19 | ENV SHELL /bin/bash 20 | 21 | # Source ROS environment automatically 22 | RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /home/$USERNAME/.bashrc 23 | RUN echo "source /home/ws/install/setup.bash" >> /home/$USERNAME/.bashrc 24 | 25 | # Set the default user 26 | USER $USERNAME 27 | CMD ["/bin/bash"] 28 | -------------------------------------------------------------------------------- /ros2/.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ROS Development Container", 3 | "privileged": true, 4 | "remoteUser": "${localEnv:USER}", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | "args": { 8 | "USERNAME": "${localEnv:USER}", 9 | "DOCKER_REPO": "osrf/ros", 10 | "ROS_DISTRO": "humble", 11 | "IMAGE_SUFFIX": "-desktop-full" 12 | } 13 | }, 14 | "workspaceFolder": "/home/ws", 15 | "workspaceMount": "source=${localWorkspaceFolder},target=/home/ws,type=bind", 16 | "customizations": { 17 | "vscode": { 18 | "extensions":[ 19 | "ms-vscode.cpptools", 20 | "ms-vscode.cpptools-themes", 21 | "twxs.cmake", 22 | "donjayamanne.python-extension-pack", 23 | "eamodio.gitlens", 24 | "ms-iot.vscode-ros" 25 | ] 26 | } 27 | }, 28 | "containerEnv": { 29 | "DISPLAY": "unix:0", 30 | "ROS_LOCALHOST_ONLY": "1", 31 | "ROS_DOMAIN_ID": "42" 32 | }, 33 | "runArgs": [ 34 | "--net=host", 35 | "-e", "DISPLAY=${env:DISPLAY}", 36 | "--gpus", "all" 37 | ], 38 | "mounts": [ 39 | "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached", 40 | "source=/dev/dri,target=/dev/dri,type=bind,consistency=cached", 41 | "source=${localEnv:HOME}/.ssh,target=/home/${localEnv:USER}/.ssh,type=bind" 42 | ], 43 | "initializeCommand": "sh ./.devcontainer/initialize.sh", 44 | "postCreateCommand": "sh ./.devcontainer/postCreate.sh" 45 | } 46 | -------------------------------------------------------------------------------- /ros2/.devcontainer/initialize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -------------------------------------------------------------------------------- /ros2/.devcontainer/postCreate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p src 3 | sudo rosdep update 4 | sudo rosdep install --from-paths /home/ws/src --ignore-src -y 5 | sudo chown -R $(whoami) /home/ws/ 6 | colcon build --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -------------------------------------------------------------------------------- /ros2/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /install/ 3 | /log/ 4 | -------------------------------------------------------------------------------- /ros2/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "browse": { 5 | "databaseFilename": "${default}", 6 | "limitSymbolsToIncludedHeaders": false 7 | }, 8 | "includePath": [ 9 | "/opt/ros/humble/include/**", 10 | "/usr/include/**" 11 | ], 12 | "name": "ROS", 13 | "intelliSenseMode": "gcc-x64", 14 | "compilerPath": "/usr/bin/gcc", 15 | "cStandard": "gnu11", 16 | "cppStandard": "c++17", 17 | "compileCommands": "${workspaceFolder}/build/compile_commands.json" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /ros2/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.autoComplete.extraPaths": [ 3 | "/opt/ros/humble/lib/python3.10/site-packages", 4 | "/opt/ros/humble/local/lib/python3.10/dist-packages" 5 | ], 6 | "python.analysis.extraPaths": [ 7 | "/opt/ros/humble/lib/python3.10/site-packages", 8 | "/opt/ros/humble/local/lib/python3.10/dist-packages" 9 | ] 10 | } -------------------------------------------------------------------------------- /ros2/compile_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | colcon build --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON --------------------------------------------------------------------------------