Help required packaging anki-desktop client as a snap

Hi,

I am trying to package a pre-built application using snapcraft. I want to be able to package the ank-desktop client via a snap although I am having significant difficulties. This is my first attempt at creating a snap so I apologise in advance if I have not understood a concept correctly from the documentation.

Anki provides a tar of the pre-built binary so I thought this should map quite well to the existing geekbench example. Below is my initial snapcraft.yaml.

FYI - I am using a vagrant ubuntu xenial VM to build the snap then install it on to my host system.

# vim: tw=80 shiftwidth=4 tabstop=4 softtabstop=4 et ai
name: anki-desktop
version: 2.0.52
summary: Anki desktop client
description: |
    Anki is a program which makes remembering things easy. Because it's a lot
    more efficient than traditional study methods, you can either greatly
    decrease your time spent studying, or greatly increase the amount you learn.

confinement: devmode

parts:
    anki-desktop:
        plugin: dump
        source: https://apps.ankiweb.net/downloads/current/anki-$SNAPCRAFT_PROJECT_VERSION-amd64.tar.bz2
        source-type: tar

apps:
    anki:
        command: anki

Within the tar, the bin folder contains anki and its various dependencies. On running snapcraft I recieve the following output:

vagrant@ubuntu-xenial:/vagrant_data$ snapcraft
Preparing to pull anki-desktop
Pulling anki-desktop
Downloading 'anki-2.0.52-amd64.tar.bz2'[==============================================] 100%
Preparing to build anki-desktop
Building anki-desktop
Staging anki-desktop
Priming anki-desktop
Files from the build host were migrated into the snap to satisfy dependencies that would otherwise not be met. This feature will be removed in a future release. If these libraries are needed in the final snap, ensure that the following are either satisfied by a stage-packages entry or through a part:
usr/lib/x86_64-linux-gnu/libICE.so.6
usr/lib/x86_64-linux-gnu/libSM.so.6
usr/lib/x86_64-linux-gnu/libX11.so.6
usr/lib/x86_64-linux-gnu/libXau.so.6
usr/lib/x86_64-linux-gnu/libXdmcp.so.6
usr/lib/x86_64-linux-gnu/libXext.so.6
usr/lib/x86_64-linux-gnu/libfontconfig.so.1
usr/lib/x86_64-linux-gnu/libicudata.so.55
usr/lib/x86_64-linux-gnu/libicuuc.so.55
usr/lib/x86_64-linux-gnu/libxcb.so.1
usr/lib/x86_64-linux-gnu/libxml2.so.2
'grade' property not specified: defaulting to 'stable'
Snapping 'anki-desktop' /
Snapped anki-desktop_2.0.52_amd64.snap

In the above output I am confused why various shared libraries are not satisfied. If these are missing how could I determine so?

When attempting to install and run the snap. The following occurs:
(Notice I am using anki-desktop.anki to ensure it is running the ank command from the snap.)

➜  anki-desktop-snap git:(master) ✗ sudo snap install anki-desktop_2.0.52_amd64.snap --devmode --dangerous
[sudo] password for rad:
anki-desktop 2.0.52 installed
➜  anki-desktop-snap git:(master) ✗ anki-desktop.anki
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  File "aqt/__init__.py", line 12, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  File "aqt/qt.py", line 10, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  File "anki/__init__.py", line 14, in <module>
Exception: Anki requires a UTF-8 locale.
runanki returned -1
➜  anki-desktop-snap git:(master) ✗

Why hasn’t snapd or the snap I created taken the locale from the host system?

Viewing localectl output shows that the host system and the VM used to build the snap contain a UTF locale.

###Arch Host:

➜  anki-desktop-snap git:(master) ✗ localectl
   System Locale: LANG=en_GB.UTF-8
       VC Keymap: uk
      X11 Layout: gb
➜  anki-desktop-snap git:(master) ✗

###Ubuntu Xenial VM:

vagrant@ubuntu-xenial:/vagrant_data$ localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105
vagrant@ubuntu-xenial:/vagrant_data$

Is it possible to get some kind of shell into the snap container to inspect the environment and determine what is wrong?

I can’t help with the rest of it, but snap run --shell anki-desktop should get you started there.

Refer ldd manpage in section 1

Snapcraft automatically stages these libraries for you for now, but you should use dpkg-query --search <filepath> find out which ubuntu package that provides it and enumerates them in stage-packages keyword.

Also, note that sometimes staging the library itself is not enough, some library depends on resources provided by other packages as well, you may find out what is missing by fetching the syscall trace via running snap run --strace='-o guvcview -e trace=execve,access,open,close,fstat,stat,write' <snap provided command> and check what resources it’s trying to locate.

Check locale output?

@Lin-Buo-Ren, @cjwatson - Thanks for your responses, I wish I’d seen the --shell option in the snap reference docs. If possible how could I contribute back to the troubleshooting documentation (if and when I get this working, heh)

From what I understood, all the shared libraries for anki were present in the ./bin/ folder of the tar.

I will update this in a few days as I get time. This is my current hobby project atm.

Quick update —

What does snap run --shell actually do?

I am running the command on my Arch host and it does get me a shell but I was expecting it to be into the FS of the container.

I ran the following and if this is right, I can see that locale from the host is present in the snap.

➜  anki-desktop-snap git:(master) ✗ snap run --shell anki-desktop.anki  [
[rad@linux anki-desktop-snap]$
[rad@linux anki-desktop-snap]$ localectl
   System Locale: LANG=en_GB.UTF-8
       VC Keymap: uk
      X11 Layout: gb
[rad@linux anki-desktop-snap]$

Running in the vagrant VM used to build the snap yeilds, really different results. I get placed in a shell at /var/lib/snapd/void.

vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$ snap run --shell anki-desktop.anki
vagrant@ubuntu-xenial:/var/lib/snapd/void$
vagrant@ubuntu-xenial:/var/lib/snapd/void$
vagrant@ubuntu-xenial:/var/lib/snapd/void$ localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105
vagrant@ubuntu-xenial:/var/lib/snapd/void$ 

I thought I would add an additional update.

I have go not further into understanding the locale issue. I could do with some answres to questions on my fourth post.

I don’t have a clear understanding on how to troubleshoot the environment I have created in the snap.

  • What shell am I placed into when running --shell?
  • What is happening when I execute localectl within the shell? For instance, what is the order of execution w.r.t binaries, container, host system.

After looking at the other warnings, I thought I would attempt to solve / remove those. When attempting to add stage-packages (such as python-qt4) I get really weird errors about being unable to copy hardlinks of .so graphics drivers.

This doesn’t make a lot of sense to me, given I thought stage-packages would just install the Ubuntu package in the container, I don’t understand why these are even being copied over. Terminal output is attached below:

vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$ snapcraft clean
Cleaning up priming area
Cleaning up staging area
Cleaning up parts directory
vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$ snapcraft
Preparing to pull anki-desktop
Hit http://archive.ubuntu.com/ubuntu xenial InRelease
Hit http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Hit http://security.ubuntu.com/ubuntu xenial-security InRelease
Fetched 0 B in 0s (0 B/s)
tar: ./usr/lib/x86_64-linux-gnu/dri/vmwgfx_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/kms_swrast_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/i915_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/radeonsi_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/r200_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/nouveau_vieux_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/virtio_gpu_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/i965_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/swrast_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/r600_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: Exiting with failure status due to previous errors
dpkg-deb: error: subprocess tar returned error exit status 2
Error while provisioning '/vagrant_data/parts/anki-desktop/ubuntu/download/libgl1-mesa-dri_17.2.8-0ubuntu0~16.04.1_amd64.deb'
vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$
vagrant@ubuntu-xenial:/vagrant_data$

The only thing I have found related to snapcraft and this error is a single comment on a SO post.

  • How can I troubleshoot or debug these issues?
  • How can I get more output from snapcraft?
  • What do information do I need to provide to assist troubleshooting?

Mostly as an aside and on a whim I created a 16.04 desktop VM, downloaded and ran the anki binary. I understand that this is probably not that helpful but I thought it might narrow down or let me exhibit the same locale issue. Without a proper understanding of how to debug the snap I thought of it as another way to introspect a somewhat similar environment. Unfortunately this works without any issue, I recieved a single warning regarding a missing shared library for Gnome theme integration but Anki launches and runs out of the box.

Another update…

I only recently stumbled on to HTMLDoc Github project and related blog post.

I wish I had found that and the Ubuntu blog post from nearly two years ago earlier. If it isn’t apparant I am trying to package a snap of a GUI application.

After modifying my snapcraft.yaml to:

# vim: tw=80 shiftwidth=4 tabstop=4 softtabstop=4 et ai
name: anki-desktop
version: 2.0.52
summary: Anki desktop client
description: |
    Anki is a program which makes remembering things easy. Because it's a lot
    more efficient than traditional study methods, you can either greatly
    decrease your time spent studying, or greatly increase the amount you learn.

confinement: devmode

parts:
    anki-desktop:
        plugin: dump
        source: https://apps.ankiweb.net/downloads/current/anki-$SNAPCRAFT_PROJECT_VERSION-amd64.tar.bz2
        source-type: tar
        after: [desktop-gtk3]

apps:
    anki:
        command: desktop-launch $SNAP/bin/anki
        plugs: [home, network, x11]

I feel like it is a step in the right direction, however rurnning snapcraft within the Vagrant VM yeilds errors about pulling in libgl1-mesa-dri.

vagrant@ubuntu-xenial:/vagrant_data$ snapcraft
Preparing to pull desktop-gtk3
Hit http://security.ubuntu.com/ubuntu xenial-security InRelease                      
Hit http://archive.ubuntu.com/ubuntu xenial InRelease                                
Hit http://archive.ubuntu.com/ubuntu xenial-updates InRelease                        
Hit http://archive.ubuntu.com/ubuntu xenial-backports InRelease                      
Fetched 0 B in 0s (0 B/s)                                                            
tar: ./usr/lib/x86_64-linux-gnu/dri/vmwgfx_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/kms_swrast_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/i915_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/radeonsi_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/r200_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/nouveau_vieux_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/virtio_gpu_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/i965_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/radeon_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/swrast_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: ./usr/lib/x86_64-linux-gnu/dri/r600_dri.so: Cannot hard link to ‘./usr/lib/x86_64-linux-gnu/dri/r300_dri.so’: Operation not permitted
tar: Exiting with failure status due to previous errors
dpkg-deb: error: subprocess tar returned error exit status 2
Error while provisioning '/vagrant_data/parts/desktop-gtk3/ubuntu/download/libgl1-mesa-dri_17.2.8-0ubuntu0~16.04.1_amd64.deb'
vagrant@ubuntu-xenial:/vagrant_data$


Why can’t I install that package?

The snap from your latest posted yam builds and installs fine here. I’ve never used vagrant to build (indeed, aside, I’ve never had any kind of success doing anything in vagrant), but I use lxd. It builds as expected. Unfortunately there’s a library error once it’s built, but it does build and install and at least try to run…

alan@hal:~/tmp/anki$ snap install anki-desktop_2.0.52_amd64.snap --dangerous --devmode
anki-desktop 2.0.52 installed
alan@hal:~/tmp/anki$ anki-desktop.anki 
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  File "aqt/__init__.py", line 12, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  File "aqt/qt.py", line 21, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 546, in load_module
ImportError: libfontconfig.so.1: cannot open shared object file: No such file or directory
runanki returned -1

Hi - Thanks for the response.

I expect that is missing the libfontconfig1 from stage-packages. If I could get to this stage myself, I am sure I could quickly get rid of these errors.

I find it kinda strange that Vagrant struggles to build this snapcraft. Would using LXD on my Arch Host, where the LXD container is Ubuntu:16.04 be a supported environment?

That’s what I use. It’s certainly the fastest way I’ve found to build snaps.

1 Like

Yes. I’m using it for building as well.