Shipping a zip file or tarball of your app makes it easy for users to get started without the heavy lifting of you independently packaging for each Linux distribution. However, this still requires that you provide instructions on installing your app’s dependencies. It requires that you come up with your own method for notifying users of available updates.
Snaps address these gaps while building upon the work you’ve already done to produce a release of your app.
What benefits to snaps bring to pre-built apps?
- Snaps are easy to discover and install. Millions of users can browse and install snaps graphically in the Snap Store or from the command-line.
- Snaps install and run the same across Linux. They bundle your app’s exact versioned dependencies.
- Snaps automatically update to the latest version. Four times a day, users’ systems will check for new versions and upgrade in the background.
- Upgrades are not disruptive. Because upgrades are not in-place, users can keep your app open as it’s upgraded in the background.
- Upgrades are safe. If your app fails to upgrade, users automatically roll back to the previous revision.
Do you have twenty minutes to get started?
Ready to get started? By the end of this guide you’ll understand how to make a snap of your pre-built app that can be published in the Snap Store, showcasing it to millions of Linux users.
Snaps are defined in a single YAML file placed in the root of your project. The geekbench example shows the entire snapcraft.yaml file for an existing project. Don’t worry, we’ll break this down.
name: geekbench4 version: 4.2.0 summary: Cross-Platform Benchmark description: > Geekbench 4 measures your system's power and tells you whether your computer is ready to roar. How strong is your mobile device or desktop computer? How will it perform when push comes to crunch? These are the questions that Geekbench can answer. confinement: devmode parts: geekbench4: plugin: dump source: http://cdn.geekbench.com/Geekbench-$SNAPCRAFT_PROJECT_VERSION-Linux.tar.gz apps: geekbench4: command: geekbench4
snapcraft.yaml file 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.
name: geekbench4 version: 4.2.0 summary: Cross-Platform Benchmark description: > Geekbench 4 measures your system's power and tells you whether your computer is ready to roar. How strong is your mobile device or desktop computer? How will it perform when push comes to crunch? These are the questions that Geekbench can answer.
name must be unique in the Snap Store. Valid snap names consist of lower-case alphanumeric characters and hyphens. They cannot be all numbers. They also cannot start or end with a hyphen.
summary can not exceed 79 characters. You can use a chevron ‘>’ in the
description key to declare a multi-line description.
The next section describes the level of confinement applied to your app.
Snaps are containerised to ensure more predictable application behaviour and greater security. Unlike other container systems, the shape of this confinement can be changed through a set of interfaces. These are declarations that tell the system to give permission for a specific task, such as accessing a webcam or binding to a network port.
It’s best to start a snap with the confinement in warning mode, rather than strictly applied. This is indicated through the
devmode keyword. When a snap is in devmode, runtime confinement violations will be allowed but reported. These can be reviewed by running
Because devmode is only intended for development, snaps must be set to strict confinement before they can be published as “stable” in the Snap Store. Once an app is working well in devmode, you can review confinement violations, add appropriate interfaces, and switch to strict confinement.
Parts define what sources are needed to assemble your app. Parts can be anything: programs, libraries, or other needed assets. We’ll deal with libraries and other assets later, so for now we just have one part: a tarball containing the geekbench binary.
parts: geekbench4: plugin: dump source: http://cdn.geekbench.com/Geekbench-$SNAPCRAFT_PROJECT_VERSION-Linux.tar.gz
dump plugin unpacks the file specified in the
source field and includes the contents in the snap. The source can be a local or remote zip file, deb file, or tarball.
In this example we use the
$SNAPCRAFT_PROJECT_VERSION variable derived from the
version: stanza in the metadata section to reference the release tarball.
Apps are the commands you want to expose to users and any background services your application provides. Each key under
apps is the command name that should be made available on users’ systems.
command specifies the path to the binary to be run. This is resolved relative to the root of your snap contents and automatically searches in the
bin subdirectories of your snap.
apps: geekbench4: command: geekbench4
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
geekbench4.command-name, for example). This is to avoid conflicting with apps defined by other installed snaps.
You can request an alias on the Snapcraft forum if your command name and snap name do not match but you don’t want your command prefixed. These aliases are set up automatically when your snap is installed from the Snap Store.
That’s it. You now have a snapcraft.yaml file which describes how the core of your app is assembled, presented, and run.
Continue on to learn how you can bundle your app’s dependencies, such as system libraries, into this snap so your app is portable across Linux distributions.
Last updated a month ago. Help improve this document in the forum.