This repository provides a way to run the MRS UAV System in a Apptainer container. Apptainer allows you, an average user, to use our system without installing it into your system and thus cluttering your OS with our software. Moreover, the following benefits arise when using Apptainer containers:
Why Apptainer and not just Docker?
$HOME
mounted into the container if needed (NOT on by default).$HOME
mounted, the programs running inside the container can use your host's computer config files.MRS Apptainer will run on the following operating systems
build script | description |
---|---|
recipes/stable_from_docker/build.sh | installs the latest Docker Image |
recipes/stable_from_apt/build.sh | installs directly from the stable PPA |
wrapper.sh
(.gitignored). It will allow you to configure the wrapper for yourself. When copying the example_wrapper.sh
outside of the mrs_apptainer
folder, the MRS_APPTAINER_PATH
variable within the script needs to be pointed to the correct location of the repository../wrapper.sh
Now, you should see the terminal prompt of the apptainer container, similar to this:
[MRS Apptainer] user@hostname:~$
You can test whether the MRS UAV System is operational by starting the example Gazebo simulation session.
[MRS Apptainer] user@hostname:~$ roscd mrs_uav_gazebo_simulation/tmux/one_drone
[MRS Apptainer] user@hostname:~$ ./start.sh
<mrs_apptainer>/user_ros_workspace/src
folder of this repository.
As an example, let's clone the mrs_core_examples.
cd user_ros_workspace/src
git clone https://github.com/ctu-mrs/mrs_core_examples.git
This host's computer folder is mounted into the container as ~/user_ros_workspace
.
You can then run the apptainer container, init the workspace, and build the packages by:
./wrapper.sh
[MRS Apptainer]$ cd ~/user_ros_workspace/
[MRS Apptainer]$ catkin init
[MRS Apptainer]$ catkin build
Although the workspace resides on your host computer, the software cannot be run by the host system. The container fulfills the dependencies. To start the software, do so from within the container:
[MRS Apptainer] user@hostname:~$ cd ~/user_ros_workspace/src/mrs_core_examples/cpp/waypoint_flier/tmux
[MRS Apptainer] user@hostname:~$ ./start.sh
Feel free to change the recipe to your needs and install additional software:
You can select whether you want to bootstrap form a fresh ROS image, or from Tomas's linux setup image:
From: ros:noetic # uncomment for bootstrapping from ROS Noetic image
# From: klaxalk/linux-setup:master # uncomment for bootstrapping from Tomas's linux-setup
You can add additional commands at the and of the %post
section.
For example, add the following code block for installing Visual Studio Code:
# install visual studio code
# takeon from https://code.visualstudio.com/docs/setup/linux
cd /tmp
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg
$HOME
./tmp
is mounted into host's /tmp/apptainer_tmp
..
├── images
├── install
├── mount
├── overlays
├── README.md
├── recipes
├── scripts
├── user_ros_workspace
└── example_wrapper.sh
Edit the parameter (false -> true)
USE_NVIDIA
in the wrapper.sh
script to enable nVidia graphics integration.
Beware, it is not guaranteed to work on all systems.
Typical issues revolve around the version 'GLIBC_2.34' not found
error.
The host's $HOME
directory is not mounted by default.
To mount the host's $HOME
into the container, run the ./wrapper.sh
with CONTAINED=false
.
However, this will make the container's shells to source your shell RC file.
To make the container run with the internal ROS environment, put the following code snippet into your .bashrc
and/or .zshrc
.
<mrs_apptainer>
stands for the path to where you have cloned this repository.
BASH:
if [ -n "$APPTAINER_NAME" ]; then
source <mrs_apptainer>/mount/apptainer_bashrc.sh
fi
ZSH:
if [ -n "$APPTAINER_NAME" ]; then
source <mrs_apptainer>/mount/apptainer_zshrc.sh
fi
There are several ways to alter the provided container.
A persistent overlay is an additional image that is dynamically loaded and attached to the provided container. Using an overlay is the most straightforward way to store changes to the container, e.g., additional installed software and libraries.
OVERLAY=TRUE
inside wrapper.sh
.sudo ./wrapper
to install additional stuff, e.g.:
apt-get install git
Remember not to put stuff in $HOME
.
./wrapper.sh
git
should be installed.Optinally, the overlay can be embedded into the provided image by running ./scripts/embed_overlay.sh. Embedding an overlay might be helpful, e.g., when providing the altered image to a third party.
Although overlays are great, they pose disadvantages: they cannot be versioned, documented, and automated. That can be overcome by bootstrapping the provided image into a new Apptainer image using a custom Apptainer recipe.
PROS:
The preferred way is to bootstrap the existing container into a new container with a custom recipe file. Creating a customized image allows you to be independent on the input container, receive updates and be compatible with the provided container.
CONS:
Building a new container takes longer. Therefore, finding out what you need to do is tedious. However, finding what actions you need to take can be done by using an overlay or modifying the container directly. See the manual down below.
An example recipe, that creates a new image with [Visual Studio Code]() can be found in ./recipes/user_modifications_from_existing_img User modifications can also be added directly by modifying one of the main recipes. However, creating a custom recipe for modifying an already existing image is a more future-proof solution.
If you need to change the container (even removing files), you can do that by following these steps:
TO_SANBOX=true
):
sudo apptainer build --sandbox <final-container-directory> <input-file.sif>
wrapper.sh
:
CONTAINER_NAME="mrs_uav_system/"
./wrapper.sh
while setting these variables withing the script: WRITABLE=true
,.sif
, (./scripts/convert_sandbox.sh, TO_SANBOX=false
):
sudo apptainer build <output-file.sif> <input-container-directory/>
WRITABLE=false
and CONTAINER_NAME="mrs_uav_system.sif"
.If something is behaving strangly, it might be because your $HOME
within the container is somehow corrupted.
The first go-to solution is to clean the container's HOME
and TMP
.
These folders are located in /tmp/apptainer
of your machine.
rm -rf /tmp/apptainer
If you encounter "No loop devices available" problem while running apptainer:
GRUB_CMDLINE_LINUX="max_loop=256"
into /etc/default/grub
and reboot your machine.