libdevmapper-dev fails to install as build-package using snapcraft:core20 (Multipass)

Bug #1982420 reported by Jason C. Nucciarone
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Snapcraft
New
Undecided
Unassigned
cloud-images
New
Undecided
Unassigned

Bug Description

# Description

When trying to install the package `libdevmapper-dev` as a build-package in a core20 based snap, the package fails due to a discrepancy in the apt sources between updating the multipass build instance and installing the build packages specified in the `snapcraft.yaml` file.

# Snapcraft, Multipass, and Ubuntu versions

$ snapcraft version
snapcraft 7.0.11

$ multipass version
multipass 1.10.1
multipassd 1.10.1

# Stacktrace and what I expect to happen

```
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libdevmapper-dev : Depends: libdevmapper1.02.1 (= 2:1.02.167-1ubuntu1) but 2:1.02.175-2ubuntu4~ubuntu20.04.1 is to be installed
E: Unable to correct problems, you have held broken packages.

```

I expect libdevmapper-dev to install correctly because I already have libdevmapper1.02.1 installed inside the multipass instance.

# Steps to reproduce

Currently, I am trying to build the microstack snap to troubleshoot some confinement issues (not related to this issue). Here are the commands that I am using to try and build the package:

1. sudo snap install multipass --classic
2. sudo snap install snapcraft --classic
3. git clone https://opendev.org/x/microstack.git
4. cd microstack
5. snapcraft

# Preliminary investigation

Browsing two separate environments, I noticed there is a discrepancy between the apt-cache policy for the libdevmapper-dev package between the unmodified snapcraft:core20 image and the failed build instance.

*Policy for base instance*

```
$ apt-cache policy libdevmapper-dev
libdevmapper-dev:
  Installed: (none)
  Candidate: 2:1.02.167-1ubuntu1
  Version table:
     2:1.02.175-2ubuntu4~ubuntu20.04.1 100
        100 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages
     2:1.02.167-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
```

*Policy for failed build instance*

```
$ apt-cache policy libdevmapper-dev
libdevmapper-dev:
  Installed: (none)
  Candidate: 2:1.02.167-1ubuntu1
  Version table:
     2:1.02.167-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages

```

Looking at these policies, it seems that when the build instance is upgrading, before pulling in the build-dependencies, apt is pulling packages from both the main and focal-backports pockets. Once the upgrade finishes, the apt sources update so that apt will only pull from the main pocket. However, since libdevmapper-dev is not compatible with the libdevmapper1.02.1 pulled from focal-backports pocket, libdevmapper-dev fails to install. I found the apt sources being changed when parsing output from journalctl.

# Potential impact and mitigation

Any snap package using core20 as its base that requires `libdevmapper-dev` will fail to build if using multipass as the build provider. This bug might also affect other packages that are tied to a specific version of a package modified when the multipass instance is upgraded.

To get around this issue for now, any package that requires `libdevmapper-dev` as a build dependency should use LXD as the build provider.

1. sudo snap install lxd
2. lxd init --auto
3. snapcraft --use-lxd

You can also add focal-backports as a package repository in the `snapcraft.yaml` file: https://snapcraft.io/docs/package-repositories

# Potential solution

Either enable snapcraft to use the focal-backports pocket in multipass-backed builds, or disable the focal-backports pocket in the snapcraft:core20 multipass image so that apt does not pull from there when upgrading the instance.

# Attachments

* Log file for the snap package build
* journalctl | grep ".sources" output

Revision history for this message
Jason C. Nucciarone (nuccitheboss) wrote :
Revision history for this message
Justin Cattle (jocado) wrote :

Hi,

I hit this bug as well.

The problem seems to be that the multipass image for core20 builds, called snapcraft:core20, contains the version of libdevmapper1.02.1 from backports. It has the backports repo enabled, and an apt preferences to give it equal wight to the standard repos. apt will not downgrade libdevmapper1.02.1 automatically unless it's defined by policy or specifically instructed otherwise.

I installed a fresh machine, using the snapcraft:core20 image, and checked a few things:

root@test-20:~# cat /etc/apt/preferences.d/backports
Package: *
Pin: release a=*-backports
Pin-Priority: 500

root@test-20:~# grep backport /etc/apt/sources.list* -R
/etc/apt/sources.list:## Also, please note that software in backports WILL NOT receive any review
/etc/apt/sources.list:deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
/etc/apt/sources.list:# deb-src http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse

root@test-20:~# dpkg -l |grep devmapper
ii libdevmapper1.02.1:amd64 2:1.02.175-2ubuntu4~ubuntu20.04.1 amd64 Linux Kernel Device Mapper userspace library

root@test-20:~# apt-cache policy libdevmapper1.02.1
libdevmapper1.02.1:
  Installed: 2:1.02.175-2ubuntu4~ubuntu20.04.1
  Candidate: 2:1.02.175-2ubuntu4~ubuntu20.04.1
  Version table:
 *** 2:1.02.175-2ubuntu4~ubuntu20.04.1 500
        500 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages
        100 /var/lib/dpkg/status
     2:1.02.167-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages

When the image is used for snapcraft, some additional setup seems to be done that removes the backports repo. So, if anything then requires libdevmapper1.02.1, it will be the older version,and you get the apt solution which cannot be resolved in that case with the default policy.

This could be resolved by changing snapcraft to keep the backprts repo, or changing the image generation process to not include backports. Including backpacks seems like strange default choice for production to be honest.

Potentially therefor, this would be better logged under the multipass project, to highlight the backprots inclusion is problematic. I'm not sure who is responsible for multipless images though, perhaps the multipass code team are not.

I will try creating an issue over on https://github.com/canonical/multipass/issues

Cheers,
Just

Revision history for this message
Justin Cattle (jocado) wrote :
Revision history for this message
Justin Cattle (jocado) wrote :

As a workaround, you can include the backports repo definition in your snapcraft.

It's not ideal though, because with the images apt pinning policy it means any backport could will used, so you may end up with some undesirable or unexpected versions.

Revision history for this message
Justin Cattle (jocado) wrote :

Here's the core20 [ focal ] sample snapcraft config:

package-repositories:
  - type: apt
    formats:
      - deb
    url: 'http://archive.ubuntu.com/ubuntu'
    key-id: 843938DF228D22F7B3742BC0D94AA3F0EFE21092
    suites:
      - focal-backports
    components:
      - main
      - restricted
      - universe
      - multiverse

Revision history for this message
Justin Cattle (jocado) wrote :

Right, I have been redirect to the cloud-images team, that looks after these.

Issue raise.

https://bugs.launchpad.net/cloud-images/+bug/2009871

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.