Skip to content

Commit

Permalink
Added Dockerfile, build.sh & run.sh scripts (space-ros#46)
Browse files Browse the repository at this point in the history
Signed-off-by: Jasmeet Singh <[email protected]>
  • Loading branch information
jasmeet0915 authored and mkhansenbot committed Sep 9, 2024
1 parent ff97cc1 commit 945e993
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 0 deletions.
108 changes: 108 additions & 0 deletions custom_gz_plugins/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright 2024 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# A Docker configuration script to build the Space ROS image.
#
# The script provides the following build arguments:
#
# VCS_REF - The git revision of the Space ROS source code (no default value).
# VERSION - The version of Space ROS (default: "preview")

FROM osrf/space-ros:latest

# Define arguments used in the metadata definition
ARG VCS_REF
ARG VERSION="preview"

# Specify the docker image metadata
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="Real World Extraterrestrial Simulations"
LABEL org.label-schema.description="Realistic Extraterrestrial Simulations demos using custom GZ plugins & data from NASA PDS"
LABEL org.label-schema.vendor="Open Robotics"
LABEL org.label-schema.version=${VERSION}
LABEL org.label-schema.url="https://github.com/space-ros"
LABEL org.label-schema.vcs-url="https://github.com/space-ros/docker"
LABEL org.label-schema.vcs-ref=${VCS_REF}

# Define a few key variables
ENV DEMO_DIR=${HOME_DIR}/demos_ws
ENV GZ_VERSION=harmonic

# Disable prompting during package installation
ARG DEBIAN_FRONTEND=noninteractive

# Clone all space-ros sources
RUN mkdir ${SPACEROS_DIR}/src \
&& vcs import ${SPACEROS_DIR}/src < ${SPACEROS_DIR}/exact.repos

# Make sure the latest versions of packages are installed
# Using Docker BuildKit cache mounts for /var/cache/apt and /var/lib/apt ensures that
# the cache won't make it into the built image but will be maintained between steps.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get dist-upgrade -y
RUN rosdep update

# Get rosinstall_generator
# Using Docker BuildKit cache mounts for /var/cache/apt and /var/lib/apt ensures that
# the cache won't make it into the built image but will be maintained between steps.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -y && sudo apt-get install -y python3-rosinstall-generator

RUN mkdir -p ${DEMO_DIR}/src
WORKDIR ${DEMO_DIR}

# Install libmongoc for development
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get install libmongoc-dev -y

# Compile mongo cxx driver https://mongocxx.org/mongocxx-v3/installation/linux/
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get install libssl-dev build-essential devscripts debian-keyring fakeroot debhelper cmake libboost-dev libsasl2-dev libicu-dev libzstd-dev doxygen -y
RUN wget https://github.com/mongodb/mongo-cxx-driver/releases/download/r3.6.7/mongo-cxx-driver-r3.6.7.tar.gz
RUN tar -xzf mongo-cxx-driver-r3.6.7.tar.gz
RUN cd mongo-cxx-driver-r3.6.7/build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local && sudo cmake --build . --target EP_mnmlstc_core && cmake --build . && sudo cmake --build . --target install

# Add osrf packages repository and manually install gz sim harmonic dependecies as they haven't been added to the rosdep index as of yet
RUN sudo 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" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
RUN sudo apt-get update && sudo apt-get install -y libgz-math7-dev libgz-transport13-dev libgz-sim8-dev libgz-msgs10-dev libgz-plugin2-dev

# Get the source for the dependencies
COPY --chown=${USERNAME}:${USERNAME} dependencies_source_pkgs.repos /tmp/
RUN vcs import src < /tmp/dependencies_source_pkgs.repos && /bin/bash -c 'source "${SPACEROS_DIR}/install/setup.bash"'

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -y \
&& /bin/bash -c 'source "${SPACEROS_DIR}/install/setup.bash"' \
&& rosdep install --from-paths ${SPACEROS_DIR}/src src --ignore-src -r -y --rosdistro ${ROSDISTRO} --skip-keys "console_bridge generate_parameter_library fastcdr fastrtps rti-connext-dds-5.3.1 urdfdom_headers rmw_connextdds ros_testing rmw_connextdds rmw_fastrtps_cpp rmw_fastrtps_dynamic_cpp composition demo_nodes_py lifecycle rosidl_typesupport_fastrtps_cpp rosidl_typesupport_fastrtps_c ikos diagnostic_aggregator diagnostic_updater joy qt_gui rqt_gui rqt_gui_py"

# Build the demo
RUN /bin/bash -c 'source ${SPACEROS_DIR}/install/setup.bash \
&& colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release'

# Add the user to the render group so that the user can access /dev/dri/renderD128
RUN sudo usermod -aG render $USERNAME

# Setup the entrypoint
COPY ./entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
22 changes: 22 additions & 0 deletions custom_gz_plugins/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

ORG=spaceros
IMAGE=custom_sim_custom_plugins_demo
TAG=latest

VCS_REF=""
VERSION=preview

# Exit script with failure if build fails
set -eo pipefail

echo ""
echo "##### Building Docker Image #####"
echo ""

docker build -t $ORG/$IMAGE:$TAG \
--build-arg VCS_REF="$VCS_REF" \
--build-arg VERSION="$VERSION" .

echo ""
echo "##### Done! #####"
126 changes: 126 additions & 0 deletions custom_gz_plugins/dependencies_source_pkgs.repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
repositories:
demos:
type: git
url: https://github.com/jasmeet0915/demos
version: jasmeet/custom_gz_plugins_pkg
realtime_tools:
type: git
url: https://github.com/ros-controls/realtime_tools.git
version: master
ros2_control:
type: git
url: https://github.com/ros-controls/ros2_control.git
version: humble
ackermann_msgs:
type: git
url: https://github.com/ros-drivers/ackermann_msgs.git
version: ros2
resource_retriever:
type: git
url: https://github.com/ros/resource_retriever.git
version: humble
angles:
type: git
url: https://github.com/ros/angles.git
version: humble-devel
control_toolbox:
type: git
url: https://github.com/ros-controls/control_toolbox.git
version: ros2-master
control_msgs:
type: git
url: https://github.com/ros-controls/control_msgs.git
version: humble
gz_ros2_control:
type: git
url: https://github.com/jasmeet0915/gz_ros2_control.git
version: jasmeet/humble_harmonic_support
backward_ros:
type: git
url: https://github.com/pal-robotics/backward_ros.git
version: foxy-devel
qt_gui_core:
type: git
url: https://github.com/ros-visualization/qt_gui_core.git
version: humble
python_qt_binding:
type: git
url: https://github.com/ros-visualization/python_qt_binding.git
version: humble
ros2_controllers:
type: git
url: https://github.com/tonylitianyu/ros2_controllers.git
version: effort_group_position_controller_2
actuator_msgs:
type: git
url: https://github.com/rudislabs/actuator_msgs.git
version: main
filters:
type: git
url: https://github.com/ros/filters.git
version: ros2
rviz:
type: git
url: https://github.com/ros2/rviz.git
version: humble
ros_gz:
type: git
url: https://github.com/gazebosim/ros_gz.git
version: humble
generate_parameter_library:
type: git
url: https://github.com/PickNikRobotics/generate_parameter_library.git
version: main
joint_state_publisher:
type: git
url: https://github.com/ros/joint_state_publisher.git
version: ros2
rsl:
type: git
url: https://github.com/PickNikRobotics/RSL.git
version: main
cpp_polyfills:
type: git
url: https://github.com/PickNikRobotics/cpp_polyfills.git
version: main
image_transport:
type: git
url: https://github.com/ros-perception/image_common.git
version: humble
interactive_markers:
type: git
url: https://github.com/ros-visualization/interactive_markers.git
version: humble
laser_geometry:
type: git
url: https://github.com/ros-perception/laser_geometry.git
version: humble
simulation:
type: git
url: https://github.com/jasmeet0915/simulation
version: real_data_planet_models
warehouse_ros:
type: git
url: https://github.com/moveit/warehouse_ros.git
version: ros2
ros-humble-warehouse-ros-mongo:
type: git
url: https://github.com/ros-planning/warehouse_ros_mongo.git
version: ros2
vision_msgs:
type: git
url: https://github.com/ros-perception/vision_msgs.git
version: ros2
navigation_msgs:
type: git
url: https://github.com/ros-planning/navigation_msgs.git
version: humble
gps_msgs:
type: git
url: https://github.com/swri-robotics/gps_umd.git
path: gps_msgs
version: 113782d
yaml_cpp_vendor:
type: git
url: https://github.com/ros2/yaml_cpp_vendor.git
version: humble
6 changes: 6 additions & 0 deletions custom_gz_plugins/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

# Setup the Demo environment
source "${SPACEROS_DIR}/install/setup.bash"
exec "$@"
36 changes: 36 additions & 0 deletions custom_gz_plugins/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all")
DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all")

xhost +local:root

ORG=spaceros
IMAGE=custom_sim_custom_plugins_demo
TAG=latest

container_name="space_ros_custom_gz_plugins_demo"

ros_domain_id=$(printenv ROS_DOMAIN_ID)

# Check if a Docker container with "$container_name" is already running.
# If it is running, open an interactive bash shell inside it.
# If the container is not running, create and run a new Docker container with specified configurations
if docker ps --format '{{.Names}}' | grep -q "$container_name"; then
docker exec -it "$container_name" /bin/bash
else
docker run -it --rm \
${DOCKER_ARGS[@]} \
-e DISPLAY=$DISPLAY \
-v $PWD/..:/workspaces/sim_ws/src \
-v /var/run/docker.sock:/var/run/docker.sock \
--name "$container_name" \
--workdir /home/spaceros-user/demos_ws/src \
--env ROS_DOMAIN_ID=$ros_domain_id \
--runtime nvidia \
--network host \
-v /dev/input:/dev/input --device-cgroup-rule='c 13:* rmw' \
$@ \
$ORG/$IMAGE:$TAG \
/bin/bash
fi

0 comments on commit 945e993

Please sign in to comment.