-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathDockerfile
More file actions
107 lines (92 loc) · 4.97 KB
/
Dockerfile
File metadata and controls
107 lines (92 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
ARG ROS_DISTRO="humble"
# ===================================================================
# Development Stage: Build the full workspace with all tools for development
# ===================================================================
FROM docker.io/library/ros:${ROS_DISTRO} AS development
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NOWARNINGS=yes
RUN --mount=type=cache,id=apt-cache-${TARGETARCH},target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=apt-lib-${TARGETARCH},target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends \
python3-pip \
python3-rospkg \
python3-rosdep \
software-properties-common \
ccache && \
add-apt-repository ppa:kisak/kisak-mesa -y && \
apt-get update && \
apt-get install -y --no-install-recommends libegl-mesa0
# Keep the cached APT files to speed up subsequent builds
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
# Copy all necessary source directories
WORKDIR /home/ubuntu/Desktop/scenario_simulator_ws/src
COPY . .
# Install dependencies for all copied packages
RUN git clone --depth 1 https://github.com/autowarefoundation/autoware_launch.git /tmp/autoware_launch && \
mv /tmp/autoware_launch/vehicle/sample_vehicle_launch/sample_vehicle_description /home/ubuntu/Desktop/scenario_simulator_ws/src/sample_vehicle_description && \
rm -rf /tmp/autoware_launch && \
mkdir -p external && \
vcs import external < dependency_${ROS_DISTRO}.repos
RUN --mount=type=cache,id=apt-cache-${TARGETARCH},target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=apt-lib-${TARGETARCH},target=/var/lib/apt,sharing=locked \
bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && \
apt-get update && \
rosdep install -iy --from-paths . --rosdistro ${ROS_DISTRO}"
WORKDIR /home/ubuntu/Desktop/scenario_simulator_ws
ENV CC="/usr/lib/ccache/gcc"
ENV CXX="/usr/lib/ccache/g++"
ENV CCACHE_DIR="/ccache"
RUN --mount=type=cache,target=/ccache bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && \
colcon build --cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_CPP_MOCK_SCENARIOS=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
# ===================================================================
# Runtime Stage: Create a minimal final image
# ===================================================================
FROM docker.io/library/ros:${ROS_DISTRO}-ros-base AS runtime
# cspell: ignore libtbb libprotobuf
# Install runtime dependencies in a single layer and clean up
RUN --mount=type=cache,id=apt-cache-${TARGETARCH},target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=apt-lib-${TARGETARCH},target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends \
software-properties-common python3-pip && \
add-apt-repository universe -y && \
apt-get update && \
apt-get install -y --no-install-recommends \
ros-humble-rmw-cyclonedds-cpp libgoogle-glog0v5 libprotobuf23 libzmq5 \
libpugixml1v5 libtbb12 libboost-filesystem1.74.0 ros-humble-lanelet2-matching \
ros-humble-lanelet2-io ros-humble-lanelet2-routing libgeographic19 \
ros-humble-behaviortree-cpp-v3 ros-humble-geographic-msgs && \
pip install xmlschema && \
apt-get remove --purge -y software-properties-common python3-pip && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=development /home/ubuntu/Desktop/scenario_simulator_ws/install/ /home/ubuntu/Desktop/scenario_simulator_ws/install/
COPY --from=development /home/ubuntu/Desktop/scenario_simulator_ws/log/ /home/ubuntu/Desktop/scenario_simulator_ws/log/
COPY --from=development /home/ubuntu/Desktop/scenario_simulator_ws/src/ /home/ubuntu/Desktop/scenario_simulator_ws/src/
# Remove unnecessary development files from the copied artifacts
RUN find /home/ubuntu/Desktop/scenario_simulator_ws/install -name cmake -type d -exec rm -rf {} + && \
find /home/ubuntu/Desktop/scenario_simulator_ws/install -name '*.a' -type f -delete && \
rm -rf /home/ubuntu/Desktop/scenario_simulator_ws/install/include
COPY ./docker-entrypoint.sh /
RUN chmod a+x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
# ===================================================================
# Desktop Stage: Inherit from runtime and add desktop tools like rviz
# ===================================================================
FROM runtime AS desktop
# Install ros2 desktop packages and rviz2
RUN --mount=type=cache,id=apt-cache-${TARGETARCH},target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=apt-lib-${TARGETARCH},target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends \
ros-${ROS_DISTRO}-desktop \
ros-${ROS_DISTRO}-rviz2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*