Skip to content

Commit 657b12d

Browse files
ruffslmsz-rai
andauthored
Add Dockerfile to simplify build process (#40)
* Add package.xml file * Omit linters * Add missing rosdistro keys for gazebo depends * Add .dockerignore file * Simplify * Add Dockerfile * Add docker build command to README * Lint Dockerfile * Separate RobotecGPULidar project to external directory * Add expected project tree info * Only extract so file from install path to demonstrate cmake issues * Use cache mounts for src folder to demonstrate cmake issues * Make source folder read only to demonstrate cmake issues * Reenable build as expected by relaxing normal build conventions to demonstrate cmake issues * Do not hardcode CMAKE_INSTALL_PREFIX * Make project files read-only. This commit changes RGL download directory from SOURCE_DIR to BINARY_DIR * Update .dockerignore to exempt dir external * Simplify builder stage now that cmake behaves * Simplify and copy install path --------- Co-authored-by: Mateusz Szczygielski <[email protected]>
1 parent 017d43b commit 657b12d

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Ignore everything by default
2+
*
3+
4+
# First-order allow exception for select directories
5+
!/external
6+
!/lidar_patterns
7+
!/RGLServerPlugin
8+
!/RGLVisualize
9+
10+
# First-order allow exception for select files
11+
!/CMakeLists.txt
12+
!/package.xml

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ARG BASE_IMAGE=base
2+
FROM ros:jazzy AS base
3+
4+
# Edit apt config for caching and update once
5+
RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/ && \
6+
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' \
7+
> /etc/apt/apt.conf.d/keep-cache && \
8+
apt-get update
9+
10+
################################################################################
11+
# MARK: prepper - prep rgl dependencies
12+
################################################################################
13+
### Core dependencies stage
14+
FROM $BASE_IMAGE AS prepper
15+
16+
# Set working directory using standard opt path
17+
WORKDIR /opt/rgl
18+
19+
# Copy package manifest
20+
COPY package.xml src/RGLGazeboPlugin/package.xml
21+
22+
# Install bootstrap tools for install scripts
23+
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
24+
rosdep install -y \
25+
--from-paths src \
26+
--ignore-src
27+
28+
################################################################################
29+
# MARK: builder - build rgl binaries
30+
################################################################################
31+
FROM prepper AS builder
32+
33+
# Copy source tree
34+
COPY . src/RGLGazeboPlugin
35+
36+
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
37+
colcon build
38+
39+
################################################################################
40+
# MARK: dancer - multi-stage for cache dancing
41+
################################################################################
42+
FROM builder AS dancer
43+
44+
# Copy entire build directory
45+
# RUN mkdir /dancer && \
46+
# cp -rT build /dancer
47+
48+
# Copy only the lib and bin directories
49+
RUN mkdir /dancer && \
50+
cp -rT install /dancer
51+
52+
################################################################################
53+
# MARK: exporter - export rgl binaries and executables
54+
################################################################################
55+
FROM scratch AS exporter
56+
57+
COPY --from=dancer /dancer /

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ Key features:
5050
export GZ_GUI_PLUGIN_PATH=`pwd`/RGLGuiPlugin:$GZ_GUI_PLUGIN_PATH
5151
```
5252
### Building from source
53+
54+
#### Docker
55+
```shell
56+
docker build \
57+
--target=exporter \
58+
--output=install .
59+
```
60+
61+
#### Manual
5362
```shell
5463
mkdir build
5564
cd build

package.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>RGLGazeboPlugin</name>
5+
<version>0.1.2</version>
6+
<description>RGL Gazebo Plugin</description>
7+
<maintainer email="[email protected]">Mateusz Szczygielski</maintainer>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>gz_cmake_vendor</depend>
13+
<depend>gz_gui_vendor</depend>
14+
<depend>gz_msgs_vendor</depend>
15+
<depend>gz_plugin_vendor</depend>
16+
<depend>gz_rendering_vendor</depend>
17+
<depend>gz_sim_vendor</depend>
18+
19+
<export>
20+
<build_type>ament_cmake</build_type>
21+
</export>
22+
</package>

0 commit comments

Comments
 (0)