Skip to content

Commit

Permalink
Change Dockerfile and add build and run scripts (fix issue space-ros#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
RBinsonB authored and mkhansenbot committed Sep 9, 2024
1 parent 7391144 commit 5c56110
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 48 deletions.
66 changes: 27 additions & 39 deletions lunar_pole_exploration_rover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,60 +48,48 @@ This package and associated plugins and models were developped by [Robin Baran](

## Running the demo <a name="running_demo"></a>
### Building the docker <a name="building_docker"></a>
To build the docker image, go to your ROS2 workspace. Make a spaceros workspace if you don't already have one:
```bash
mkdir -p ~spaceros_ws/src
cd ~spaceros_ws
```
To build the docker image, go to the docker folder and run:

Clone the demos and simulation repos. Checkout both repos to the feature branch `feat/lunar_pole_exploration_rover`:
```bash
cd ~spaceros_ws
git clone [email protected]:RBinsonB/demos.git
git checkout feat/lunar_pole_exploration_rover
cd ~spaceros_ws
git clone [email protected]:RBinsonB/simulation.git
git checkout feat/lunar_pole_exploration_rover
cd docker
./build.sh
```

Build the image:
```bash
cd ~spaceros_ws
docker build -f demos/lunar_pole_exploration_rover/docker/Dockerfile -t lunar_rover_image .
```
The build process will take about 30 minutes, depending on the host computer.


### Running the docker <a name="running_docker"></a>
Run the following command before running the container:
After building the image, you can see the newly-built image by running:

```bash
xhost +local:docker
docker image list
```

Run the container by typing:
The output will look something like this:

```
REPOSITORY TAG IMAGE ID CREATED SIZE
openrobotics/moveit2 latest 6edb2edc9643 10 hours ago 15.5GB
openrobotics/lunar_pole_exploration_rover_demo latest 629b13cf7b74 12 hours ago 7.8GB
nvidia/cudagl 11.4.1-devel-ubuntu20.04 336416dfcbba 1 week ago 5.35GB
```

The new image is named **openrobotics/lunar_pole_exploration_rover_demo:latest**.

There is a run.sh script provided for convenience that will run the spaceros image in a container.

```bash
docker run --rm -it --name lunar_pole_exploration_rover \
--network host \
-e DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
lunar_rover_image
./run.sh
```

If you have gpu
To enable hardware acceleration, use run_gpu.sh (requires a docker install not from snap)*

```bash
docker run --rm -it --name lunar_pole_exploration_rover \
--network host \
--privileged \
--gpus all \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=graphics \
-e DISPLAY=$DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-e XAUTHORITY=$XAUTHORITY \
--mount type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix \
lunar_rover_image
./run_gpu.sh
```



Once the container is running, launch the demo by typing the following command:
```bash
ros2 launch lunar_pole_exploration_rover lunar_pole_exploration_rover.launch.py
Expand Down
83 changes: 74 additions & 9 deletions lunar_pole_exploration_rover/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# VCS_REF - The git revision of the Space ROS source code (no default value).
# VERSION - The version of Space ROS (default: "preview")

FROM openrobotics/moveit2:latest
FROM osrf/space-ros:latest

# Define arguments used in the metadata definition
ARG VCS_REF
Expand All @@ -43,17 +43,76 @@ ENV GZ_VERSION=fortress
# Disable prompting during package installation
ARG DEBIAN_FRONTEND=noninteractive


# 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

# 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

# Install the various build and test tools
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt install -y \
build-essential \
clang-format \
cmake \
git \
libbullet-dev \
python3-colcon-common-extensions \
python3-flake8 \
python3-pip \
python3-pytest-cov \
python3-rosdep \
python3-setuptools \
python3-vcstool \
wget

# Install some pip packages needed for testing
RUN python3 -m pip install -U \
argcomplete \
flake8-blind-except \
flake8-builtins \
flake8-class-newline \
flake8-comprehensions \
flake8-deprecated \
flake8-docstrings \
flake8-import-order \
flake8-quotes \
pytest-repeat \
pytest-rerunfailures \
pytest

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

# Update the ownership of the source files (had to use sudo above to work around
# a possible inherited 'insteadof' from the host that forces use of ssh
RUN sudo chown -R ${USERNAME}:${USERNAME} ${DEMO_DIR}

# Get rosinstall_generator
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

# Install libmongoc for development
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
Expand All @@ -70,28 +129,34 @@ RUN cd mongo-cxx-driver-r3.6.7/build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCM

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

# Copy the "demos" and "simulation" repos into the workspace
COPY demos ./src/demos
COPY simulation ./src/simulation

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"' \
&& /bin/bash -c 'source "${MOVEIT2_DIR}/install/setup.bash"' \
&& rosdep install --from-paths src --ignore-src -r -y --rosdistro ${ROSDISTRO}

# Build the demo
RUN /bin/bash -c 'source ${SPACEROS_DIR}/install/setup.bash && source ${MOVEIT2_DIR}/install/setup.bash \
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

# Add a couple sample GUI apps for testing
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get install -y \
firefox \
glmark2 \
libcanberra-gtk3-0 \
libpci-dev \
xauth \
xterm

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

ORG=openrobotics
IMAGE=lunar_pole_exploration_rover_demo
TAG=latest

VCS_REF=""
VERSION=preview

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

echo ""
echo "##### Building Space ROS Demo Docker Image #####"
echo ""

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

echo ""
echo "##### Done! #####"

8 changes: 8 additions & 0 deletions lunar_pole_exploration_rover/docker/demo_manual_pkgs.repos
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ repositories:
type: git
url: https://github.com/ros-controls/gz_ros2_control.git
version: humble
demos:
type: git
url: https://github.com/RBinsonB/demos.git
version: feat/lunar_pole_exploration_rover
simulation:
type: git
url: https://github.com/RBinsonB/simulation.git
version: feat/lunar_pole_exploration_rover
qt_gui_core:
type: git
url: https://github.com/ros-visualization/qt_gui_core.git
Expand Down
16 changes: 16 additions & 0 deletions lunar_pole_exploration_rover/docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Runs a docker container with the image created by build.bash
# Requires:
# docker
# an X server

IMG_NAME=openrobotics/lunar_pole_exploration_rover_demo

# Replace `/` with `_` to comply with docker container naming
# And append `_runtime`
CONTAINER_NAME="$(tr '/' '_' <<< "$IMG_NAME")"

# Start the container
docker run --rm -it --name $CONTAINER_NAME --network host \
-e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 $IMG_NAME
28 changes: 28 additions & 0 deletions lunar_pole_exploration_rover/docker/run_gpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Runs a docker container with the image created by build.bash
# Requires:
# docker
# an X server

IMG_NAME=openrobotics/lunar_pole_exploration_rover_demo

xhost +local:docker

# Replace `/` with `_` to comply with docker container naming
# And append `_runtime`
CONTAINER_NAME="$(tr '/' '_' <<< "$IMG_NAME")"

# Start the container
docker run --rm -it --name $CONTAINER_NAME \
--network host \
--privileged \
--gpus all \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=graphics \
-e DISPLAY=$DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-e XAUTHORITY=$XAUTHORITY \
--mount type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix \
$IMG_NAME

0 comments on commit 5c56110

Please sign in to comment.