From 4a710c857ba58cd9bc3907d9c7130be197a321a1 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Fri, 23 Aug 2024 03:03:53 +0800 Subject: [PATCH] refactor(gazebo_world_ws): Sync style with latest template --- gazebo_world_ws/.devcontainer/devcontainer.json | 6 +++--- gazebo_world_ws/.gitignore | 3 ++- gazebo_world_ws/docker/.bashrc | 11 +++++++++-- gazebo_world_ws/docker/Dockerfile | 10 ++++++---- gazebo_world_ws/docker/compose.yaml | 16 +++++++++++----- tests/diff_base/docker/.bashrc | 1 + 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/gazebo_world_ws/.devcontainer/devcontainer.json b/gazebo_world_ws/.devcontainer/devcontainer.json index 236308a2..67030b69 100644 --- a/gazebo_world_ws/.devcontainer/devcontainer.json +++ b/gazebo_world_ws/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ "name": "gazebo-world-ws", "dockerComposeFile": "../docker/compose.yaml", "service": "gazebo-world-ws", - // workspace settings + // Workspace settings "workspaceFolder": "/home/ros2-essentials/gazebo_world_ws", // Vscode extensions "customizations": { @@ -19,5 +19,5 @@ "ms-iot.vscode-ros" ] } - }, -} \ No newline at end of file + } +} diff --git a/gazebo_world_ws/.gitignore b/gazebo_world_ws/.gitignore index 171c8a96..2bc3ebb3 100644 --- a/gazebo_world_ws/.gitignore +++ b/gazebo_world_ws/.gitignore @@ -1,6 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install -/log \ No newline at end of file +/log diff --git a/gazebo_world_ws/docker/.bashrc b/gazebo_world_ws/docker/.bashrc index 1e429d1f..8e92c030 100644 --- a/gazebo_world_ws/docker/.bashrc +++ b/gazebo_world_ws/docker/.bashrc @@ -1,7 +1,7 @@ # Check if the architecture is aarch64 if [ $(arch) == "aarch64" ]; then echo "Architecture is aarch64, which is not supported by Gazebo. Exiting..." - exit + exit 1 fi # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash @@ -21,8 +21,15 @@ if [ ! -f $ROS2_WS/install/setup.bash ]; then cd $ROS2_WS # Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html rosdep install --from-paths src --ignore-src -y -r - colcon build --symlink-install + # TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore ` to ignore x86 packages + # Ref: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html + if [ $(arch) == "aarch64" ]; then + colcon build --symlink-install + else + colcon build --symlink-install + fi echo "Workspace built." fi +# TODO: Source other workspace environments as underlay # Source workspace environment source $ROS2_WS/install/setup.bash diff --git a/gazebo_world_ws/docker/Dockerfile b/gazebo_world_ws/docker/Dockerfile index a6fc6039..f7173a6f 100644 --- a/gazebo_world_ws/docker/Dockerfile +++ b/gazebo_world_ws/docker/Dockerfile @@ -1,6 +1,6 @@ -# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble FROM osrf/ros:humble-desktop-full AS amd64 -# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble +# Base Image: https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble FROM arm64v8/ros:humble AS arm64 # Use docker automatic platform args to select the base image. @@ -86,8 +86,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ # && rm -rf /var/lib/apt/lists/* USER $USERNAME -COPY .bashrc /home/$USERNAME/.bashrc # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount RUN mkdir /home/$USERNAME/.gazebo +# TODO: Run additional commands as non-root user here +COPY .bashrc /home/$USERNAME/.bashrc +# TODO: Copy additional files here ENTRYPOINT [] -CMD ["/bin/bash"] \ No newline at end of file +CMD ["/bin/bash"] diff --git a/gazebo_world_ws/docker/compose.yaml b/gazebo_world_ws/docker/compose.yaml index 5f9008aa..06a3b140 100644 --- a/gazebo_world_ws/docker/compose.yaml +++ b/gazebo_world_ws/docker/compose.yaml @@ -1,9 +1,12 @@ -version: '3' services: gazebo-world-ws: build: context: . dockerfile: Dockerfile + # TODO: Specify the target platform to build the image, otherwise it will build for the host platform. + # Reference: https://docs.docker.com/compose/compose-file/build/#platforms + # platforms: + # - "linux/arm64" image: j3soon/ros2-gazebo-world-ws container_name: ros2-gazebo-world-ws stdin_open: true @@ -16,7 +19,6 @@ services: environment: # Set X11 server environment variable for existing display. - DISPLAY=$DISPLAY - # TODO: Set ros2 environment variables. # References: # - https://docs.ros.org/en/humble/Concepts/Intermediate/About-Domain-ID.html # - https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html @@ -27,9 +29,10 @@ services: # Domain ID is set to 0 to allow communication through ros1_bridge. - RCUTILS_COLORIZED_OUTPUT=1 - ROS2_WS=/home/ros2-essentials/gazebo_world_ws + # TODO: Add more environment variables here. # TODO: Uncomment the lines below to enable GPU support. + # # Reference: https://docs.docker.com/compose/gpu-support/ # deploy: - # # Reference : https://docs.docker.com/compose/gpu-support/ # resources: # reservations: # devices: @@ -50,14 +53,17 @@ services: - /dev/dri:/dev/dri # Mount sound card to prevent Gazebo warning. - /dev/snd:/dev/snd - # Uncomment the line below and comment out the two entries above to enable USB support. + # Mount shared memory for ROS2 communication. + - /dev/shm:/dev/shm + # TODO: Uncomment the line below and comment out the three entries above to enable USB support. # - /dev:/dev # Mount Gazebo models directory to reuse models downloaded during first launch. # Reference: https://answers.ros.org/question/365658 # Note that this volume is shared among all workspaces. - gazebo-cache:/home/user/.gazebo + # TODO: Add more volume mounts here. # Mount root workspace to allow easy access to all workspaces. - ../..:/home/ros2-essentials volumes: gazebo-cache: - name: ros2-gazebo-cache \ No newline at end of file + name: ros2-gazebo-cache diff --git a/tests/diff_base/docker/.bashrc b/tests/diff_base/docker/.bashrc index 29f8cd2f..a91c4e83 100644 --- a/tests/diff_base/docker/.bashrc +++ b/tests/diff_base/docker/.bashrc @@ -1,3 +1,4 @@ +{PLACEHOLDER_MULTILINE} # Source global ROS2 environment source /opt/ros/$ROS_DISTRO/setup.bash # Optionally perform apt update if it has not been executed yet