Skip to content

Commit

Permalink
feat(template_ws): Add multi-platform builds support
Browse files Browse the repository at this point in the history
Co-authored-by: YuZhong-Chen <yuzhong1214@gmail.com>
  • Loading branch information
j3soon and YuZhong-Chen committed Aug 21, 2024
1 parent b1bd29f commit f8e86d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 17 additions & 3 deletions template_ws/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 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

# 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
Expand Down Expand Up @@ -49,10 +56,17 @@ RUN --mount=type=cache,target=/var/cache/apt \
git-extras \
&& rm -rf /var/lib/apt/lists/*

# Install ROS2 RVIZ and Gazebo
# Install ROS2 Gazebo packages for amd64
RUN 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 \
apt-get update && apt-get install -y \
ros-$ROS_DISTRO-gazebo-ros-pkgs \
ros-$ROS_DISTRO-rviz2 \
&& rm -rf /var/lib/apt/lists/*

Expand Down
8 changes: 7 additions & 1 deletion template_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
services:
template-ws:
build: .
build:
context: .
dockerfile: Dockerfile
# 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
Expand Down

0 comments on commit f8e86d9

Please sign in to comment.