Container Apps

Packaging Apps To Run on Any Linux Device

Finding Nemo

Figure 3 shows a search using the keyword host . This is a command that you’ll be using frequently with snap if you’re pulling in other people’s snaps. Instead of search , as in Docker, the Snap Store uses find  to look for useful snaps.

Figure 3: Searching for a snap with the word "host" in the Name or Summary.

To install one of the newly found packages, just use the install  command. Opting sensibly for the second package from the top, because it’s from Canonical, I use the command:

$ snap install wifi-ap

In the console, you can see the snap output as it installs successfully.

Figure 4: Installing a snap made by Canonical.

Shopping Lists

Another command you’ll need frequently is the list  command, which shows your installed snaps. Figure 5 shows two locally installed snaps: core  and wifi-ap , both created by Canonical.

Figure 5: Running a list command displays local snap information.

A quick glance at what the docs have to say about a Hello World! snap can be found on the Usage  page. I remember when I first saw this, I was surprised to see the output without any prepended command on the host’s command prompt (i.e., no snap  command). I just typed hello  after installing the snap:

$ hello
Hello, world!

The output denotes success.

Remember the wifi-ap  snap? This command has a lot of juicy information, which you can see by entering the info  command (Listing 2). The description  section should be self-explanatory; just below that, a URL points you to the snap’s source code. Also note the options listed under the commands  section, which lists the possible parameters you can send to the snap.

Listing 2: Getting wifi-ap  Snap Information

root@chris:~# snap info wifi-ap
name:      wifi-ap
summary:   "WiFi Access Point based on hostapd"
publisher: canonical
contact:   snappy-canonical-storeaccount@canonical.com
description: |
  This snap is implementing a WiFi access point based on hostapd and allows
  easily to share a internet connection or just create a network others can
  easily connect to.
  
  Please find the source of this snap at:
    https://code.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap
  
commands:
  - wifi-ap.config
  - wifi-ap.setup-wizard
  - wifi-ap.status
tracking:    stable
installed:   15 (146) 31MB -
refreshed:   2017-05-05 16:20:19 +0000 UTC
channels:                 
  stable:    15     (146) 31MB -
  candidate: 15     (146) 31MB -
  beta:      16     (186) 31MB -
  edge:      17-dev (194) 31MB -

If you follow the source link to the Ubuntu Launchpad site, navigate to the Get this  repository  section, and then run the git clone  command with the -b  (branch) switch (Listing 3), you can download the latest source. If you then enter the wifi-ap  directory, you can see, among all the small files, the all-important snapcraft.yaml  file.

Listing 3: Getting the Latest wifi-ap  Source Code

root@chris:~# git clone -b master https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap
Cloning into 'wifi-ap'...
remote: Counting objects: 2220, done.
remote: Compressing objects: 100% (1903/1903), done.
remote: Total 2220 (delta 882), reused 955 (delta 182)
Receiving objects: 100% (2220/2220), 2.71 MiB | 0 bytes/s, done.
Resolving deltas: 100% (882/882), done.
Checking connectivity... done.

Snap, Crackle, and Pop

Now I’ll look at how you can create your own very basic snap. In this example, you just want to perform a super-simple echo  command of whatever input (STDIN) is typed. To develop your own snaps, you need to install the snapcraft  package:

$ apt install snapcraft

After a little more than 8MB of files are installed, youcan start creating a snap with an init  command (Figure 6), which pulls in a template.

Figure 6: Some helpful output from the friendly, neighborhood init function.

Because I’ve already run hello  and wifi-ap , those snaps are in the snap/  directory, along with the snapcraft.yaml  file:

root@chris:~# ls snap/
core  hello  snapcraft.yaml  wifi-ap

Listing 4 shows the intuitive and easy-to-follow template file.

Listing 4: A snapcraft.yaml  Template File

root@chris:~# ls snap/
core  hello  snapcraft.yaml  wifi-ap
 
name: my-snap-name # you probably want to 'snapcraft register <name>'
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.
 
grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
 
parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: nil

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

comments powered by Disqus