From 1fa7380535ce017da4c0a5b1cf36ec238cd5dcc0 Mon Sep 17 00:00:00 2001 From: Tobit Flatscher <53856473+2b-t@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:07:59 +0000 Subject: [PATCH] refactor: Restructure VS Code integration removing VS Code layer and adding dedicated VS Code Docker Compose file --- templates/ros/.devcontainer/devcontainer.json | 2 +- templates/ros/.vscode/ros_source.bash | 33 ------------------- templates/ros/.vscode/tasks.json | 18 ++++++---- templates/ros/docker/Dockerfile | 23 ++++++------- .../ros/docker/docker-compose-gui-nvidia.yml | 1 + templates/ros/docker/docker-compose-gui.yml | 1 + .../ros/docker/docker-compose-nvidia.yml | 1 + .../ros/docker/docker-compose-vscode.yml | 9 +++++ templates/ros/docker/docker-compose.yml | 2 +- .../ros2/.devcontainer/devcontainer.json | 2 +- templates/ros2/.vscode/ros2_source.bash | 33 ------------------- templates/ros2/.vscode/tasks.json | 15 ++++++--- templates/ros2/docker/Dockerfile | 21 +++++------- .../ros2/docker/docker-compose-gui-nvidia.yml | 1 + templates/ros2/docker/docker-compose-gui.yml | 1 + .../ros2/docker/docker-compose-nvidia.yml | 1 + .../ros2/docker/docker-compose-vscode.yml | 9 +++++ templates/ros2/docker/docker-compose.yml | 2 +- 18 files changed, 69 insertions(+), 106 deletions(-) delete mode 100755 templates/ros/.vscode/ros_source.bash create mode 100644 templates/ros/docker/docker-compose-vscode.yml delete mode 100755 templates/ros2/.vscode/ros2_source.bash create mode 100644 templates/ros2/docker/docker-compose-vscode.yml diff --git a/templates/ros/.devcontainer/devcontainer.json b/templates/ros/.devcontainer/devcontainer.json index 17eec00..69a6d6c 100644 --- a/templates/ros/.devcontainer/devcontainer.json +++ b/templates/ros/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ { "name": "ROS Docker", "dockerComposeFile": [ - "../docker/docker-compose-gui.yml" // Alternatives: "../docker/docker-compose-gui.yml", "../docker/docker-compose-gui-nvidia.yml", "../docker/docker-compose-nvidia.yml" + "../docker/docker-compose-vscode.yml" ], "service": "ros_docker", "workspaceFolder": "/catkin_ws", diff --git a/templates/ros/.vscode/ros_source.bash b/templates/ros/.vscode/ros_source.bash deleted file mode 100755 index 6204e48..0000000 --- a/templates/ros/.vscode/ros_source.bash +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# Bash script for sourcing either the current workspace environment or the default ROS one located in '/opt/ros/${ROS_DISTRO}' -# Author: Tobit Flatscher - github.com/2b-t (2021) -# -# Usage: - $ ./ros_source.sh -# Defaults to "noetic" -# - $ ./ros_source.sh -# ros_distro: Optional ROS distribution e.g. "melodic" - - -function main { - local ROS_DISTRO=${1:-"noetic"} - local CURRENT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd) - local WORKSPACE_SOURCE_FILE="${CURRENT_PATH}/../devel/setup.bash" - local DISTRO_SOURCE_FILE="/opt/ros/${ROS_DISTRO}/setup.bash" - - # Check if file local 'setup.bash' exists - if [ -f "${WORKSPACE_SOURCE_FILE}" ] - then - source ${WORKSPACE_SOURCE_FILE} - echo "Successfully sourced '${WORKSPACE_SOURCE_FILE}'." - # Else check if distro 'setup.bash' exists - elif [ -f "${DISTRO_SOURCE_FILE}" ] - then - source ${DISTRO_SOURCE_FILE} - echo "Successfully sourced '${DISTRO_SOURCE_FILE}'." - else - echo "Error: Could not find 'setup.bash' file to source in '${WORKSPACE_SOURCE_FILE}' and '${DISTRO_SOURCE_FILE}'!" - fi -} - -main $@ - diff --git a/templates/ros/.vscode/tasks.json b/templates/ros/.vscode/tasks.json index 9f1ed0b..efbf045 100644 --- a/templates/ros/.vscode/tasks.json +++ b/templates/ros/.vscode/tasks.json @@ -12,7 +12,8 @@ "command": "vcs import < .repos", "options": { "cwd": "${workspaceFolder}/src" - } + }, + "problemMatcher": [] }, // Install ROS dependencies { @@ -22,7 +23,8 @@ "command": "sudo apt-get update && rosdep update && rosdep install --from-paths src --ignore-src -y", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] }, // Build tasks { @@ -62,7 +64,8 @@ "group": { "kind": "test", "isDefault": true - } + }, + "problemMatcher": [] }, // Clean { @@ -72,7 +75,8 @@ "command": "catkin clean --yes", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] }, { "label": "purge", @@ -81,7 +85,8 @@ "command": "rm -fr .catkin_tools build install log && py3clean .", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] }, // Start ROS Master node { @@ -91,7 +96,8 @@ "command": "roscore", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] }, ], "inputs": [ diff --git a/templates/ros/docker/Dockerfile b/templates/ros/docker/Dockerfile index 8894967..e820c16 100644 --- a/templates/ros/docker/Dockerfile +++ b/templates/ros/docker/Dockerfile @@ -39,9 +39,13 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y \ + ack \ + htop \ iperf3 \ iputils-ping \ + mlocate \ net-tools \ + psmisc \ python3-vcstool \ && rm -rf /var/lib/apt/lists/* @@ -52,8 +56,6 @@ RUN apt-get update \ # Install additional developer tools here... -ENV DEBIAN_FRONTEND=dialog - RUN apt-get update \ && apt-get install -y sudo \ && rm -rf /var/lib/apt/lists/* \ @@ -62,18 +64,13 @@ RUN apt-get update \ && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ && chown -R ${UID}:${GID} /home/${USERNAME} \ && chown -R ${UID}:${GID} ${CATKIN_WORKSPACE_DIR} + +ENV DEBIAN_FRONTEND=dialog -USER ${USERNAME} - - -############################ -# Visual Studio Code image # -############################ -FROM dev as vsc - -COPY ".vscode" "${CATKIN_WORKSPACE_DIR}/.vscode" -RUN echo "alias rsource='source ${CATKIN_WORKSPACE_DIR}/.vscode/ros_source.bash ${ROS_DISTRO}'" >> /home/${USERNAME}/.bash_aliases \ +RUN echo "alias rsource='source ${CATKIN_WORKSPACE_DIR}/devel/setup.bash'" >> /home/${USERNAME}/.bash_aliases \ && echo "alias rbuild='(cd ${CATKIN_WORKSPACE_DIR} && catkin build)'" >> /home/${USERNAME}/.bash_aliases \ && echo "alias rclean='(cd ${CATKIN_WORKSPACE_DIR} && catkin clean -y)'" >> /home/${USERNAME}/.bash_aliases \ - && echo "rsource" >> /home/${USERNAME}/.bashrc + && echo "rsource || source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USERNAME}/.bashrc + +USER ${USERNAME} diff --git a/templates/ros/docker/docker-compose-gui-nvidia.yml b/templates/ros/docker/docker-compose-gui-nvidia.yml index 0a77c55..9ed57b9 100644 --- a/templates/ros/docker/docker-compose-gui-nvidia.yml +++ b/templates/ros/docker/docker-compose-gui-nvidia.yml @@ -8,3 +8,4 @@ services: - NVIDIA_VISIBLE_DEVICES=all - NVIDIA_DRIVER_CAPABILITIES=all runtime: nvidia + diff --git a/templates/ros/docker/docker-compose-gui.yml b/templates/ros/docker/docker-compose-gui.yml index e6032e5..f859054 100644 --- a/templates/ros/docker/docker-compose-gui.yml +++ b/templates/ros/docker/docker-compose-gui.yml @@ -10,3 +10,4 @@ services: volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw - /tmp/.docker.xauth:/tmp/.docker.xauth:rw + diff --git a/templates/ros/docker/docker-compose-nvidia.yml b/templates/ros/docker/docker-compose-nvidia.yml index e228d1e..7271d6b 100644 --- a/templates/ros/docker/docker-compose-nvidia.yml +++ b/templates/ros/docker/docker-compose-nvidia.yml @@ -7,3 +7,4 @@ services: environment: - NVIDIA_VISIBLE_DEVICES=all runtime: nvidia + diff --git a/templates/ros/docker/docker-compose-vscode.yml b/templates/ros/docker/docker-compose-vscode.yml new file mode 100644 index 0000000..5e972bd --- /dev/null +++ b/templates/ros/docker/docker-compose-vscode.yml @@ -0,0 +1,9 @@ +version: "3.9" +services: + ros_docker: + extends: + file: docker-compose-gui.yml + service: ros_docker + volumes: + - ../.vscode:${CATKIN_WORKSPACE_DIR}/.vscode + diff --git a/templates/ros/docker/docker-compose.yml b/templates/ros/docker/docker-compose.yml index 3c66e61..12b0442 100644 --- a/templates/ros/docker/docker-compose.yml +++ b/templates/ros/docker/docker-compose.yml @@ -4,7 +4,7 @@ services: build: context: .. dockerfile: docker/Dockerfile - target: vsc + target: dev args: - CATKIN_WORKSPACE_DIR=${CATKIN_WORKSPACE_DIR} - USERNAME=${USERNAME:-developer} diff --git a/templates/ros2/.devcontainer/devcontainer.json b/templates/ros2/.devcontainer/devcontainer.json index 62c2d62..85437d6 100644 --- a/templates/ros2/.devcontainer/devcontainer.json +++ b/templates/ros2/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ { "name": "ROS2 Docker", "dockerComposeFile": [ - "../docker/docker-compose-gui.yml" // Alternatives: "../docker/docker-compose-gui.yml", "../docker/docker-compose-gui-nvidia.yml" + "../docker/docker-compose-vscode.yml" ], "service": "ros2_docker", "workspaceFolder": "/ament_ws", diff --git a/templates/ros2/.vscode/ros2_source.bash b/templates/ros2/.vscode/ros2_source.bash deleted file mode 100755 index c762585..0000000 --- a/templates/ros2/.vscode/ros2_source.bash +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# Bash script for sourcing either the current workspace environment or the default ROS2 one located in /opt/ros/${ROS_DISTRO} -# Author: Tobit Flatscher - github.com/2b-t (2021) -# -# Usage: - $ ./ros2_source.sh -# Defaults to "humble" -# - $ ./ros2_source.sh -# ros2_distro: Optional ROS distribution e.g. "humble" - - -function main { - local ROS_DISTRO=${1:-"humble"} - local CURRENT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd) - local WORKSPACE_SOURCE_FILE="${CURRENT_PATH}/../install/setup.bash" - local DISTRO_SOURCE_FILE="/opt/ros/${ROS_DISTRO}/setup.bash" - - # Check if file local 'setup.bash' exists - if [ -f "${WORKSPACE_SOURCE_FILE}" ] - then - source ${WORKSPACE_SOURCE_FILE} - echo "Successfully sourced '${WORKSPACE_SOURCE_FILE}'." - # Else check if distro 'setup.bash' exists - elif [ -f "${DISTRO_SOURCE_FILE}" ] - then - source ${DISTRO_SOURCE_FILE} - echo "Successfully sourced '${DISTRO_SOURCE_FILE}'." - else - echo "Error: Could not find 'setup.bash' file to source in '${WORKSPACE_SOURCE_FILE}' and '${DISTRO_SOURCE_FILE}'!" - fi -} - -main $@ - diff --git a/templates/ros2/.vscode/tasks.json b/templates/ros2/.vscode/tasks.json index c209b2d..9062d42 100644 --- a/templates/ros2/.vscode/tasks.json +++ b/templates/ros2/.vscode/tasks.json @@ -12,7 +12,8 @@ "command": "vcs import < .repos", "options": { "cwd": "${workspaceFolder}/src" - } + }, + "problemMatcher": [] }, // Install ROS dependencies { @@ -22,7 +23,8 @@ "command": "sudo apt-get update -y && rosdep update && rosdep install --from-paths src --ignore-src -y", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] }, // Build tasks { @@ -62,7 +64,8 @@ "group": { "kind": "test", "isDefault": true - } + }, + "problemMatcher": [] }, // Clean tasks { @@ -72,7 +75,8 @@ "command": "colcon clean workspace --yes", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] }, { "label": "purge", @@ -81,7 +85,8 @@ "command": "rm -fr build install log && py3clean .", "options": { "cwd": "${workspaceFolder}" - } + }, + "problemMatcher": [] } ], "inputs": [ diff --git a/templates/ros2/docker/Dockerfile b/templates/ros2/docker/Dockerfile index de0e109..8cf4ef7 100644 --- a/templates/ros2/docker/Dockerfile +++ b/templates/ros2/docker/Dockerfile @@ -44,9 +44,13 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y \ + ack \ + htop \ iperf3 \ iputils-ping \ + mlocate \ net-tools \ + psmisc \ python3-vcstool \ && rm -rf /var/lib/apt/lists/* @@ -57,8 +61,6 @@ RUN apt-get update \ # Install additional developer tools here... -ENV DEBIAN_FRONTEND=dialog - RUN apt-get update \ && apt-get install -y sudo \ && rm -rf /var/lib/apt/lists/* \ @@ -68,17 +70,12 @@ RUN apt-get update \ && chown -R ${UID}:${GID} /home/${USERNAME} \ && chown -R ${UID}:${GID} ${AMENT_WORKSPACE_DIR} -USER ${USERNAME} - - -############################ -# Visual Studio Code image # -############################ -FROM dev as vsc +ENV DEBIAN_FRONTEND=dialog -COPY ".vscode" "${AMENT_WORKSPACE_DIR}/.vscode" -RUN echo "alias rsource='source ${AMENT_WORKSPACE_DIR}/.vscode/ros2_source.bash ${ROS_DISTRO}'" >> /home/${USERNAME}/.bash_aliases \ +RUN echo "alias rsource='source ${AMENT_WORKSPACE_DIR}/install/setup.bash'" >> /home/${USERNAME}/.bash_aliases \ && echo "alias rbuild='(cd ${AMENT_WORKSPACE_DIR} && colcon build)'" >> /home/${USERNAME}/.bash_aliases \ && echo "alias rclean='(cd ${AMENT_WORKSPACE_DIR} && colcon clean workspace -y)'" >> /home/${USERNAME}/.bash_aliases \ - && echo "rsource" >> /home/${USERNAME}/.bashrc + && echo "rsource || source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USERNAME}/.bashrc + +USER ${USERNAME} diff --git a/templates/ros2/docker/docker-compose-gui-nvidia.yml b/templates/ros2/docker/docker-compose-gui-nvidia.yml index 6d7d18b..f5c4467 100644 --- a/templates/ros2/docker/docker-compose-gui-nvidia.yml +++ b/templates/ros2/docker/docker-compose-gui-nvidia.yml @@ -8,3 +8,4 @@ services: - NVIDIA_VISIBLE_DEVICES=all - NVIDIA_DRIVER_CAPABILITIES=all runtime: nvidia + diff --git a/templates/ros2/docker/docker-compose-gui.yml b/templates/ros2/docker/docker-compose-gui.yml index 08f1bf0..09c2e88 100644 --- a/templates/ros2/docker/docker-compose-gui.yml +++ b/templates/ros2/docker/docker-compose-gui.yml @@ -10,3 +10,4 @@ services: volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw - /tmp/.docker.xauth:/tmp/.docker.xauth:rw + diff --git a/templates/ros2/docker/docker-compose-nvidia.yml b/templates/ros2/docker/docker-compose-nvidia.yml index d20c32e..3eded6a 100644 --- a/templates/ros2/docker/docker-compose-nvidia.yml +++ b/templates/ros2/docker/docker-compose-nvidia.yml @@ -7,3 +7,4 @@ services: environment: - NVIDIA_VISIBLE_DEVICES=all runtime: nvidia + diff --git a/templates/ros2/docker/docker-compose-vscode.yml b/templates/ros2/docker/docker-compose-vscode.yml new file mode 100644 index 0000000..ffb3072 --- /dev/null +++ b/templates/ros2/docker/docker-compose-vscode.yml @@ -0,0 +1,9 @@ +version: "3.9" +services: + ros2_docker: + extends: + file: docker-compose-gui.yml + service: ros2_docker + volumes: + - ../.vscode:${AMENT_WORKSPACE_DIR}/.vscode + diff --git a/templates/ros2/docker/docker-compose.yml b/templates/ros2/docker/docker-compose.yml index 683c0ce..f07a8be 100644 --- a/templates/ros2/docker/docker-compose.yml +++ b/templates/ros2/docker/docker-compose.yml @@ -4,7 +4,7 @@ services: build: context: .. dockerfile: docker/Dockerfile - target: vsc + target: dev args: - AMENT_WORKSPACE_DIR=${AMENT_WORKSPACE_DIR} - USERNAME=${USERNAME:-developer}