Skip to content

Commit

Permalink
refactor: Restructure VS Code integration removing VS Code layer and …
Browse files Browse the repository at this point in the history
…adding dedicated VS Code Docker Compose file
  • Loading branch information
2b-t committed Feb 17, 2024
1 parent 453d87d commit 1fa7380
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 106 deletions.
2 changes: 1 addition & 1 deletion templates/ros/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 0 additions & 33 deletions templates/ros/.vscode/ros_source.bash

This file was deleted.

18 changes: 12 additions & 6 deletions templates/ros/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"command": "vcs import < .repos",
"options": {
"cwd": "${workspaceFolder}/src"
}
},
"problemMatcher": []
},
// Install ROS dependencies
{
Expand All @@ -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
{
Expand Down Expand Up @@ -62,7 +64,8 @@
"group": {
"kind": "test",
"isDefault": true
}
},
"problemMatcher": []
},
// Clean
{
Expand All @@ -72,7 +75,8 @@
"command": "catkin clean --yes",
"options": {
"cwd": "${workspaceFolder}"
}
},
"problemMatcher": []
},
{
"label": "purge",
Expand All @@ -81,7 +85,8 @@
"command": "rm -fr .catkin_tools build install log && py3clean .",
"options": {
"cwd": "${workspaceFolder}"
}
},
"problemMatcher": []
},
// Start ROS Master node
{
Expand All @@ -91,7 +96,8 @@
"command": "roscore",
"options": {
"cwd": "${workspaceFolder}"
}
},
"problemMatcher": []
},
],
"inputs": [
Expand Down
23 changes: 10 additions & 13 deletions templates/ros/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand All @@ -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/* \
Expand All @@ -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}

1 change: 1 addition & 0 deletions templates/ros/docker/docker-compose-gui-nvidia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ services:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
runtime: nvidia

1 change: 1 addition & 0 deletions templates/ros/docker/docker-compose-gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ services:
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- /tmp/.docker.xauth:/tmp/.docker.xauth:rw

1 change: 1 addition & 0 deletions templates/ros/docker/docker-compose-nvidia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ services:
environment:
- NVIDIA_VISIBLE_DEVICES=all
runtime: nvidia

9 changes: 9 additions & 0 deletions templates/ros/docker/docker-compose-vscode.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion templates/ros/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: ..
dockerfile: docker/Dockerfile
target: vsc
target: dev
args:
- CATKIN_WORKSPACE_DIR=${CATKIN_WORKSPACE_DIR}
- USERNAME=${USERNAME:-developer}
Expand Down
2 changes: 1 addition & 1 deletion templates/ros2/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 0 additions & 33 deletions templates/ros2/.vscode/ros2_source.bash

This file was deleted.

15 changes: 10 additions & 5 deletions templates/ros2/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"command": "vcs import < .repos",
"options": {
"cwd": "${workspaceFolder}/src"
}
},
"problemMatcher": []
},
// Install ROS dependencies
{
Expand All @@ -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
{
Expand Down Expand Up @@ -62,7 +64,8 @@
"group": {
"kind": "test",
"isDefault": true
}
},
"problemMatcher": []
},
// Clean tasks
{
Expand All @@ -72,7 +75,8 @@
"command": "colcon clean workspace --yes",
"options": {
"cwd": "${workspaceFolder}"
}
},
"problemMatcher": []
},
{
"label": "purge",
Expand All @@ -81,7 +85,8 @@
"command": "rm -fr build install log && py3clean .",
"options": {
"cwd": "${workspaceFolder}"
}
},
"problemMatcher": []
}
],
"inputs": [
Expand Down
21 changes: 9 additions & 12 deletions templates/ros2/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand All @@ -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/* \
Expand All @@ -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}

1 change: 1 addition & 0 deletions templates/ros2/docker/docker-compose-gui-nvidia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ services:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
runtime: nvidia

1 change: 1 addition & 0 deletions templates/ros2/docker/docker-compose-gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ services:
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- /tmp/.docker.xauth:/tmp/.docker.xauth:rw

1 change: 1 addition & 0 deletions templates/ros2/docker/docker-compose-nvidia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ services:
environment:
- NVIDIA_VISIBLE_DEVICES=all
runtime: nvidia

9 changes: 9 additions & 0 deletions templates/ros2/docker/docker-compose-vscode.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion templates/ros2/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: ..
dockerfile: docker/Dockerfile
target: vsc
target: dev
args:
- AMENT_WORKSPACE_DIR=${AMENT_WORKSPACE_DIR}
- USERNAME=${USERNAME:-developer}
Expand Down

0 comments on commit 1fa7380

Please sign in to comment.