Adding a PPA on LXD builds

I can’t seem to add PPAs using cleanbuild on LXD.

I need some software packages that are available in an external repository. It woks on my machine but I would like it to work in a cleanbuild environment to make it easier to reproduce.

I have a ppa part that includes the repository and an after dependency in my main app part.

--- 8< ---
parts:
  ppa:
    plugin: nil
    override-build: |
      snapcraftctl build
      add-apt-repository -yu ppa:some/ppa
    build-packages:
      - software-properties-common
  app:
    after: [ppa]
    build-packages:
      - some-package-from-some-ppa

Building with LXD (in an Ubuntu 16.04 container) gives:

--- 8< ---
snapcraft 2.42 from 'canonical' installed
Setting up container with project assets
./
./test.yml
./snap/
./snap/snapcraft.yaml
Could not find a required package in 'build-packages': some-package-from-some-ppa

When I try to debug in the container it indeed didn’t add the repository (yet).

Any ideas?

  1. The snapcraftctl build is unnecessary for the nil plugin
  2. snapcraft can’t find some-package-from-some-ppa due to the fact that you haven’t updated the APT local package cache, to do so add apt-get update after the add-apt-repository call

Thanks but that’s not the issue.

The -u in the add-apt-repository -yu ppa:some/ppa line does exactly that.

-u, --update After adding the repository, update the package cache with packages from this repository (avoids need to apt-get update)

Removing the snapcraftctl build line as you mention did however get me a little bit farther in the build process:

--- 8< ---
Setting up container with project assets
./
./snap/
./snap/snapcraft.yaml
./snap/.snapcraft/
./snap/.snapcraft/state
./parts/
Could not find a required package in 'build-packages': some-package-from-some-ppa
1 Like

When I remove the app: from the YAML and only keep the ppa: part I get:

--- 8< ---
./snap/.snapcraft/
./snap/.snapcraft/state
./parts/
Preparing to pull ppa 
Pulling ppa 
Preparing to build ppa 
Building ppa 

So it looks like the build completely ignores the ppa: part when there is a second part specified. Would that be possible?

In my case I simply install the packages in the pseudo part:

  gcc-6:
    plugin: nil
    override-pull: 'true'
    override-build: |
      sudo apt --yes install software-properties-common

      # Install newer GCC from Toolchain test builds PPA
      sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
      sudo apt update
      sudo apt --yes install gcc-6 g++-6

    override-stage: 'true'
    override-prime: 'true'

Thank for helping me out Lin-Buo-Ren but still no luck. :roll_eyes:

Using the override-build or override-pull in the same part as the one where I build my application is too late. Snapcraft fails before it even reaches that step. I think it looks for the needed build packages earlier in the process.

I need a way to tell Snapcraft: include this repository before doing anything else. It has to be possible and I am missing something… but what?!

I have found a solution! But I don’t understand why. :thinking:

This does not work:

--- 8< ---
parts:
  ppa:
    plugin: nil
    override-pull: |
      add-apt-repository -yu ppa:bitcoin/bitcoin
  wallet:
    plugin: autotools
    after: [ppa]
    build-packages:
      - something
      - libdb4.8++-dev

But this does work:

--- 8< ---
parts:
  ppa:
    plugin: nil
    override-pull: |
      add-apt-repository -yu ppa:bitcoin/bitcoin
      apt install -y libdb4.8++-dev
  wallet:
    plugin: autotools
    after: [ppa]
    build-packages:
      - something

I passed it through a YAML linter and it seems the file is a valid YAML file, so I don’t think it’s related to the ++- syntax.

Can anyone explain why the first example doesn’t work?

It’s a snapcraft lifecycle problem. Snapcraft is pulling all the build dependencies before you have ever started the pull and build for the ppa part.

4 Likes