FROM osrf/ros:jazzy-desktop-full

ENV ROS_DISTRO=jazzy
RUN apt-get update -y
#Debugging tools
RUN apt-get install -y wget lsb-release curl gnupg net-tools inetutils-ping build-essential qterminal
#Gazebo Install
RUN curl https://packages.osrfoundation.org/gazebo.gpg --output /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
RUN apt-get update -y
RUN apt-get install -y nano \
    libgz-sim8-dev \
    rapidjson-dev \
    libopencv-dev \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-libav \
    gstreamer1.0-gl \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly 

RUN apt-get install -y \
    ros-${ROS_DISTRO}-xacro \
    ros-${ROS_DISTRO}-gazebo-msgs \
    ros-${ROS_DISTRO}-ros-gz


ENV workspace=/home/gz-workspace/ardupilot_gazebo
WORKDIR ${workspace}/
#Burak: Copy ardupilot_gazebo files from local to the image.
# I didn't do git pull because this is working right now. 
# I don't want to pull where github/ardupilot_gazebo might push breaking changes and this sdk would stop working in the next build.
COPY ./ardupilot_gazebo ${workspace}/
COPY --link --from=git.spirirobotics.com/spiri/gazebo-resources:main /models /${workspace}/models/
COPY --link --from=git.spirirobotics.com/spiri/gazebo-resources:main /worlds /${workspace}/worlds/
RUN echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
RUN echo "export GZ_SIM_SYSTEM_PLUGIN_PATH=${workspace}/build:$GZ_SIM_SYSTEM_PLUGIN_PATH" >> ~/.bashrc
RUN echo "export GZ_SIM_RESOURCE_PATH=${workspace}/models:${workspace}/worlds:$GZ_SIM_RESOURCE_PATH" >> ~/.bashrc
ENV GZ_SIM_SYSTEM_PLUGIN_PATH=${workspace}/build
ENV GZ_SIM_RESOURCE_PATH=${workspace}/models:/home/gz-workspace/ardupilot_gazebo/worlds

WORKDIR ${workspace}/build
RUN cmake ..
RUN make -j16
RUN make install
WORKDIR ${workspace}

COPY ./spawn_drones.sh /spawn_drones.sh
RUN chmod +x /spawn_drones.sh
COPY ./launcher.py /launcher.py
CMD python3 /launcher.py



