1- FROM ubuntu:24.04 AS builder
1+ # Build arguments for version configuration
2+ ARG UBUNTU_VERSION=24.04
3+ ARG CUDA_VERSION=13.1.0
4+ ARG ROS_DISTRO=jazzy
5+
6+ FROM ubuntu:${UBUNTU_VERSION} AS builder
7+
8+ # Re-declare ARG after FROM to make it available in this stage
9+ ARG ROS_DISTRO
10+ ARG UBUNTU_VERSION
211
312# setup
413ENV DEBIAN_FRONTEND=noninteractive
5- ENV ROS_DISTRO=jazzy
14+ ENV ROS_DISTRO=${ROS_DISTRO}
615
716# install build dependencies
817RUN apt-get update \
9- # add ROS 2 Jazzy sources, see e.g. https://docs.ros.org/en/jazzy /Installation/Ubuntu-Install-Debians.html
18+ # add ROS 2 sources, see e.g. https://docs.ros.org/en/humble /Installation/Ubuntu-Install-Debians.html
1019 && apt-get install -y \
1120 software-properties-common \
1221 && add-apt-repository universe \
@@ -31,6 +40,13 @@ RUN apt-get update \
3140 ros-${ROS_DISTRO}-ament-cmake-pytest \
3241 && rm -rf /var/lib/apt/lists/*
3342
43+ # create ubuntu user (only needed for Ubuntu 22.04 as it doesn't exist in base image)
44+ # Note: Ubuntu 24.04 base images already include the ubuntu user with uid=1000, gid=1000
45+ RUN if [ "$UBUNTU_VERSION" = "22.04" ]; then \
46+ groupadd --gid 1000 ubuntu \
47+ && useradd --uid 1000 --gid 1000 -m ubuntu; \
48+ fi
49+
3450# non-root user installation stuff
3551USER ubuntu
3652WORKDIR /home/ubuntu
@@ -77,22 +93,32 @@ RUN cd roboreg-deployment \
7793 /home/ubuntu/.cache \
7894 /tmp/*
7995
80- FROM nvidia/cuda:13.1.0-base-ubuntu24.04 AS runtime
96+ FROM nvidia/cuda:${CUDA_VERSION}-base-ubuntu${UBUNTU_VERSION} AS runtime
97+
98+ # Re-declare ARGs after FROM to make them available in this stage
99+ ARG CUDA_VERSION
100+ ARG UBUNTU_VERSION
101+ ARG ROS_DISTRO
81102
82103# setup
83104ENV DEBIAN_FRONTEND=noninteractive
84- ENV ROS_DISTRO=jazzy
85-
86- # add ubuntu to sudoers: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user
87- RUN apt-get update \
105+ ENV ROS_DISTRO=${ROS_DISTRO}
106+ # create ubuntu user and add to sudoers (only needed for Ubuntu 22.04 as it doesn't exist in base image)
107+ # Note: Ubuntu 24.04 CUDA base images already include the ubuntu user with uid=1000, gid=1000
108+ RUN if [ "$UBUNTU_VERSION" = "22.04" ]; then \
109+ groupadd --gid 1000 ubuntu \
110+ && useradd --uid 1000 --gid 1000 -m ubuntu; \
111+ fi \
112+ # add ubuntu to sudoers: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user
113+ && apt-get update \
88114 && apt-get install -y sudo \
89115 && echo ubuntu ALL=\( root\) NOPASSWD:ALL > /etc/sudoers.d/ubuntu \
90116 && chmod 0440 /etc/sudoers.d/ubuntu \
91117 && rm -rf /var/lib/apt/lists/*
92118
93119# install runtime dependencies
94120RUN apt-get update \
95- # add ROS 2 Jazzy sources, see e.g. https://docs.ros.org/en/jazzy /Installation/Ubuntu-Install-Debians.html
121+ # add ROS 2 sources, see e.g. https://docs.ros.org/en/humble /Installation/Ubuntu-Install-Debians.html
96122 && apt-get install -y \
97123 software-properties-common \
98124 && add-apt-repository universe \
@@ -109,6 +135,10 @@ RUN apt-get update \
109135 ros-${ROS_DISTRO}-xacro \
110136 libgl1 \
111137 libxrender1 \
138+ # python3-setuptools only needed for Ubuntu 22.04
139+ && if [ "$UBUNTU_VERSION" = "22.04" ]; then \
140+ apt-get install -y python3-setuptools; \
141+ fi \
112142 && rm -rf /var/lib/apt/lists/*
113143
114144# copy roboreg-deployment from builder stage
0 commit comments