Avoiding breakage when using content interface

My snap uses content[docker-executables] interface so that it can run docker/docker-compose commands without having to bundle those executables.

The snapcraft.yaml has the following relevant bits:

    interface: content
    default-provider: docker
    target: $SNAP/docker-exe

  PATH: $PATH:$SNAP/docker-exe/usr/bin:$PATH:$SNAP/docker-exe/bin
  PYTHONPATH: $SNAP/docker-exe/lib/python2.7/site-packages

This was working fine until docker-snap was updated to 19.03 which upgraded the python version to 3.5. To fix the breakage I had to update PYTHONPATH to $SNAP/docker-exe/lib/python3.5/site-packages.

What is the recommended way of using content interface to avoid such breakages in future?

Snaps providing content via the content interface need to version the names of the interfaces, if I understand correctly. The only way to completely avoid the problem is to bundle them.

1 Like

@tianon, this is something you probably want to think about, other snaps use the docker content interface to call docker-compose which is Python based and thus could be broken by changes to the version of python in the snap, etc. Perhaps instead of putting the docker-compose file in that dir, you could put a little wrapper script which sets the proper env variables so that users of the content interface don’t need to mind this themselves? i.e. move the bin/docker-compose binary to bin/docker-compose-real and then bin/docker-compose becomes:

#!/bin/bash -e

# snippet from https://stackoverflow.com/a/246128/10102404
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

export PYTHONPATH="$SCRIPT_DIR/../lib/python3.5/site-packages"
exec $SCRIPT_DIR/bin/docker-compose-real "$@"

Otherwise, I think the typical convention of naming of these interfaces that is versioned would be something like (in the docker snap)

    content: docker-executables
    interface: content
    - .

For changing the snap to use python3 or changing the base of the snap to 18.04 you could change the slot to docker-executables-16.04-python3 or docker-executables-18.04-python2 respectively. However then other snap applications like this user would be broken again if you switched the slot names so I would recommend just replacing the docker-compose binary as described above.

1 Like

Thanks @ijohnson. Your proposed solution of replacing the docker-compose binary would work great for us. @tianon: Thoughts?

@tianon: Any thoughts on the solution proposed by @ijohnson?