Skip to content

Commit 3330220

Browse files
authored
Merge pull request #102 from lbr-stack/copilot/deprecate-duplicate-dockerfiles
Unify duplicate Dockerfiles using build arguments
2 parents d999784 + 7501f75 commit 3330220

File tree

4 files changed

+71
-150
lines changed

4 files changed

+71
-150
lines changed

.docker/cuda-13.1.0-ubuntu-24.04.Dockerfile renamed to .docker/Dockerfile

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
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
413
ENV DEBIAN_FRONTEND=noninteractive
5-
ENV ROS_DISTRO=jazzy
14+
ENV ROS_DISTRO=${ROS_DISTRO}
615

716
# install build dependencies
817
RUN 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
3551
USER ubuntu
3652
WORKDIR /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
83104
ENV 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
94120
RUN 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

.docker/cuda-12.4.1-ubuntu-22.04.Dockerfile

Lines changed: 0 additions & 137 deletions
This file was deleted.

.github/workflows/docker.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ on:
99
jobs:
1010
docker:
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- ubuntu_version: "22.04"
16+
cuda_version: "12.4.1"
17+
ros_distro: "humble"
18+
- ubuntu_version: "24.04"
19+
cuda_version: "13.1.0"
20+
ros_distro: "jazzy"
1221
steps:
1322
- name: Login to GitHub Container Registry
1423
uses: docker/login-action@v3
@@ -27,8 +36,12 @@ jobs:
2736
uses: docker/build-push-action@v6
2837
with:
2938
platforms: linux/amd64
30-
file: .docker/cuda-13.1.0-ubuntu-24.04.Dockerfile
39+
file: .docker/Dockerfile
40+
build-args: |
41+
UBUNTU_VERSION=${{ matrix.ubuntu_version }}
42+
CUDA_VERSION=${{ matrix.cuda_version }}
43+
ROS_DISTRO=${{ matrix.ros_distro }}
3144
push: ${{ github.ref == 'refs/heads/main' }}
3245
tags: |
33-
roboreg:latest
34-
ghcr.io/lbr-stack/roboreg:latest
46+
roboreg:${{ matrix.ubuntu_version }}
47+
ghcr.io/lbr-stack/roboreg:${{ matrix.ubuntu_version }}

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,22 @@ Next:
9191
cd roboreg
9292
docker build \
9393
-t roboreg:latest \
94-
-f .docker/cuda-13.1.0-ubuntu-24.04.Dockerfile \
94+
-f .docker/Dockerfile \
95+
--build-arg UBUNTU_VERSION=24.04 \
96+
--build-arg CUDA_VERSION=13.1.0 \
97+
--build-arg ROS_DISTRO=jazzy \
98+
.
99+
```
100+
101+
For Ubuntu 22.04 with ROS 2 Humble and CUDA 12.4.1, use:
102+
103+
```shell
104+
docker build \
105+
-t roboreg:latest \
106+
-f .docker/Dockerfile \
107+
--build-arg UBUNTU_VERSION=22.04 \
108+
--build-arg CUDA_VERSION=12.4.1 \
109+
--build-arg ROS_DISTRO=humble \
95110
.
96111
```
97112

0 commit comments

Comments
 (0)