Skip to content

Commit 6b28953

Browse files
committed
Update main Dockerfile for "noble" base images:
- Use the provided user "ubuntu" at UID 1000 - Use a venv for user-installed python packages
1 parent 907e01d commit 6b28953

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

.docker/Dockerfile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN apt-get -q update \
1818
clang-tools \
1919
python3-pip \
2020
python3-dev \
21+
python3-venv \
2122
lsb-release \
2223
wget \
2324
gnupg \
@@ -38,14 +39,14 @@ RUN apt-get -q update \
3839

3940
FROM ci AS robot
4041

41-
# Configure a new non-root user
42-
ARG USERNAME=blue
42+
#
43+
# Ubuntu 24.04 "Noble", which is used as the base image for
44+
# jazzy and rolling images, now includes a user "ubuntu" at UID 1000
45+
ARG USERNAME=ubuntu
4346
ARG USER_UID=1000
4447
ARG USER_GID=$USER_UID
4548

46-
RUN groupadd --gid $USER_GID $USERNAME \
47-
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
48-
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
49+
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
4950
&& chmod 0440 /etc/sudoers.d/$USERNAME \
5051
&& usermod -a -G dialout $USERNAME \
5152
&& echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc
@@ -56,6 +57,16 @@ ENV DEBIAN_FRONTEND=noninteractive
5657
USER $USERNAME
5758
ENV USER=$USERNAME
5859

60+
# Python in Ubuntu is now marked as a "Externally managed environment",
61+
# Per best practice, create a venv for local python packages
62+
#
63+
# These two ENVs effectively "activate" the venv for subsequent calls to
64+
# python/pip in the Dockerfile
65+
WORKDIR /home/$USERNAME
66+
ENV VIRTUAL_ENV=/home/$USERNAME/.venv/blue
67+
RUN python3 -m venv --system-site-packages --symlinks $VIRTUAL_ENV
68+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
69+
5970
# Install MAVROS dependencies
6071
WORKDIR /home/$USERNAME
6172
RUN wget https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh \
@@ -97,7 +108,8 @@ RUN sudo apt-get -q update \
97108
&& sudo rm -rf /var/lib/apt/lists/*
98109

99110
RUN echo "source ${USER_WORKSPACE}/install/setup.bash" >> /home/$USERNAME/.bashrc \
100-
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc
111+
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc \
112+
&& echo "\n# Ensure colcon is run in the venv\nalias colcon='python3 -m colcon'" >> /home/$USERNAME/.bashrc
101113

102114
FROM robot AS desktop
103115

0 commit comments

Comments
 (0)