Objective
Improve Snapcraft behaviors when network connectivity is unavailable, either purposefully (airplane mode) or accidentally (temporary network outage).
Background
Network is required for Snapcraft to function for several components:
-
snap store (info, download, install)
-
apt (cache update, download, install)
-
network connectivity checks (starting container/VM instance)
-
lxd, multipass (namely to launch new container/VM)
-
plugin-specific tooling (such as npm, pip, go get)
-
remote-build
Proposed Changes
Add a new parameter --offline
to Snapcraft to instruct Snapcraft to avoid network connectivity in situations where it may not be required.
The following sections describe these changes in behavior in more detail.
Provided Environments
Startup Behaviors: Network Connectivity
When launching an LXD container, Snapcraft performs a network connectivity check.
- If
--offline
is used, Snapcraft shall skip this network connectivity check.
Startup Behaviors: Snapcraft Updates
When launching a build environment, Snapcraft ensures the Snapcraft in the environment is up-to-date.
- If
--offline
is used, Snapcraft shall not attempt to update Snapcraft snap or its dependencies.
Apt Support
Apt Cache
Upon launching the build environment, Snapcraft may update the apt cache to ensure it is up to date.
-
If
--offline
is used, Snapcraft shall skip this update and warn accordingly. -
The stage package cache shall be updated to use the host’s apt state such that the stage cache does not have to be updated independently.
Stage Packages
Stage packages and their versions are determined on every run of Snapcraft.
- If
--offline
is used, Snapcraft shall unpack previously fetched stage-packages, erroring if the configured set ofstage-packages
has changed.
Build Packages
Build packages and their versions are determined on every run of Snapcraft.
- If
--offline
is used, Snapcraft shall error only if the requested build-packages are not installed. The installed version shall be ignored.
Snaps
Stage Snaps
Stage snaps and their versions are determined on every run of Snapcraft.
- If
--offline
is used, Snapcraft shall unpack previously fetched stage snaps, erroring if the configured set ofstage-snaps
has changed.
Build Snaps
Build snaps and their versions are determined on every run of Snapcraft.
- If
--offline
is used, Snapcraft shall error only if the requested snap is not installed. The installed revision/channel shall be ignored.
Lifecycle Management
Automatic Part Cleaning
Snapcraft may automatically clean parts that have dependencies that changed (new sources, rebuilt, etc.).
- If
--offline
is used, Snapcraft will skip the clean step for these parts but warn accordingly. This allows the part to maintain its previously fetched stage snaps, packages, and sources.
Reducing Network Accesses
Snapd API usage
Snapcraft uses Snapd’s /v2/find API which incurs a network access to the Snap Store. Some of these calls can be replaced with /v2/snaps API to limit the query to installed snaps.
Additionally, some /v2/find calls are redundant and may be consolidated.
Out of Scope
Future work will consider:
- plugin behaviors
- enabling usage of snapshots for LXD, etc.