Reuse packages between builds

When Snapcraft downloads packages while it builds a snap, it doesn’t store them persistently. On subsequent builds that rely on those same packages, on any project, Snapcraft will download them again, costing time and bandwidth.

By setting up a cache, your packages will be reused across all snap builds. For an example of the performance gain that a cache provides, the ROS2 Talker/Listener snap packs 52% faster with a cache than without.

Requirements

There are multiple ways to set up a package cache, depending on your deployment and network and storage needs. What follows is a cache for all HTTP traffic that requires:

  • A local Linux host

  • LXD as the build provider

Set up the proxy

If you’re on a host that has never run Snapcraft before, start by packing a snap to create the LXD image:

snapcraft pack

Create a new Ubuntu 24.04 container instance for the proxy, reusing the Snapcraft namespace in LXD.

lxc launch ubuntu:24.04 package-cache --project snapcraft

Install and configure the proxy