Snapcraft builds on top of the
catkin tool, familiar to any ROS1 developer, to create snaps for people to install on Linux.
ROS itself is distributed via Open Robotics’ own Debian archive, along with many community-supported tools. It’s possible to get your own application into their archive as well, but it requires that the application is open-source. You’re also left with the question of how to update ROS and your application on a robotic platform that has already been shipped. With snapcraft it’s just one command to bundle a specific ROS version along with your application into a snap that works anywhere and can be automatically updated.
Here are some snap advantages that will benefit many ROS projects:
Let’s take a look at the talker and listener out of the ROS tutorials, and show how simple that system is to snap.
Snaps are defined in a single yaml file placed in the root of your project. Here is the entire
snapcraft.yaml for this project. Let’s break it down.
name: ros-talker-listener base: core18 version: "0.1" summary: ROS Talker/Listener Example description: | This example requires roscore as well as a talker and listener. grade: devel confinement: devmode parts: ros-tutorials: # The catkin plugin will use Melodic for core18-based snaps plugin: catkin source: https://github.com/ros/ros_tutorials.git source-branch: melodic-devel source-space: roscpp_tutorials/ apps: run: command: roslaunch roscpp_tutorials talker_listener.launch
snapcraft.yaml starts with a small amount of human-readable metadata, which usually can be lifted from the GitHub description or project README.md. This data is used in the presentation of your app in the Snap Store. The
summary: can not exceed 79 characters. You can use a pipe in the
description: key to declare a multi-line description. The
base here is the name of the base snap that makes up the execution environment for this snap (
core18 is based on Ubuntu 18.04, Bionic).
name: ros-talker-listener base: core18 version: "0.1" summary: ROS Talker/Listener Example description: | This example requires roscore as well as a talker and listener.
To get started we won’t confine this application. Unconfined applications, specified with
devmode, can only be released to the “edge” channel where you and other developers can install them.
Parts define how to build your app. Parts can be anything: programs, libraries, or other assets needed to create and run your application. In this case we have one: ros-tutorials. Parts can point to local directories, remote git repositories, or tarballs.
The Catkin plugin will bundle
roscore in the snap. It will also use
rosdep to determine the dependencies of the Catkin packages in the workspace, download them from the ROS archive, and unpack them into the snap. Finally, it will build the packages.
Important note: Most ROS1 developers run out of the
devel space. As a result, it’s easy to forget the importance of good install rules, i.e. rules for installing every component of the package necessary to run, or every component necessary to use a given library. The Catkin packages you’re building must have good install rules, or the snapcraft CLI won’t know which components to place into the snap. Make sure you install binaries, libraries, header files, launch files, etc.
parts: ros-tutorials: # The catkin plugin will use Melodic for core18-based snaps plugin: catkin source: https://github.com/ros/ros_tutorials.git source-branch: melodic-devel source-space: roscpp_tutorials/
Apps are the commands and services exposed to end users. If your command name matches the snap
name, users will be able run the command directly. If the names differ, then apps are prefixed with the snap
ros-talker-listener.command-name, for example). This is to avoid conflicting with apps defined by other installed snaps.
If you don’t want your command prefixed you can request an alias for it on the snapcraft forum. These are set up automatically when your snap is installed from the Snap Store.
Here we simply run a launch file that brings up roscore along with the talker and listener.
apps: run: command: roslaunch roscpp_tutorials talker_listener.launch
If your application is intended to run as a service you simply add the line
daemon: simple after the command keyword. This will automatically keep the service running on install, update, and reboot.
You’ll first need to install snap support, and then install the snapcraft tool:
sudo snap install snapcraft --classic
If you have just installed snap support, start a new shell so your
PATH is updated to include
/snap/bin. You can then build this example yourself:
git clone https://github.com/snapcraft-docs/ros-talker-listener cd ros-talker-listener snapcraft
The resulting snap can be installed locally. This requires the
--dangerous flag because the snap is not signed by the Snap Store. The
--devmode flag acknowledges that you are installing an unconfined application:
sudo snap install ros-talker-listener_*.snap --devmode --dangerous
You can then try it out:
$ ros-talker-listener.run <snip> SUMMARY ======== PARAMETERS * /rosdistro: kinetic * /rosversion: 1.12.7 NODES / listener (roscpp_tutorials/listener) talker (roscpp_tutorials/talker) auto-starting new master process[master]: started with pid  ROS_MASTER_URI=http://localhost:11311 setting /run_id to a2132f48-a959-11e7-a19a-346895ed0f23 process[rosout-1]: started with pid  started core service [/rosout] process[listener-2]: started with pid  process[talker-3]: started with pid  [ INFO] [1507158810.260508402]: hello world 0 [ INFO] [1507158810.360553002]: hello world 1 [ INFO] [1507158810.460584229]: hello world 2 [ INFO] [1507158810.460985451]: I heard: [hello world 2] [ INFO] [1507158810.560586692]: hello world 3 [ INFO] [1507158810.560894817]: I heard: [hello world 3] [ INFO] [1507158810.660587011]: hello world 4
Removing the snap is simple too:
sudo snap remove ros-talker-listener
To share your snaps you need to publish them in the Snap Store. First, create an account on the dashboard. Here you can customize how your snaps are presented, review your uploads and control publishing.
You’ll need to choose a unique “developer namespace” as part of the account creation process. This name will be visible by users and associated with your published snaps.
Make sure the
snapcraft command is authenticated using the email address attached to your Snap Store account:
You can publish your own version of a snap, provided you do so under a name you have rights to. You can register a name on dashboard.snapcraft.io, or by running the following command:
snapcraft register myrossnap
Be sure to update the
name: in your
snapcraft.yaml to match this registered name, then run
Use snapcraft to push the snap to the Snap Store.
snapcraft push --release=edge myrossnap_*.snap
If you’re happy with the result, you can commit the snapcraft.yaml to your GitHub repo and turn on automatic builds so any further commits automatically get released to edge, without requiring you to manually build locally.
Here are all the Catkin plugin-specific keywords:
- catkin-packages: (list of strings) List of catkin packages to build. If not specified, all packages in the workspace will be built. If set to an empty list (), no packages will be built. - source-space: (string) The source space containing Catkin packages. By default this is 'src'. - include-roscore: (boolean) Whether or not to include roscore with the part. Defaults to true. - rosinstall-files: (list of strings) List of rosinstall files to merge while pulling. Paths are relative to the source. - recursive-rosinstall: (boolean) Whether or not to recursively merge/update rosinstall files from fetched sources. Will continue until all rosinstall files have been merged. Defaults to false. - catkin-cmake-args: (list of strings) Configure flags to pass onto the cmake invocation from catkin. - underlay: (object) Used to inform Snapcraft that this snap isn't standalone, and is actually overlaying a workspace from another snap via content sharing. Made up of two properties: - build-path: (string) Build-time path to existing workspace to underlay the one being built, for example '$SNAPCRAFT_STAGE/opt/ros/kinetic'. - run-path: (string) Run-time path of the underlay workspace (e.g. a subdirectory of the content interface's 'target' attribute.) - catkin-ros-master-uri: (string) The URI to ros master setting the env variable ROS_MASTER_URI. Defaults to http://localhost:11311.
You can view them locally by running:
snapcraft help catkin
You can extend the behaviour of any part in your
snapcraft.yaml with shell commands. These can be run instead of any given step in the lifecycle of the part. For example, you can run shell commands instead of the
pull step by using
override-pull. Similarly, you can use
override-build to run shell commands instead of the build process, and the pattern continues for the other steps.
For example, while the
ros_tutorials have proper install rules, say you were creating a snap of an upstream ROS application that didn’t, and you wanted a launch file out of it. You could make use of the
override-build keyword to get around the lack of install rules:
parts: ros-tutorials: source: https://url/to/bad/workspace plugin: catkin override-build: | # Run the default build step first snapcraftctl build # Now install the launch file mkdir -p "$SNAPCRAFT_PART_INSTALL/opt/ros/kinetic/share/no_install_rules" cp -r no_install_rules/launch "$SNAPCRAFT_PART_INSTALL/opt/ros/kinetic/share/no_install_rules/"