|
1 | 1 | # Build arguments for version configuration |
2 | | -ARG UBUNTU_VERSION=24.04 |
3 | | -ARG CUDA_VERSION=13.1.0 |
4 | | -ARG ROS_DISTRO=jazzy |
| 2 | +ARG PYTORCH_VERSION=2.6.0 |
| 3 | +ARG CUDA_VERSION=12.4 |
5 | 4 |
|
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 |
| 5 | +FROM pytorch/pytorch:${PYTORCH_VERSION}-cuda${CUDA_VERSION}-cudnn9-runtime |
11 | 6 |
|
12 | 7 | # setup |
13 | 8 | ENV DEBIAN_FRONTEND=noninteractive |
14 | | -ENV ROS_DISTRO=${ROS_DISTRO} |
15 | | - |
16 | | -# install build dependencies |
17 | | -RUN apt-get update \ |
18 | | - # add ROS 2 sources, see e.g. https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html |
19 | | - && apt-get install -y \ |
20 | | - software-properties-common \ |
21 | | - && add-apt-repository universe \ |
22 | | - && apt-get update \ |
23 | | - && apt-get install -y \ |
24 | | - curl \ |
25 | | - && curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \ |
26 | | - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null \ |
27 | | - && apt-get update \ |
28 | | - # install build tools (unavailable in base image and only required for builder stage) |
29 | | - && apt-get install -y \ |
30 | | - git \ |
31 | | - cmake \ |
32 | | - python3 \ |
33 | | - python3-venv \ |
34 | | - python3-pip \ |
35 | | - # install minimal ROS 2 build utilities |
36 | | - # remove ament_cmake_pytest on https://github.com/lbr-stack/lbr_fri_ros2_stack/issues/372 |
37 | | - && apt-get install -y \ |
38 | | - python3-colcon-common-extensions \ |
39 | | - ros-${ROS_DISTRO}-ament-cmake \ |
40 | | - ros-${ROS_DISTRO}-ament-cmake-pytest \ |
41 | | - && rm -rf /var/lib/apt/lists/* |
42 | | - |
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 | 9 |
|
50 | | -# non-root user installation stuff |
51 | | -USER ubuntu |
52 | | -WORKDIR /home/ubuntu |
53 | | - |
54 | | -# setup |
55 | | -COPY --chown=ubuntu:ubuntu . ./roboreg |
56 | | -ENV PIP_NO_CACHE_DIR=1 |
57 | | -SHELL ["/bin/bash", "-c"] |
58 | | - |
59 | | -# clone the LBR-Stack and xarm source code for robot description only |
60 | | -RUN mkdir -p roboreg-deployment/src \ |
61 | | - && git clone \ |
62 | | - --depth 1 \ |
63 | | - -b $ROS_DISTRO \ |
64 | | - https://github.com/lbr-stack/lbr_fri_ros2_stack.git roboreg-deployment/src/lbr_fri_ros2_stack \ |
65 | | - && git clone \ |
66 | | - --depth 1 \ |
67 | | - -b $ROS_DISTRO \ |
68 | | - --recursive \ |
69 | | - --shallow-submodules \ |
70 | | - https://github.com/xArm-Developer/xarm_ros2.git roboreg-deployment/src/xarm_ros2 |
71 | | - |
72 | | -# create a virtual environment and install roboreg |
73 | | -RUN cd roboreg-deployment \ |
74 | | - && python3 -m venv roboreg-venv \ |
75 | | - && touch roboreg-venv/COLCON_IGNORE \ |
76 | | - && cd .. \ |
77 | | - && source roboreg-deployment/roboreg-venv/bin/activate \ |
78 | | - && pip3 install roboreg/ \ |
79 | | - && rm -rf /home/ubuntu/.cache/pip |
80 | | - |
81 | | -# install robot description files |
82 | | -RUN cd roboreg-deployment \ |
83 | | - && source /opt/ros/${ROS_DISTRO}/setup.bash \ |
84 | | - && colcon build \ |
85 | | - --cmake-args -DBUILD_TESTING=0 \ |
86 | | - --packages-select \ |
87 | | - xarm_description \ |
88 | | - lbr_description \ |
89 | | - && rm -rf \ |
90 | | - roboreg-deployment/build \ |
91 | | - roboreg-deployment/log \ |
92 | | - roboreg-deployment/src \ |
93 | | - /home/ubuntu/.cache \ |
94 | | - /tmp/* |
95 | | - |
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 |
102 | | - |
103 | | -# setup |
104 | | -ENV DEBIAN_FRONTEND=noninteractive |
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 \ |
| 10 | +# create ubuntu user only if it doesn't exist yet |
| 11 | +RUN getent group ubuntu || groupadd --gid 1000 ubuntu \ |
| 12 | + && id -u ubuntu >/dev/null 2>&1 || useradd --uid 1000 --gid 1000 -m ubuntu \ |
112 | 13 | # add ubuntu to sudoers: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user |
113 | 14 | && apt-get update \ |
114 | 15 | && apt-get install -y sudo \ |
115 | 16 | && echo ubuntu ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/ubuntu \ |
116 | 17 | && chmod 0440 /etc/sudoers.d/ubuntu \ |
117 | 18 | && rm -rf /var/lib/apt/lists/* |
118 | 19 |
|
119 | | -# install runtime dependencies |
| 20 | +# install dependencies (most for displaying, can be removed if not needed) |
120 | 21 | RUN apt-get update \ |
121 | | - # add ROS 2 sources, see e.g. https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html |
122 | | - && apt-get install -y \ |
123 | | - software-properties-common \ |
124 | | - && add-apt-repository universe \ |
125 | | - && apt-get update \ |
126 | | - && apt-get install -y \ |
127 | | - curl \ |
128 | | - && curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \ |
129 | | - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null \ |
130 | | - && apt-get update \ |
131 | | - # install minimal runtime utilities |
| 22 | + # install build tools (unavailable in base image and only required for builder stage) |
132 | 23 | && apt-get install -y \ |
133 | | - python3 \ |
134 | | - ros-${ROS_DISTRO}-ament-index-python \ |
135 | | - ros-${ROS_DISTRO}-xacro \ |
136 | | - libgl1 \ |
137 | | - 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 \ |
| 24 | + libx11-6 \ |
| 25 | + libxext6 \ |
| 26 | + libxrender1 \ |
| 27 | + libxrandr2 \ |
| 28 | + libxinerama1 \ |
| 29 | + libxcursor1 \ |
| 30 | + libxfixes3 \ |
| 31 | + libxi6 \ |
| 32 | + libgl1 \ |
| 33 | + libgl1-mesa-dri \ |
| 34 | + libglx-mesa0 \ |
| 35 | + libegl1 \ |
| 36 | + libglib2.0-0 \ |
| 37 | + libfontconfig1 \ |
| 38 | + libfreetype6 \ |
| 39 | + libdbus-1-3 \ |
| 40 | + mesa-utils \ |
| 41 | + x11-apps \ |
142 | 42 | && rm -rf /var/lib/apt/lists/* |
143 | 43 |
|
144 | | -# copy roboreg-deployment from builder stage |
145 | | -COPY --chown=ubuntu:ubuntu --from=builder /home/ubuntu/roboreg-deployment/roboreg-venv /home/ubuntu/roboreg-deployment/roboreg-venv |
146 | | -COPY --chown=ubuntu:ubuntu --from=builder /home/ubuntu/roboreg-deployment/install /home/ubuntu/roboreg-deployment/install |
147 | | -COPY --chown=ubuntu:ubuntu --from=builder /home/ubuntu/roboreg/test/assets /home/ubuntu/sample-data |
148 | | - |
149 | | -# non-root user |
| 44 | +# non-root user installation stuff |
150 | 45 | USER ubuntu |
151 | 46 | WORKDIR /home/ubuntu |
152 | 47 |
|
153 | | -# source ROS 2 workspace |
154 | | -RUN echo "source /home/ubuntu/roboreg-deployment/install/setup.bash" >> .bashrc |
155 | | -RUN echo "source /home/ubuntu/roboreg-deployment/roboreg-venv/bin/activate" >> .bashrc |
| 48 | +# setup |
| 49 | +COPY --chown=ubuntu:ubuntu . ./roboreg |
| 50 | +ENV PIP_NO_CACHE_DIR=1 |
| 51 | +SHELL ["/bin/bash", "-c"] |
156 | 52 |
|
157 | 53 | # extend PATH (for CLI) |
158 | | -ENV PATH="$PATH:/home/ubuntu/roboreg-deployment/roboreg-venv/bin" |
| 54 | +ENV PATH="$PATH:/home/ubuntu/.local/bin" |
| 55 | + |
| 56 | +# install roboreg (to use cached libraries, break system packages for Ubuntu 24.04) |
| 57 | +RUN UBUNTU_VERSION=$(grep -oP '(?<=VERSION_ID=")[^"]+' /etc/os-release) && \ |
| 58 | + echo "Detected Ubuntu $UBUNTU_VERSION" && \ |
| 59 | + if [ "$UBUNTU_VERSION" = "24.04" ]; then \ |
| 60 | + pip install --upgrade pip setuptools wheel --break-system-packages && \ |
| 61 | + pip install roboreg/ --no-build-isolation --break-system-packages; \ |
| 62 | + else \ |
| 63 | + pip install --upgrade pip setuptools wheel && \ |
| 64 | + pip install roboreg/ --no-build-isolation; \ |
| 65 | + fi \ |
| 66 | + && rm -rf /home/ubuntu/.cache/pip |
| 67 | + |
| 68 | +# copy sample data |
| 69 | +RUN mkdir sample-data \ |
| 70 | + && cp -r roboreg/test/assets/* sample-data/ |
159 | 71 |
|
160 | 72 | # run inside the roboreg folder (where data is located) |
161 | 73 | CMD ["/bin/bash"] |
0 commit comments