10

I am working on a snap of a bigger piece of software and building the snap, removing the old one, installing the new one just takes a very long time.

I would like to iterate over creating the snap and testing things out more quickly. I know that the snap builds just fine, now I'm interested in testing things like launching the app and its integration. Is there a way to do this?

1 Answer 1

8

Preface

One way to go about this is to use snap try. From its --help message:

The try command installs an unpacked snap into the system for testing
purposes. The unpacked snap content continues to be used even after 
installation, so non-metadata changes there go live instantly. Metadata
changes such as those performed in snap.yaml will require reinstallation 
to go live.

It also comes with an option:

--devmode     Install in development mode and disable confinement

This is particularly helpful if you want to test confinement bits and getting the use of interfaces right.

Usage

The way to use this is simple, just run:

snapcraft prime
snap try prime/

In the first step you tell snapcraft to do the

Final copy and preparation for the snap.

And in the second step snapd makes use of the contents of the directory to "install" the snap. Now you can play around with the package while still being able to make changes to it.

Example

Let's use an example from the Snappy Playpen to show how to use this.

We are using consul as it's relatively quick to build and use:

$ git clone https://github.com/ubuntu/snappy-playpen
$ cd snappy-playpen/consul/
snappy-playpen/consul$ snapcraft prime
Preparing to pull consul 
[...]
Staging consul 
Priming consul 
snappy-playpen/consul$ 

Now let's make sure that we don't have another version installed of it and then proceed with the installation.

snappy-playpen/consul$ which consul
snappy-playpen/consul$ snap try prime

Name    Version  Rev  Developer  Notes
consul  0.6.4    x1              try
snappy-playpen/consul$ consul --help
usage: consul [--version] [--help] <command> [<args>]

Available commands are:
    agent          Runs a Consul agent
[...]
snappy-playpen/consul$ 

So far so good. It seems to work just fine. Now let's replace it with /bin/echo just to see how things work:

snappy-playpen/consul$ cp /bin/echo prime/bin/consul 
snappy-playpen/consul$ consul --help
Usage: /snap/consul/x1/bin/consul [SHORT-OPTION]... [STRING]...
   or:  /snap/consul/x1/bin/consul LONG-OPTION
Echo the STRING(s) to standard output.
[...]
daniel@daydream:/tmp/test/snappy-playpen/consul$  

As you can see, we can make changes to the live system in prime while still running things under confinement. This is generally a good way to get the snap up and running and fully tested quickly.

Note: With snapd before 2.0.10 (2016-07-09), you had to temove the snap before running snapcraft clean or snapd would get into a bad state and whine about being unable to find mounted snaps. Some more fixes are lined up for 2.0.11, which should land in a few days as well.

3
  • 1
    You might consider mentioning that the snap should be removed before one runs snapcraft clean or snapd currently gets into a bad state and whines about being unable to find mounted snaps. The fix is in progress for that, but not yet released.
    – kyrofa
    Jul 7, 2016 at 20:05
  • Nice one! Adding the info now.
    – dholbach
    Jul 8, 2016 at 7:27
  • 1
    Yeah, 'snap try' is for exactly this use case. It allows you to make a directory and build your snap in it, without having to keep making the squashfs and remount it. You iterate just by working in that directory (you effectively have a read-write snap) until you are happy, then make the squashfs out of that directory. Jul 8, 2016 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .