Pushing the snapcraft on host into the container

There are three scenarios here where snapcraft can run from:

  • VCS/source checkout
  • debian package from the archive
  • snap

For all of these, when doing a container build we apt install snapcraft. This of course leads to version skew when running as a user and a hard to test system when working as a developer.

To solve this, we need to get the snapcraft on the host system being run onto the container. Let’s explore these scenarios.

From VCS

  • Detect we are running from a git checkout.
  • Push the files under VCS control to the container.
  • apt install the deb packages defined in our HACKING.md
  • Install python3/pip onto the container.
  • pip install --user -r requirements.txt
  • run snapcraft using the vcs binary.

From snap

  • Detect we are running from a snap.
  • Install the squash fuse tools.
  • Query snapd for the corresponding assertion for our revision.
  • Push the snap and assertion onto the container.
  • run snapcraft :arrow_right: /snap/bin/snapcraft

From the deb

This is the least important one as it generally provides minimal version skew.

  • Detect we are running from a deb.
  • Generate a file listing from information on /var/lib/dpkg
  • Retrieve Depends from the control file.
  • Install the Depends on the container.
  • Copy the snapcraft files that were generated.
  • run snapcraft
3 Likes

I opened a pull request for injecting the snapcraft and core snaps into the LXD container.

1 Like

thanks for working on this.

For anyone following this topic: the branch was merged! No more surprise differences in behavior when using the Snapcraft snap to build in a container.

1 Like