From 6f8835d5ea46367e73bfcf6aae3af15fabacb8e9 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Tue, 20 Aug 2024 02:47:05 +0800 Subject: [PATCH] feat(aloha_ws): Create aloha_ws Using the `create_workspace.sh` script, and remove `minimal_pkg` --- aloha_ws/.devcontainer/devcontainer.json | 25 ++++++++++ aloha_ws/.devcontainer/postCreateCommand.sh | 6 +++ aloha_ws/.gitignore | 12 +++++ aloha_ws/README.md | 1 + aloha_ws/docker/.bashrc | 5 ++ aloha_ws/docker/.dockerignore | 2 + aloha_ws/docker/Dockerfile | 52 ++++++++++++++++++++ aloha_ws/docker/cache/.gazebo/.gitkeep | 0 aloha_ws/docker/compose.yaml | 53 +++++++++++++++++++++ 9 files changed, 156 insertions(+) create mode 100644 aloha_ws/.devcontainer/devcontainer.json create mode 100755 aloha_ws/.devcontainer/postCreateCommand.sh create mode 100644 aloha_ws/.gitignore create mode 100644 aloha_ws/README.md create mode 100644 aloha_ws/docker/.bashrc create mode 100644 aloha_ws/docker/.dockerignore create mode 100644 aloha_ws/docker/Dockerfile create mode 100644 aloha_ws/docker/cache/.gazebo/.gitkeep create mode 100644 aloha_ws/docker/compose.yaml diff --git a/aloha_ws/.devcontainer/devcontainer.json b/aloha_ws/.devcontainer/devcontainer.json new file mode 100644 index 00000000..be9fb16a --- /dev/null +++ b/aloha_ws/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +/* Reference: https://aka.ms/devcontainer.json */ +{ + "name": "aloha-ws", + "dockerComposeFile": "../docker/compose.yaml", + "service": "aloha-ws", + // workspace settings + "workspaceFolder": "/home/ros2-agv-essentials/aloha_ws", + // Vscode extensions + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cpptools-themes", + "twxs.cmake", + "donjayamanne.python-extension-pack", + "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", + "ms-iot.vscode-ros" + ] + } + }, + // Lifecycle scripts + "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" +} \ No newline at end of file diff --git a/aloha_ws/.devcontainer/postCreateCommand.sh b/aloha_ws/.devcontainer/postCreateCommand.sh new file mode 100755 index 00000000..a8dcfdf1 --- /dev/null +++ b/aloha_ws/.devcontainer/postCreateCommand.sh @@ -0,0 +1,6 @@ +sudo apt-get update +sudo rosdep update +# Note: The following commands are commented out to prevent unintended install/builds. +# sudo rosdep install --from-paths src --ignore-src -y +# sudo chown -R user /home/ros2-agv-essentials/ +# colcon build diff --git a/aloha_ws/.gitignore b/aloha_ws/.gitignore new file mode 100644 index 00000000..6bf2ffcd --- /dev/null +++ b/aloha_ws/.gitignore @@ -0,0 +1,12 @@ +.vscode + +# ROS2 basic directories +/build +/install +/log + +# Gazebo cache +docker/cache/* +!docker/cache/.gazebo +docker/cache/.gazebo/* +!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/aloha_ws/README.md b/aloha_ws/README.md new file mode 100644 index 00000000..95c172aa --- /dev/null +++ b/aloha_ws/README.md @@ -0,0 +1 @@ +# aloha_ws diff --git a/aloha_ws/docker/.bashrc b/aloha_ws/docker/.bashrc new file mode 100644 index 00000000..7c9df020 --- /dev/null +++ b/aloha_ws/docker/.bashrc @@ -0,0 +1,5 @@ +# Source global ROS2 environment +source /opt/ros/$ROS_DISTRO/setup.bash +# Source workspace environment +# Note: If you have not built your workspace yet, the following command will fail +source $ROS2_WS/install/setup.bash diff --git a/aloha_ws/docker/.dockerignore b/aloha_ws/docker/.dockerignore new file mode 100644 index 00000000..4901728d --- /dev/null +++ b/aloha_ws/docker/.dockerignore @@ -0,0 +1,2 @@ +* +!.bashrc diff --git a/aloha_ws/docker/Dockerfile b/aloha_ws/docker/Dockerfile new file mode 100644 index 00000000..a2f106fb --- /dev/null +++ b/aloha_ws/docker/Dockerfile @@ -0,0 +1,52 @@ +# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble +FROM osrf/ros:humble-desktop-full + +LABEL org.opencontainers.image.authors="yuzhong1214@gmail.com" + +ARG USERNAME=user +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Create the user +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # + # [Optional] Add sudo support. Omit if you don't need to install software after connecting. + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y python3-pip \ + && rm -rf /var/lib/apt/lists/* +ENV SHELL /bin/bash + +# ******************************************************** +# * Anything else you want to do like clean up goes here * +# ******************************************************** + +# Install common tools +RUN apt-get update && apt-get install -y \ + curl \ + git \ + git-extras \ + htop \ + net-tools \ + tmux \ + vim \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# Install ROS2 RVIZ and Gazebo +RUN apt-get update && apt-get install -y \ + ros-$ROS_DISTRO-gazebo-ros-pkgs \ + ros-$ROS_DISTRO-rviz2 \ + && rm -rf /var/lib/apt/lists/* + +COPY .bashrc /home/$USERNAME/.bashrc + +# [Optional] Set the default user. Omit if you want to keep the default as root. +USER $USERNAME +CMD ["/bin/bash"] diff --git a/aloha_ws/docker/cache/.gazebo/.gitkeep b/aloha_ws/docker/cache/.gazebo/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/aloha_ws/docker/compose.yaml b/aloha_ws/docker/compose.yaml new file mode 100644 index 00000000..e2bb1815 --- /dev/null +++ b/aloha_ws/docker/compose.yaml @@ -0,0 +1,53 @@ +services: + aloha-ws: + build: . + image: j3soon/ros2-aloha-ws + container_name: ros2-aloha-ws + stdin_open: true + tty: true + privileged: true + command: /bin/bash + network_mode: host + working_dir: /home/ros2-agv-essentials/aloha_ws + environment: + - DISPLAY=${DISPLAY} + # 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 + # - https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#console-output-colorizing + - ROS_LOCALHOST_ONLY=1 + - ROS_DOMAIN_ID=42 + - ROS2_WS=/home/ros2-agv-essentials/aloha_ws + - RCUTILS_COLORIZED_OUTPUT=1 + # If you want to access GPU, please uncomment the lines below. + # Reference : https://docs.docker.com/compose/gpu-support/ + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [ gpu ] + volumes: + # Mount local timezone into container. ( Readonly ) + # Reference: https://stackoverflow.com/questions/57607381/how-do-i-change-timezone-in-a-docker-container + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + # Mount X11 server + - /tmp/.X11-unix:/tmp/.X11-unix + - $HOME/.Xauthority:/home/user/.Xauthority + # Direct Rendering Infrastructure + - /dev/dri:/dev/dri + # Mount sound card to prevent Gazebo warning. + - /dev/snd:/dev/snd + # Mount Gazebo models directory to reuse models downloaded during first launch. + # Reference: https://answers.ros.org/question/365658 + - ./cache/.gazebo:/home/user/.gazebo + # Mounting the following directories will forbid direct deletion. + # Consider mount these directories only if the build process is slow. + # "source=${localWorkspaceFolder}/../cache/humble/build,target=/home/ws/build,type=bind", + # "source=${localWorkspaceFolder}/../cache/humble/install,target=/home/ws/install,type=bind", + # "source=${localWorkspaceFolder}/../cache/humble/log,target=/home/ws/log,type=bind" + # Mount workspace + - ../..:/home/ros2-agv-essentials