Need both core _and_ core18 base snaps - possible to rationalize?

We deploy and run applications via the snap ecosystem on a number of Raspberry Pis. The underlying OS on these is Raspbian/Debian rather than Ubuntu Core, and this will probably not change in the near future.

For the snaps to run, we’ve found that both the core and core18 base snaps need to be installed. This is because:

  1. core18 is set as the base in our snapcraft.yaml, since the code requires Python 3.6 (rather than 3.5, which is what core provides).
  2. The core snap needs to be installed, since this provides all the actual interfaces (core18 does not). Without a core snap, interfaces like network-bind don’t exist on the system at all - and any attempt by the application snap to bind to a port correspondingly fails.

I feel like issue #2 was discussed elsewhere some time ago, though I can’t find it right now. In any case, the symptoms look like this:

$ sudo snap connect <snap-name>:network-bind
error: cannot resolve connection, slot snap name is empty

And running snap interfaces only shows plugs on the snap side, and no slots on the system side.

My question is as follows: is there any way to avoid installing both the core and core18 snaps?
Perhaps there is another snap (besides core) that can provide the interfaces/slots? It just seems somewhat inelegant and duplicative to require both base snaps. And on a practical level, it means that updates for both base snaps are being downloaded during refresh, which ends up eating up bandwidth in a constrained environment.

Thanks in advance for any suggestions!

this should not be necessary anymore …

https://bugs.launchpad.net/snapd/+bug/1819318

has been fixed last summer …
did you test this behaviour recently (perhaps it regressed again and the bug needs to be re-opened)?

I have seen this recently too, I’m sure of it. But I don’t recall how I got into that situation and just figured that bug wasn’t fixed yet.

Yes, tried this (again) today, thinking that things may have evolved since last time. The bug - specifically, lack of interfaces on core18 - still appears to be there

I don’t know anything about (2), but:

Have you considered building whatever version of python you need in your snap? You don’t need to limit yourself to the one available in the base snap.

Yes there is, using the snapd snap. However, in order to use the snapd snap (and only the snapd snap), on a classic distro your OS needs to meet these 3 conditions:

  1. the version of snapd packaged by your distro needs to be new enough to support switching to use the snapd snap, I can confirm that 2.40 is at least new enough, I don’t know what version you may have in the Raspbian archive
  2. your distro needs to support re-exec (and thus using the version of snapd from a snap rather than from a traditional package like a deb or rpm) - Debian derivatives are good here
  3. You need to never have installed any snaps before. This is because today, as soon as the core snap is installed, it is forever unremovable. If you have installed snaps, you could reset snapd state by removing all snaps, and then purging the package from your machine, then reinstall the snapd distro package and install the snapd snap first before anything else.

So if you meet all those requirements, just install the snapd snap with snap install snapd and then you should see you only have the snapd snap installed:

ubuntu@busy-collie:~$ snap version # version from xenial archives
snap    2.40
snapd   2.40
series  16
ubuntu  16.04
kernel  4.4.0-173-generic
ubuntu@busy-collie:~$ sudo snap install snapd # install the snapd snap
2020-02-09T19:34:32-06:00 INFO Waiting for restart...
snapd 2.42.5 from Canonical✓ installed
ubuntu@busy-collie:~$ snap list # only the snapd snap installed
Name   Version  Rev   Tracking  Publisher   Notes
snapd  2.42.5   5754  stable    canonical✓  snapd
ubuntu@busy-collie:~$ snap version # now using snapd from the snapd snap
snap    2.42.5
snapd   2.42.5
series  16
ubuntu  16.04
kernel  4.4.0-173-generic
ubuntu@busy-collie:~$ dpkg -s snapd | grep Version # still old version of snapd in debian pkg
Version: 2.40
ubuntu@busy-collie:~$ sudo snap install test-snapd-sh-core18 # install a core18 snap
test-snapd-sh-core18 1.0 from Sergio Cazzolato (cachio) installed
ubuntu@busy-collie:~$ snap list # now we have only snapd, core18, & test-snapd-sh-core18 snaps
Name                  Version   Rev   Tracking  Publisher   Notes
core18                20200124  1668  stable    canonical✓  base
snapd                 2.42.5    5754  stable    canonical✓  snapd
test-snapd-sh-core18  1.0       7     stable    cachio      -

Also note that if you ever end up installing a snap with base: core, you will be unable to remove the core snap, even if you remove the snap that has base: core, I think this is a bug however, since if we’re using the snapd snap and you don’t have any snaps with base: core I think you should be able to remove the core snap.

2 Likes

What is snap version for you ?

Thanks @kyrofa and @ijohnson for the suggestions!

@kyrofa that’s an interesting suggestion. I’m a little concerned about ending up in dependency hell (with respect to the other libraries), but will keep it mind.

@ijohnson thanks for the detailed instructions. I did wonder if the version of snapd I was using was the culprit here - Raspbian Buster (stable) comes with 2.37.4, which I’m conscious is a bit out of date. So as part of my testing I did install a more recent version of snapd via dpkg, which did not solve the interface issue. But I did not think to try installing the snapd snap through that. I’ll give what you’re suggesting a spin later today and report back.

Thanks again for taking the time to help

1 Like

OK, as suggested by @ijohnson, I can confirm that the following works on Raspbian - and I assume Debian - Buster (stable):

  1. Add the Raspbian Bullseye (testing) repo to the apt sources - more or less following https://serverfault.com/a/382101.

  2. This allows you to install snapd 2.42.1 via sudo apt update && sudo apt install -y snapd/testing. [Aside: getting a recent version of snapd is probably also doable manually through dpkg, though there’s at least one dependency from Bullseye that snapd 2.42.1 requires, so the apt sources method seems cleaner]

  3. Install any snap that has base: core18. This will also trigger an install of the snapd and core18 snaps. The core18-based snap will work normally, with all interfaces connected as expected - and without the core snap being installed.

Thanks again for the help in getting this running!

1 Like

So…I came across a situation with the wifi-ap snap, which does not define a base one way or another - but still triggers an install of the core snap. Any ideas why that is? My understanding was that not specifying a base does not imply base: core - and that’s also what I understand from your comment.

For reference, the snap.yaml from the wifi-ap snap’s meta directory is below. As a workaround I’m currently trying to roughly clone that snap with base: core18 specified, to avoid this situation.

snap.yaml
name: wifi-ap
version: 30
summary: WiFi Access Point based on hostapd
description: |
  This snap is implementing a WiFi access point based on hostapd and allows
  easily to share a internet connection or just create a network others can
  easily connect to.
  Please find the source of this snap at:
  https://code.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap
architectures:
- armhf
confinement: strict
grade: stable
slots:
  control:
    content: socket-directory
    interface: content
    write:
    - $SNAP_DATA/sockets
apps:
  automatic-setup:
    command: command-automatic-setup.wrapper
    daemon: simple
    plugs:
    - network
  config:
    command: command-config.wrapper
    plugs:
    - network
  management-service:
    command: command-management-service.wrapper
    daemon: simple
    plugs:
    - network-bind
    - network-control
    - firewall-control
    - network-manager
  setup-wizard:
    command: command-setup-wizard.wrapper
    plugs:
    - network
  status:
    command: command-status.wrapper
    plugs:
    - network

If a snap does not define a base, it defaults to use the core snap as a base, apologies if I didn’t make this clear.

This is incorrect, see above

Ah ok got it. I think I was also thrown off by some of what I read at https://snapcraft.io/docs/base-snaps, e.g. “Snaps that don’t use bases can often migrate to one without too much difficulty.” - which made me think that there is such a thing as a snap without a base.

Thanks for clarifying.

I’ll try to get that doc updated to make this clearer