8

If I try to run snap under a gitlab-CI pipeline, installing the most simple package, it fails with:

$ snap install hello-world

error: cannot communicate with server: Post http://localhost/v2/snaps/hello-world: dial unix /run/snapd.socket: connect: no such file or directory

The gitlab-ci yml configuration file is the simplest ever:

image: ubuntu:18.04

before_script:
  - apt-get update -qq

test:
  script:
    - apt-get install -y snapd
    - snap version
    - snap install hello-world
    - hello-world

What's going on?

knocte
  • 16,941
  • 11
  • 79
  • 125

3 Answers3

6

Unfortunately, snaps use many of the underlying security tech used by docker, and they don't play very nicely. Installing a snap also requires snapd to be running, which it's not in docker (hence the error). I'm afraid you simply cannot reliably install snaps in docker containers today.

Note that there are other non-docker-based CI systems. You can, with a little custom work, use LXD as the backend for your GitLab CI runner, which handle snaps fine. You can also use GitHub Actions, which seem so be based on a Azure VM, which also handles snaps fine.

kyrofa
  • 1,759
  • 1
  • 14
  • 19
5

In my case it is solved by starting the snapd service:

systemctl start snapd.service
Simon
  • 4,251
  • 2
  • 24
  • 34
2

Seems GithubActionsCI doesn't use Docker so I'm using this now instead of GitLabCI, to build and test snap packages.

Just note:

  • You need sudo to install snap with apt-get, and also to install any snap package with the snap command.
  • If you want to run the snapcraft (to build packages, not just test them), getting it via apt-get works, but gives a version that is a bit old (e.g. it doesn't support layouts). If you want a newer version, you can install it via snap with snap install snapcraft but you need some workarounds to make it run, such as sudo chown root:root / and to pass the --destructive-mode flag (see https://forum.snapcraft.io/t/permissions-problem-using-snapcraft-in-azure-pipelines/13258/16).
knocte
  • 16,941
  • 11
  • 79
  • 125