Update persistent LXD containers

Context

Exporting SNAPCRAFT_CONTAINER_BUILDS=1 in the environment enables persistent LXD containers. Snapcraft will pull, build and clean within a container.

Problem

snapcraft update, used to refresh the parts list, is not aware of containers.
Further more, with a LXD container, new packages won’t be installed because apt-get update is called without apt-get upgrade.

Proposal

  • Run snapcraft update in the container
  • Run apt-get update, apt-get upgrade and snap refresh as part of update - this would be similar to how the clean command without arguments deletes the container
  • Stop running apt-get update with all other commands

I proposed a PR implementing the proposal.

The snapcraft update operation is currently described as:

Usage: snapcraft update [OPTIONS]

Updates the parts listing from the cloud.

This is an innocent looking operation, perhaps inspired by “apt-get update” which is mainly a metadata fetching operation. It doesn’t even feel like being aware of containers is something relevant for it. The behavior being proposed on the other hand is more aggressive, and could lead to a snap that doesn’t build anymore because things are changing under it.

Given that it runs “snap refresh”, perhaps “snapcraft refresh” would be the right term for it?

I’m also curious about that first point:

Is there a topic I could read more about the end user experience intended? We already have cleanbuild which builds on a LXD container, so now we have two different ways to do that. Is that a migration towards something else, or do we need to consider where we intend to be eventually?

Right. It’s a work-in-progress that will be exposed in the CLI soon rather than hidden behind an environment variable. Unlike cleanbuild the workflow will be much closer to a native build where you don’t have to re-create containers all the time and running snapcraft commands becomes very fast. See the original proposal.

In this context that’s not true. Once you’re re-using an existing container your parts list may be outdated, and packages installed in the container can be out of date, both of which can prevent you from building your snap.