ARG ROS_DISTRO=jazzy
FROM delicjusz/ros2aria:$ROS_DISTRO AS pkg-builder
SHELL ["/bin/bash", "-c"]

WORKDIR /ros2_ws
COPY ./src /ros2_ws/src
RUN apt update &&  apt install -y ros-dev-tools && source /opt/ros/$ROS_DISTRO/setup.bash && \
    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 && \
    colcon build

FROM delicjusz/ros2aria:$ROS_DISTRO
ARG ROS_DISTRO

SHELL ["/bin/bash", "-c"]
WORKDIR /ros2_ws

COPY --from=pkg-builder /ros2_ws /ros2_ws
RUN apt-get update && apt-get install -y ros-dev-tools  && \
    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

RUN apt-get clean && \
	apt-get remove -y \
		ros-dev-tools  && \
	rm -rf /var/lib/apt/lists/*