Skip to content

Commit f8e86d9

Browse files
j3soonYuZhong-Chen
andcommitted
feat(template_ws): Add multi-platform builds support
Co-authored-by: YuZhong-Chen <yuzhong1214@gmail.com>
1 parent b1bd29f commit f8e86d9

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

template_ws/docker/Dockerfile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble
2-
FROM osrf/ros:humble-desktop-full
2+
FROM osrf/ros:humble-desktop-full AS amd64
3+
# Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble
4+
FROM arm64v8/ros:humble AS arm64
5+
6+
# Use docker automatic platform args to select the base image.
7+
# It may be `arm64` or `amd64` depending on the platform.
8+
# Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope
9+
FROM $TARGETARCH
310

411
# Arguments for the default user
512
ARG USERNAME=user
@@ -49,10 +56,17 @@ RUN --mount=type=cache,target=/var/cache/apt \
4956
git-extras \
5057
&& rm -rf /var/lib/apt/lists/*
5158

52-
# Install ROS2 RVIZ and Gazebo
59+
# Install ROS2 Gazebo packages for amd64
60+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
61+
apt-get update && apt-get install -y \
62+
ros-$ROS_DISTRO-gazebo-ros-pkgs \
63+
ros-$ROS_DISTRO-gazebo-ros2-control \
64+
&& rm -rf /var/lib/apt/lists/*; \
65+
fi
66+
67+
# Install ROS2 RVIZ and other custom ROS2 packages
5368
RUN --mount=type=cache,target=/var/cache/apt \
5469
apt-get update && apt-get install -y \
55-
ros-$ROS_DISTRO-gazebo-ros-pkgs \
5670
ros-$ROS_DISTRO-rviz2 \
5771
&& rm -rf /var/lib/apt/lists/*
5872

template_ws/docker/compose.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
services:
22
template-ws:
3-
build: .
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
# Specify the target platform to build the image, otherwise it will build for the host platform.
7+
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
8+
# platforms:
9+
# - "linux/arm64"
410
image: j3soon/ros2-template-ws
511
container_name: ros2-template-ws
612
stdin_open: true

0 commit comments

Comments
 (0)