How to do "snap try" when building using multipass?

My current understanding of the workflow of creating snaps using snapcraft 3.x is to (transparently) use multipass to do the entire build process on a VM. snapcraft drops the resulting snap in your project directory and you can install it.

How about the snap try feature that was illustrated in the Create your first snap walkthrough?

snap try requires access to the prime directory which is now on a separate machine. Am I missing something or is there a slick trick that I don’t know about or is snap try not currently usable when running snapcraft using multipass?

Thank you!

3 Likes

I was wondering the same, and tried the following with success:

  1. Build your snap with multipass, resulting in a my-snap-name_version_arch.snap file
  2. Execute unsquashfs <my-snap-name_version_arch>.snap to unpack your snap to a new subdirectory named squashfs-root (use -d prime to unpack your snap to a directory prime)
  3. Run snap try squashfs-root (or just snap try if you unpacked to prime)

Happy snap trying :slight_smile:

You should be able to use multipass mount to access /root/prime inside the multipass vm. Not sure if it’ll work all the way though (keep us posted!)

Note mounts only work the other way around, so you’d need to multipass mount prime snapcraft-<snap>:/root/prime before the priming process.

1 Like

I wonder why is multipass build environment not build in-place in the projectdir in the first place?

@Lin-Buo-Ren because that would be a lot of unnecessary traffic between your host and the instance. You rarely need all the intermediate build artifacts, most often you need the resulting .snap file, and so only the source is mounted into the instance. I know it’s on the roadmap to bring back the snap try capability in some way.

1 Like