Dockerfile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # Copyright (c) Contributors to the Open 3D Engine Project.
  2. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR MIT
  5. #
  6. # Collect the arguments for the base ros image
  7. ARG ROS_VERSION=humble
  8. ARG UBUNTU_VERSION=jammy
  9. FROM ros:${ROS_VERSION}-ros-base-${UBUNTU_VERSION}
  10. ARG ROS_VERSION
  11. ARG UBUNTU_VERSION
  12. # Argument to control the type of docker image to build
  13. ARG IMAGE_TYPE=simulation # Default to 'simulation'
  14. # Arguments for the source repos
  15. ARG O3DE_REPO=https://github.com/o3de/o3de.git
  16. ARG O3DE_BRANCH=development
  17. ARG O3DE_EXTRAS_REPO=https://github.com/o3de/o3de-extras.git
  18. ARG O3DE_EXTRAS_BRANCH=development
  19. ARG ROSCON_DEMO_REPO=https://github.com/o3de/ROSConDemo.git
  20. ARG ROSCON_DEMO_BRANCH=main
  21. # Additional argument to control build concurrency
  22. ARG CMAKE_JOBS=8
  23. ARG DEBIAN_FRONTEND=noninteractive
  24. ENV WORKSPACE=/data/workspace
  25. WORKDIR $WORKSPACE
  26. # Verify only the supported ROS2 versions was specified
  27. RUN if [ "${ROS_VERSION}" = "humble" ]; then \
  28. echo "Building ROS2/Humble based image"; \
  29. elif [ "${ROS_VERSION}" = "galactic" ]; then \
  30. echo "Building ROS2/Galactic based image"; \
  31. else \
  32. echo "Unsupported ROS_VERSION: ${ROS_VERSION}" && exit 1; \
  33. fi
  34. # Setup time zone and locale data (necessary for SSL and HTTPS packages)
  35. RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get -y \
  36. install \
  37. tzdata \
  38. locales \
  39. keyboard-configuration \
  40. && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
  41. && dpkg-reconfigure --frontend=noninteractive locales \
  42. && update-locale LANG=en_US.UTF-8 \
  43. && rm -rf /var/lib/apt/lists/*
  44. ENV LANG=en_US.UTF-8
  45. # Install the required ubuntu packages
  46. RUN apt-get update && apt-get install -y \
  47. bc \
  48. bind9-utils \
  49. binutils \
  50. ca-certificates \
  51. clang \
  52. cmake \
  53. curl \
  54. file \
  55. firewalld \
  56. git \
  57. git-lfs \
  58. jq \
  59. kbd \
  60. kmod \
  61. less \
  62. lsb-release \
  63. libglu1-mesa-dev \
  64. libxcb-xinerama0 \
  65. libfontconfig1-dev \
  66. libcurl4-openssl-dev \
  67. libnvidia-gl-470 \
  68. libssl-dev \
  69. libxcb-xkb-dev \
  70. libxkbcommon-x11-dev \
  71. libxkbcommon-dev \
  72. libxcb-xfixes0-dev \
  73. libxcb-xinput-dev \
  74. libxcb-xinput0 \
  75. libpcre2-16-0 \
  76. lsof \
  77. net-tools \
  78. ninja-build \
  79. pciutils \
  80. python3-pip \
  81. software-properties-common \
  82. sudo \
  83. tar \
  84. unzip \
  85. vim \
  86. wget \
  87. xz-utils \
  88. && rm -rf /var/lib/apt/lists/*
  89. # Setup and install the ROS packages
  90. RUN sh -c 'echo "deb [arch=amd64,arm64] http://repo.ros2.org/ubuntu/main `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list' \
  91. && curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
  92. RUN apt-get update && apt-get install -y \
  93. ros-${ROS_DISTRO}-ackermann-msgs \
  94. ros-${ROS_DISTRO}-control-toolbox \
  95. ros-${ROS_DISTRO}-gazebo-msgs \
  96. ros-${ROS_DISTRO}-joy \
  97. ros-${ROS_DISTRO}-navigation2 \
  98. ros-${ROS_DISTRO}-rviz2 \
  99. ros-${ROS_DISTRO}-tf2-ros \
  100. ros-${ROS_DISTRO}-urdfdom \
  101. ros-${ROS_DISTRO}-vision-msgs \
  102. python3-colcon-common-extensions \
  103. ros-${ROS_DISTRO}-cyclonedds \
  104. ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \
  105. ros-${ROS_DISTRO}-slam-toolbox \
  106. ros-${ROS_DISTRO}-navigation2 \
  107. ros-${ROS_DISTRO}-nav2-bringup \
  108. ros-${ROS_DISTRO}-pointcloud-to-laserscan \
  109. ros-${ROS_DISTRO}-teleop-twist-keyboard \
  110. ros-${ROS_DISTRO}-ackermann-msgs \
  111. ros-${ROS_DISTRO}-topic-tools \
  112. && rm -rf /var/lib/apt/lists/* \
  113. && pip install python-statemachine
  114. # Depending on the image type, sync, setup and build only whats needed
  115. RUN if [ "${IMAGE_TYPE}" = "full" ]; then \
  116. git clone --recursive $O3DE_REPO $WORKSPACE/o3de \
  117. && git -C $WORKSPACE/o3de checkout $O3DE_BRANCH \
  118. && git -C $WORKSPACE/o3de lfs install \
  119. && git -C $WORKSPACE/o3de lfs pull \
  120. && $WORKSPACE/o3de/python/get_python.sh \
  121. && $WORKSPACE/o3de/scripts/o3de.sh register -ep $WORKSPACE/o3de \
  122. && git clone $O3DE_EXTRAS_REPO \
  123. && git -C $WORKSPACE/o3de-extras checkout $O3DE_EXTRAS_BRANCH \
  124. && $WORKSPACE/o3de/scripts/o3de.sh register -gp $WORKSPACE/o3de-extras/Gems/ROS2 \
  125. && git clone $ROSCON_DEMO_REPO \
  126. && git -C $WORKSPACE/ROSConDemo checkout $ROSCON_DEMO_BRANCH \
  127. && git -C $WORKSPACE/ROSConDemo lfs install \
  128. && git -C $WORKSPACE/ROSConDemo lfs pull \
  129. && $WORKSPACE/o3de/scripts/o3de.sh register -pp $WORKSPACE/ROSConDemo/Project \
  130. && . /opt/ros/humble/setup.sh \
  131. && cd $WORKSPACE/ROSConDemo/Project \
  132. && cmake -B $WORKSPACE/ROSConDemo/Project/build/linux -S . -G "Ninja Multi-Config" -DLY_DISABLE_TEST_MODULES=ON -DLY_STRIP_DEBUG_SYMBOLS=ON \
  133. && cmake --build $WORKSPACE/ROSConDemo/Project/build/linux --config profile --target ROSConDemo.GameLauncher Editor ROSConDemo.Assets -j $CMAKE_JOBS \
  134. && cd $WORKSPACE/ROSConDemo/kraken_nav \
  135. && colcon build --symlink-install \
  136. && rm -rf ~/.o3de/3rdParty/ \
  137. && rm -rf $WORKSPACE/o3de/.git \
  138. && rm -rf $WORKSPACE/o3de/AutomatedTesting \
  139. && rm -rf $WORKSPACE/o3de/python/downloaded_packages \
  140. && rm -rf $WORKSPACE/o3de/Code \
  141. && rm -rf $WORKSPACE/o3de/Gems \
  142. && rm -rf $WORKSPACE/ROSConDemo/build/linux/Azcg/ \
  143. && rm -rf $WORKSPACE/ROSConDemo/build/linux/CMake \
  144. && rm -rf $WORKSPACE/ROSConDemo/build/linux/CMakeFiles/ \
  145. && rm -rf $WORKSPACE/ROSConDemo/build/linux/External/ \
  146. && rm -rf $WORKSPACE/ROSConDemo/build/linux/Testing/ \
  147. && rm -rf $WORKSPACE/ROSConDemo/build/linux/_deps/ \
  148. && rm -rf $WORKSPACE/ROSConDemo/build/linux/cmake \
  149. && rm -rf $WORKSPACE/ROSConDemo/build/linux/lib/ \
  150. && rm -rf $WORKSPACE/ROSConDemo/build/linux/o3de/ \
  151. && rm -rf $WORKSPACE/ROSConDemo/build/linux/packages/; \
  152. elif [ "${IMAGE_TYPE}" = "simulation" ]; then \
  153. git clone --recursive $O3DE_REPO $WORKSPACE/o3de \
  154. && git -C $WORKSPACE/o3de checkout $O3DE_BRANCH \
  155. && git -C $WORKSPACE/o3de lfs install \
  156. && git -C $WORKSPACE/o3de lfs pull \
  157. && $WORKSPACE/o3de/python/get_python.sh \
  158. && $WORKSPACE/o3de/scripts/o3de.sh register -ep $WORKSPACE/o3de \
  159. && git clone $O3DE_EXTRAS_REPO \
  160. && git -C $WORKSPACE/o3de-extras checkout $O3DE_EXTRAS_BRANCH \
  161. && $WORKSPACE/o3de/scripts/o3de.sh register -gp $WORKSPACE/o3de-extras/Gems/ROS2 \
  162. && git clone $ROSCON_DEMO_REPO \
  163. && git -C $WORKSPACE/ROSConDemo checkout $ROSCON_DEMO_BRANCH \
  164. && git -C $WORKSPACE/ROSConDemo lfs install \
  165. && git -C $WORKSPACE/ROSConDemo lfs pull \
  166. && $WORKSPACE/o3de/scripts/o3de.sh register -pp $WORKSPACE/ROSConDemo/Project \
  167. && . /opt/ros/humble/setup.sh \
  168. && cd $WORKSPACE/ROSConDemo/Project \
  169. && cmake -B $WORKSPACE/ROSConDemo/Project/build/linux -S . -G "Ninja Multi-Config" -DLY_DISABLE_TEST_MODULES=ON -DLY_STRIP_DEBUG_SYMBOLS=ON \
  170. && cmake --build $WORKSPACE/ROSConDemo/Project/build/linux --config profile --target ROSConDemo.GameLauncher ROSConDemo.Assets -j $CMAKE_JOBS \
  171. && cd $WORKSPACE/ROSConDemo/kraken_nav \
  172. && colcon build --symlink-install \
  173. && rm -rf $WORKSPACE/o3de-extras/ \
  174. && rm -rf ~/.o3de/3rdParty/ \
  175. && rm -rf $WORKSPACE/o3de/.git \
  176. && rm -rf $WORKSPACE/o3de/AutomatedTesting \
  177. && rm -rf $WORKSPACE/o3de/python/downloaded_packages \
  178. && rm -rf $WORKSPACE/o3de/Code \
  179. && rm -rf $WORKSPACE/o3de/Gems \
  180. && rm -rf $WORKSPACE/ROSConDemo/.git \
  181. && rm -rf $WORKSPACE/ROSConDemo/Gem \
  182. && rm -rf $WORKSPACE/ROSConDemo/Source \
  183. && rm -rf $WORKSPACE/ROSConDemo/Levels \
  184. && rm -rf $WORKSPACE/ROSConDemo/ReflectionProbes \
  185. && rm -rf $WORKSPACE/ROSConDemo/build/linux/Azcg/ \
  186. && rm -rf $WORKSPACE/ROSConDemo/build/linux/CMake \
  187. && rm -rf $WORKSPACE/ROSConDemo/build/linux/CMakeFiles/ \
  188. && rm -rf $WORKSPACE/ROSConDemo/build/linux/External/ \
  189. && rm -rf $WORKSPACE/ROSConDemo/build/linux/Testing/ \
  190. && rm -rf $WORKSPACE/ROSConDemo/build/linux/_deps/ \
  191. && rm -rf $WORKSPACE/ROSConDemo/build/linux/cmake \
  192. && rm -rf $WORKSPACE/ROSConDemo/build/linux/lib/ \
  193. && rm -rf $WORKSPACE/ROSConDemo/build/linux/o3de/ \
  194. && rm -rf $WORKSPACE/ROSConDemo/build/linux/packages/ \
  195. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/*.Editor.so \
  196. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/EditorPlugins \
  197. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/Editor \
  198. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/AssetProcessor \
  199. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/AssetProcessorBatch \
  200. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/MaterialEditor \
  201. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/AssetBuilder \
  202. && rm -rf $WORKSPACE/ROSConDemo/build/linux/bin/profile/MaterialCanvas; \
  203. elif [ "${IMAGE_TYPE}" = "navstack" ]; then \
  204. git clone $ROSCON_DEMO_REPO \
  205. && git -C $WORKSPACE/ROSConDemo checkout $ROSCON_DEMO_BRANCH \
  206. && git -C $WORKSPACE/ROSConDemo lfs install \
  207. && git -C $WORKSPACE/ROSConDemo lfs pull \
  208. && cd $WORKSPACE/ROSConDemo/kraken_nav \
  209. && colcon build --symlink-install; \
  210. else \
  211. echo "Unsupported IMAGE_TYPE: ${IMAGE_TYPE}" && exit 1; \
  212. fi
  213. ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
  214. # Add the appropriate ros2 environment setup script to the system startup
  215. RUN echo "[Unit]" > /etc/systemd/system/setup_ros.service \
  216. && echo "After=network.target" >> /etc/systemd/system/setup_ros.service \
  217. && echo "" >> /etc/systemd/system/setup_ros.service \
  218. && echo "[Service]" >> /etc/systemd/system/setup_ros.service \
  219. && if [ "${ROS_VERSION}" = "humble" ]; then \
  220. echo "ExecStart=/opt/ros/humble/setup.bash" >> /etc/systemd/system/setup_ros.service; \
  221. elif [ "${ROS_VERSION}" = "galactic" ]; then \
  222. echo "ExecStart=/opt/ros/galactic/setup.bash" >> /etc/systemd/system/setup_ros.service; \
  223. fi \
  224. && echo "" >> /etc/systemd/system/setup_ros.service \
  225. && echo "[Install]" >> /etc/systemd/system/setup_ros.service \
  226. && echo "WantedBy=default.target" >> /etc/systemd/system/setup_ros.service \
  227. && echo "" >> /etc/systemd/system/setup_ros.service
  228. ENV NVIDIA_VISIBLE_DEVICES all
  229. ENV NVIDIA_DRIVER_CAPABILITIES all