Search code examples
dockergitlabgitlab-cisnapcraft

snap and gitlab-CI: error: cannot communicate with server: Post http://localhost/v2/snaps/hello-world


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?


Solution

  • 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).