Packaging Apps To Run on Any Linux Device

It's a Snap!

Innards

The Snapcraft docs [8] explain some of the intricacies of which files do what inside a typical snap (not at the pre-build stage). Figure 2 shows the key files involved. It's important not to confuse the snap.yaml and snapcraft.yaml files. The latter is used before the snap is compiled (i.e., the pre-build stage I mentioned before). The main file I'll look at is the snapcraft.yaml file. To whet your appetite, Listing 1 is a snippet from such a file, with some pertinent comments.

Listing 1

A Sample snapcraft.yaml File

---
name: Echo a name
version: "1.0" # I'm a string not a number, so put me in quotes
apps:
    echo-chrisbinnie:
        command: bin/echo # Note I drop the prepended slash to make it work inside a snap
Figure 2: The key files inside a snap (source: The snap format [9]).

In this basic example, you can see that this snippet is just "echoing" a string. Note that I'm intentionally using the relative path and not the usual absolute path, /usr/bin/host.

Getting Your Hands Dirty

Now that I've touched on the basics, I'll create a snap that does something useful. All the major distributions support snapd, from Arch Linux, Fedora, Gentoo, and openSUSE to OpenWrt and OpenEmbedded/Yocto, not to mention the obvious Debian and Ubuntu distributions.

I'll focus on my Linux Mint Debian laptop for convenience. To add the snapd package, I use the oh-so-arduous command (which might not even be necessary on some of the newer Ubuntu versions; I've read it's built in from 16.04 onward):

$ sudo apt install snapd

Snaps are usually pulled from the Snap Store [10], which is comparable to the Docker Hub. To get going, it's a case of searching for your snap. Again, this process isn't too dissimilar to using the Docker Hub. You'll find a lot of pre-built snaps to work with.

Shopping

If you don't have an Ubuntu One account, simply sign up. You'll also be shown the way to add your own snaps to the Snap Store once you've logged in. The marketing blurb includes the promise of getting your snap published within minutes and being able to reach millions of devices through the Snap Store.

Next, you will want to log in to the Snap Store:

$ snap login chris@binnie.tld

You should see a Login successful message.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Container Apps
    Canonical’s Snapcraft (Snappy) package manager creates self-contained applications that work across Linux distributions. We show you how to install, publish, and run a simple snap.
comments powered by Disqus