How to cache snaps in Travis?

Hey folks,

We use a snap in our Travis build, and I was wondering if there’s a path that I could ask Travis to save/restore (as an arbitrary directory cache) that snapd would look in before downloading a snap?

Thanks!

1 Like

Travis docs say that if it’s download time that you’re trying to save, it’s probably not worth it :slight_smile:

There is .cache/snapcraft and .local/share/snapcraft that you could try… And I’m gonna shut up now since I don’t actually know :slight_smile:

Yep, we may decide against doing it if it doesn’t give us results, but I suspect that the wording in the Travis docs may not be entirely true because it’s in Travis’ interests to not store 300MB of stuff for everyone. :wink:

I would expect these to only help with snapcraft operation? (In this case, we’re installing the lxd snap.)

Can I just me2 this question – I would love to be able to speed up my tests by caching the fatter snaps locally.

There isn’t such a path that “just works” today, but could you do something like:

$ cd some-dir
$ snap download some-snap --filename=expected-name.snap
$ snap ack expected-name.assert
$ snap install expected-name.snap

and cache on some-dir ?

You’d have to manage updates to all the snaps, though…

Caching /var/lib/snapd would probably work, or at least parts of it…

wouldn’t this just be snap download snap1 && snap download snap2 for all the snaps you care about?

Would have to check whether you have it already yet? I believe snap download… doesn’t look before overwriting.

That’s not entirely true. The logic is a bit complicated, but essentially the logic becomes much simpler if you use the --basename= argument I mentioned above (originally I put --filename and that was a typo, my apologies). If the filename is set, snap download will first check if the revision specified in the assertion you have downloaded in the .assert is the same as what’s in the store for the specified channel (i.e. latest/stable if --channel is omitted). If the revision in the .assert file is the same as what the store says then it won’t download anything.

I stand corrected, wonder why that isn’t the default behaviour without --basename=