Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-gorecki committed Dec 4, 2023
1 parent 68ab64f commit 06c551e
Showing 1 changed file with 23 additions and 40 deletions.
63 changes: 23 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ARG ROS_DISTRO=humble
ARG ROS_DISTRO=iron
ARG PREFIX=

### BUILD IMAGE ###
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS build
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core

RUN apt update && apt install -y \
ros-$ROS_DISTRO-nav2-msgs
ENV SLAM_MODE=navigation
ENV PREFIX_ENV=$PREFIX

# Create healthcheck package
WORKDIR /ros2_ws

COPY ./healthcheck /healthcheck

# Install everything needed
RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
apt-get update --fix-missing && apt-get install -y \
Expand All @@ -23,8 +23,10 @@ RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y&& cd src/ && \
source /opt/ros/$ROS_DISTRO/setup.bash && \
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \
# Create healthcheck package
cd src/ && \
source "/opt/$MYDISTRO/$ROS_DISTRO/setup.bash" && \
ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp lifecycle_msgs nav2_msgs && \
sed -i '/find_package(nav2_msgs REQUIRED)/a \
add_executable(healthcheck_localization src/healthcheck_localization.cpp)\n \
Expand All @@ -38,49 +40,30 @@ RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
healthcheck_navigation \
healthcheck_slam \
DESTINATION lib/${PROJECT_NAME})' \
/ros2_ws/src/healthcheck_pkg/CMakeLists.txt

COPY ./healthcheck /ros2_ws/src/healthcheck_pkg/src

# Build
RUN source /opt/ros/$ROS_DISTRO/setup.bash && \
colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=Release

### RUNTIME IMAGE ###
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core

ARG PREFIX
ENV SLAM_MODE=navigation
ENV PREFIX_ENV=$PREFIX

WORKDIR /ros2_ws

RUN apt update && apt upgrade -y && apt install -y \
ros-$ROS_DISTRO-navigation2 \
ros-$ROS_DISTRO-nav2-bringup \
ros-$ROS_DISTRO-pointcloud-to-laserscan && \
mkdir /maps && \
/ros2_ws/src/healthcheck_pkg/CMakeLists.txt && \
mv /healthcheck/* /ros2_ws/src/healthcheck_pkg/src/ && \
rm -r /healthcheck && \
cd .. && \
# Build
colcon build && \
# Make the image smaller
export SUDO_FORCE_REMOVE=yes && \
apt-get remove -y \
ros-dev-tools && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY ./nav2_params /nav2_params
COPY --from=build /ros2_ws/install /ros2_ws/install

RUN echo $(dpkg -s ros-$ROS_DISTRO-navigation2 | grep 'Version' | sed -r 's/Version:\s([0-9]+.[0-9]+.[0-9]+).*/\1/g') > /version.txt

RUN if [ -f "/ros_entrypoint.sh" ]; then \
sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \
ros2 run healthcheck_pkg "healthcheck_$SLAM_MODE" &' \
/ros_entrypoint.sh; \
else \
sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \
RUN sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \
ros2 run healthcheck_pkg "healthcheck_$SLAM_MODE" &' \
/vulcanexus_entrypoint.sh; \
fi
/ros_entrypoint.sh

COPY ./healthcheck/healthcheck.sh /
HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \
CMD ["/healthcheck.sh"]

#tip: gathering logs from healthcheck: docker inspect b39 | jq '.[0].State.Health.Log'
# #tip: gathering logs from healthcheck: docker inspect b39 | jq '.[0].State.Health.Log'

0 comments on commit 06c551e

Please sign in to comment.