content: ARG BASE_IMAGE=ghcr.io/watonomous/robot_base/base:humble-ubuntu22.04
  
  ################################ Source ################################
  FROM ${BASE_IMAGE} AS source
  
  WORKDIR ${AMENT_WS}/src
  
  # Copy in source code 
  COPY src/samples/cpp/producer producer
  COPY src/wato_msgs/sample_msgs sample_msgs
  
  # Scan for rosdeps
  RUN apt-get -qq update && rosdep update && \
      rosdep install --from-paths . --ignore-src -r -s \
          | (grep 'apt-get install' || true) \
          | awk '{print $3}' \
          | sort  > /tmp/colcon_install_list
  
  ################################# Dependencies ################################
  FROM ${BASE_IMAGE} AS dependencies
  
  # Install Rosdep requirements
  COPY --from=source /tmp/colcon_install_list /tmp/colcon_install_list
  RUN apt-fast install -qq -y --no-install-recommends $(cat /tmp/colcon_install_list)
  
  # Copy in source code from source stage
  WORKDIR ${AMENT_WS}
  COPY --from=source ${AMENT_WS}/src src
  
  # Dependency Cleanup
  WORKDIR /
  RUN apt-get -qq autoremove -y && apt-get -qq autoclean && apt-get -qq clean && \
      rm -rf /root/* /root/.ros /tmp/* /var/lib/apt/lists/* /usr/share/doc/*
  
  ################################ Build ################################
  FROM dependencies AS build
  
  # Build ROS2 packages
  WORKDIR ${AMENT_WS}
  RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
      colcon build \
          --cmake-args -DCMAKE_BUILD_TYPE=Release --install-base ${WATONOMOUS_INSTALL}
  
  # Source and Build Artifact Cleanup 
  RUN rm -rf src/* build/* devel/* install/* log/*
  
  # Entrypoint will run before any CMD on launch. Sources ~/opt/<ROS_DISTRO>/setup.bash and ~/ament_ws/install/setup.bash
  COPY docker/wato_ros_entrypoint.sh ${AMENT_WS}/wato_ros_entrypoint.sh
  ENTRYPOINT ["./wato_ros_entrypoint.sh"]
  