-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from j3soon/refactor/template-ws
Refactor `template_ws`
- Loading branch information
Showing
9 changed files
with
157 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
# Source global ROS2 environment | ||
source /opt/ros/$ROS_DISTRO/setup.bash | ||
# Optionally perform apt update if it has not been executed yet | ||
if [ -z "$( ls -A '/var/lib/apt/lists' )" ]; then | ||
echo "apt-get update has not been executed yet. Running sudo apt-get update..." | ||
sudo apt-get update | ||
fi | ||
# Optionally perform rosdep update if it has not been executed yet | ||
if [ ! -d $HOME/.ros/rosdep/sources.cache ]; then | ||
echo "rosdep update has not been executed yet. Running rosdep update..." | ||
rosdep update | ||
fi | ||
# Optionally build the workspace if it has not been built yet | ||
if [ ! -f $ROS2_WS/install/setup.bash ]; then | ||
echo "Workspace has not been built yet. Building workspace..." | ||
cd $ROS2_WS | ||
# Ref: https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html | ||
rosdep install --from-paths src --ignore-src -y -r | ||
# TODO: If command `arch` outputs `aarch64`, consider adding `--packages-ignore <package>` 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 | ||
# Source workspace environment | ||
# Note: If you have not built your workspace yet, the following command will fail | ||
source $ROS2_WS/install/setup.bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,92 @@ | ||
# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble | ||
FROM osrf/ros:humble-desktop-full | ||
FROM osrf/ros:humble-desktop-full AS amd64 | ||
# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble | ||
FROM arm64v8/ros:humble AS arm64 | ||
|
||
LABEL org.opencontainers.image.authors="[email protected]" | ||
# Use docker automatic platform args to select the base image. | ||
# It may be `arm64` or `amd64` depending on the platform. | ||
# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope | ||
FROM $TARGETARCH | ||
|
||
# Arguments for the default user | ||
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 \ | ||
|
||
# Keep downloaded packages for caching purposes | ||
# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages | ||
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache | ||
|
||
# Upgrade packages | ||
# Ref: https://pythonspeed.com/articles/security-updates-in-docker/ | ||
# Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages | ||
# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398 | ||
# Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404 | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
apt-get update && apt-get upgrade -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ENV SHELL /bin/bash | ||
|
||
# ******************************************************** | ||
# * Anything else you want to do like clean up goes here * | ||
# ******************************************************** | ||
# Install sudo and create a user with sudo privileges | ||
# Ref: https://stackoverflow.com/a/65434659 | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
apt-get update && apt-get install -y sudo \ | ||
&& useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \ | ||
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install common tools | ||
RUN apt-get update && apt-get install -y \ | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
apt-get update && apt-get install -y \ | ||
curl \ | ||
git \ | ||
git-extras \ | ||
htop \ | ||
iputils-ping \ | ||
nano \ | ||
net-tools \ | ||
tmux \ | ||
tree \ | ||
unzip \ | ||
vim \ | ||
wget \ | ||
zip \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Python pip | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
apt-get update && apt-get install -y \ | ||
python3-pip \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install custom tools | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
apt-get update && apt-get install -y \ | ||
git-extras \ | ||
&& 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 \ | ||
# Install ROS2 Gazebo packages for amd64 | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
if [ "$TARGETARCH" = "amd64" ]; then \ | ||
apt-get update && apt-get install -y \ | ||
ros-$ROS_DISTRO-gazebo-ros-pkgs \ | ||
ros-$ROS_DISTRO-gazebo-ros2-control \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
|
||
# Install ROS2 RVIZ and other custom ROS2 packages | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
apt-get update && apt-get install -y \ | ||
ros-$ROS_DISTRO-rviz2 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY .bashrc /home/$USERNAME/.bashrc | ||
# TODO: Add more commands here | ||
# For example, to install additional packages, uncomment the following lines and add the package names | ||
# RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ | ||
# apt-get update && apt-get install -y \ | ||
# $OTHER_PACKAGES \ | ||
# && rm -rf /var/lib/apt/lists/* | ||
|
||
# [Optional] Set the default user. Omit if you want to keep the default as root. | ||
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 | ||
ENTRYPOINT [] | ||
CMD ["/bin/bash"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,66 @@ | ||
services: | ||
template-ws: | ||
build: . | ||
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-template-ws | ||
container_name: ros2-template-ws | ||
stdin_open: true | ||
tty: true | ||
# TODO: Comment the line below if the workspace don't need to communicate through `/dev/*` devices. | ||
privileged: true | ||
command: /bin/bash | ||
network_mode: host | ||
working_dir: /home/ros2-agv-essentials/template_ws | ||
working_dir: /home/ros2-essentials/template_ws | ||
environment: | ||
- DISPLAY=${DISPLAY} | ||
# Set ros2 environment variables. | ||
# 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 | ||
# - 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/template_ws | ||
- ROS_LOCALHOST_ONLY=0 | ||
# Localhost only is disabled by default to allow communication with external devices. | ||
- ROS_DOMAIN_ID=0 | ||
# Domain ID is set to 0 to allow communication through ros1_bridge. | ||
- 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 ] | ||
- ROS2_WS=/home/ros2-essentials/template_ws | ||
# TODO: Uncomment the lines below to enable GPU support. | ||
# deploy: | ||
# # Reference : https://docs.docker.com/compose/gpu-support/ | ||
# resources: | ||
# reservations: | ||
# devices: | ||
# - driver: nvidia | ||
# count: all | ||
# capabilities: [ gpu ] | ||
volumes: | ||
# Mount local timezone into container. ( Readonly ) | ||
# Mount local timezone into container. | ||
# 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 | ||
# X11-unix is mounted to allow GUI applications to display on host. | ||
- $HOME/.Xauthority:/home/user/.Xauthority | ||
# Direct Rendering Infrastructure | ||
# Xauthority is mounted to allow X11 forwarding for remote display. | ||
# Mount Direct Rendering Infrastructure (DRI) for hardware acceleration support such as OpenGL. | ||
- /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. | ||
# - /dev:/dev | ||
# 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 | ||
# Note that this volume is shared among all workspaces. | ||
- gazebo-cache:/home/user/.gazebo | ||
# Mount root workspace to allow easy access to all workspaces. | ||
- ../..:/home/ros2-essentials | ||
volumes: | ||
gazebo-cache: | ||
name: ros2-gazebo-cache |