Failed to get started with snapcraft using Vagrant

This is my first attempt at using snapcraft to build a snap.

I have installed Vagrant and pulled down the ubuntu/xenial64 box. After SSHing into the virtual machine, initialising lxd and installing snapcraft I have attempted to check my environment is set up correctly.

sudo snap install snapcraft --classic
snapcraft init
sudo snapcraft cleanbuild

Below shows the output from this last command:

vagrant@ubuntu-xenial:~/foo$
vagrant@ubuntu-xenial:~/foo$ sudo snapcraft cleanbuild
Creating snapcraft-gorgedly-trothless-dollie
Starting snapcraft-gorgedly-trothless-dollie
error: flag provided but not defined: --format
Failed to get container image info: `lxc image list --format=json ubuntu:xenial/amd64` returned with exit code 2, output: b''
It will not be recorded in manifest.
Waiting for a network connection...
Network connection established
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [7532 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [511 kB]
Get:7 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [219 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [354 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [132 kB]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3456 B]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [1744 B]
Get:12 http://archive.ubuntu.com/ubuntu xenial/universe Translation-en [4354 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [144 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial/multiverse Translation-en [106 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [795 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [329 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [635 kB]
Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [255 kB]
Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.4 kB]
Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [8344 B]
Get:21 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [4844 B]
Get:22 http://archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [3220 B]
Get:23 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7400 B]
Get:24 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3996 B]
Fetched 15.7 MB in 7s (2204 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  squashfuse
0 upgraded, 1 newly installed, 0 to remove and 10 not upgraded.
Need to get 17.4 kB of archives.
After this operation, 54.3 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 squashfuse amd64 0.1.100-0ubuntu1~ubuntu16.04.1 [17.4 kB]
Fetched 17.4 kB in 0s (248 kB/s)
Selecting previously unselected package squashfuse.
(Reading database ... 25657 files and directories currently installed.)
Preparing to unpack .../squashfuse_0.1.100-0ubuntu1~ubuntu16.04.1_amd64.deb ...
Unpacking squashfuse (0.1.100-0ubuntu1~ubuntu16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up squashfuse (0.1.100-0ubuntu1~ubuntu16.04.1) ...
error: no changes of type "auto-refresh" found
Looking up assertion ['account-key', 'public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul']
Looking up assertion ['snap-declaration', 'snap-name=core']
Looking up assertion ['snap-revision', 'snap-revision=4650', 'snap-id=99T7MUlRhtI3U0QFgl5mXXESAiSwt776']
error: open /var/lib/snapd/hostfs/home/vagrant/snap/lxd/common/snapcraftx_f_16kg/core_4650.assert: no such file or directory
Stopping local:snapcraft-gorgedly-trothless-dollie
Sorry, Snapcraft ran into an error when trying to running through its
lifecycle that generated the following traceback:
Traceback (most recent call last):
  File "/snap/snapcraft/1594/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==2.42.1', 'console_scripts', 'snapcraft')()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 222, in cleanbuild
    build_environment=build_environment)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_containers.py", line 53, in cleanbuild
    _deprecated_cleanbuild(project, remote, config, tar_filename)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_containers.py", line 77, in _deprecated_cleanbuild
    metadata=config.get_metadata(), remote=remote).execute()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 186, in execute
    with self._container_running():
  File "/snap/snapcraft/1594/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 84, in _container_running
    with self._ensure_started():
  File "/snap/snapcraft/1594/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 107, in _ensure_started
    self._ensure_container()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_cleanbuilder.py", line 50, in _ensure_container
    self._inject_snapcraft(new_container=True)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 253, in _inject_snapcraft
    self._inject_snap('core', tmp_dir)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 303, in _inject_snap
    ], tmp_dir)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 377, in _inject_assertions
    self._push_file(filepath, container_filename)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 326, in _push_file
    src, '{}{}'.format(self._container_name, dst)])
  File "/snap/snapcraft/1594/usr/lib/python3.5/subprocess.py", line 581, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['lxc', 'file', 'push', '/home/vagrant/snap/lxd/common/snapcraftx_f_16kg/core_4650.assert', 'local:snapcraft-gorgedly-trothless-dollie/run/core_4650.assert']' returned non-zero exit status 1

1 Like

I have been investigating this more, it seems that I only get this error when running cleanbuild.

Just running snapcraft it successfully builds the snap. If I run clean, it cleans fine. I don’t really understand why running cleanbuild makes such a difference.

Are your files stored on your host machine, mounted into the vagrant vm? if so then I expect the vagrant file sharing mechanism is interfering with LXD.

I also get the same thing on Vagrant. I’m not running in the shared /vagrant folder.

vagrant@ubuntu-xenial:~/projects/test-snapcraft$ snapcraft cleanbuild
Creating snapcraft-chronographically-wayless-toshia
Starting snapcraft-chronographically-wayless-toshia
error: flag provided but not defined: --format
Failed to get container image info: `lxc image list --format=json ubuntu:xenial/amd64` returned with exit code 2, output: b''
It will not be recorded in manifest.
Waiting for a network connection...
Network connection established
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [7532 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [539 kB]
Get:7 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [367 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [138 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3456 B]
Get:10 http://archive.ubuntu.com/ubuntu xenial/universe Translation-en [4354 kB]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [1744 B]
Get:12 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [144 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial/multiverse Translation-en [106 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [831 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [680 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [274 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.4 kB]
Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [8344 B]
Get:19 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [6756 B]
Get:20 http://archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [4180 B]
Get:21 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7420 B]
Get:22 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3996 B]
Fetched 15.3 MB in 4s (3383 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  squashfuse
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 17.4 kB of archives.
After this operation, 54.3 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 squashfuse amd64 0.1.100-0ubuntu1~ubuntu16.04.1 [17.4 kB]
Fetched 17.4 kB in 0s (57.8 kB/s)
Selecting previously unselected package squashfuse.
(Reading database ... 25666 files and directories currently installed.)
Preparing to unpack .../squashfuse_0.1.100-0ubuntu1~ubuntu16.04.1_amd64.deb ...
Unpacking squashfuse (0.1.100-0ubuntu1~ubuntu16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up squashfuse (0.1.100-0ubuntu1~ubuntu16.04.1) ...
error: no changes of type "auto-refresh" found
Looking up assertion ['account-key', 'public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul']
Looking up assertion ['snap-declaration', 'snap-name=core']
Looking up assertion ['snap-revision', 'snap-revision=5145', 'snap-id=99T7MUlRhtI3U0QFgl5mXXESAiSwt776']
error: open /var/lib/snapd/hostfs/home/vagrant/snap/lxd/common/snapcraftht7hqnju/core_5145.assert: no such file or directory
Stopping local:snapcraft-chronographically-wayless-toshia
Sorry, Snapcraft ran into an error when trying to running through its
lifecycle that generated the following traceback:
Traceback (most recent call last):
  File "/snap/snapcraft/1594/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==2.42.1', 'console_scripts', 'snapcraft')()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 222, in cleanbuild
    build_environment=build_environment)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_containers.py", line 53, in cleanbuild
    _deprecated_cleanbuild(project, remote, config, tar_filename)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_containers.py", line 77, in _deprecated_cleanbuild
    metadata=config.get_metadata(), remote=remote).execute()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 186, in execute
    with self._container_running():
  File "/snap/snapcraft/1594/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 84, in _container_running
    with self._ensure_started():
  File "/snap/snapcraft/1594/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 107, in _ensure_started
    self._ensure_container()
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_cleanbuilder.py", line 50, in _ensure_container
    self._inject_snapcraft(new_container=True)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 253, in _inject_snapcraft
    self._inject_snap('core', tmp_dir)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 303, in _inject_snap
    ], tmp_dir)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 377, in _inject_assertions
    self._push_file(filepath, container_filename)
  File "/snap/snapcraft/1594/lib/python3.5/site-packages/snapcraft/internal/lxd/_containerbuild.py", line 326, in _push_file
    src, '{}{}'.format(self._container_name, dst)])
  File "/snap/snapcraft/1594/usr/lib/python3.5/subprocess.py", line 581, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['lxc', 'file', 'push', '/home/vagrant/snap/lxd/common/snapcraftht7hqnju/core_5145.assert', 'local:snapcraft-chronographically-wayless-toshia/run/core_5145.assert']' returned non-zero exit status 1
vagrant@ubuntu-xenial:~/projects/test-snapcraft$

Shouldn’t this work with Xenial using Vagrant?

I am having the same issues. I wanted to build a SNAP package on a CI environment where I can’t use “sudo”.
I tried

  • Using “snapcraft”: Works but requires “sudo”
  • Using “snapcraft cleanbuild”: Does not work. Getting the same error as mentioned in this ticket
  • Using docker: It works but creates files and directories using “root” on which I get permission issues. Here’s the official doc link which does warn about these permission issues and recommends using “sudo chown” to take ownership back (which I can’t do).

Does anyone have any idea on how to make any one of the way mentioned above work?

This is the error that I see

buildkite-agent@ip-xxx-xx-xx-xxx:$ snapcraft cleanbuild --debug
locale: Cannot set LC_CTYPE to default locale: No such file or directory
Locale not set! Snapcraft will temporarily use C.UTF-8
Creating snapcraft-badly-loving-macaw
Starting snapcraft-badly-loving-macaw
error: flag provided but not defined: --format
Failed to get container image info: `lxc image list --format=json ubuntu:xenial/amd64` returned with exit code 2, output: b''
It will not be recorded in manifest.
Waiting for a network connection...
Network connection established
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
...
Get:38 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [4184 B]
Fetched 25.8 MB in 5s (5027 kB/s)
Reading package lists... Done
sudo: unable to resolve host snapcraft-badly-loving-macaw: Connection refused
sudo: unable to resolve host snapcraft-badly-loving-macaw: Connection refused
error: no changes of type "auto-refresh" found
sudo: unable to resolve host snapcraft-badly-loving-macaw: Connection refused
error: cannot install "core": Post https://api.snapcraft.io/v2/snaps/refresh: dial tcp: lookup
       api.snapcraft.io on [::1]:53: read udp [::1]:56436->[::1]:53: read: connection refused
Stopping local:snapcraft-badly-loving-macaw
An error occurred when trying to execute 'sudo snap install core' with 'lxd': returned exit code 1.

This is a long time ago but the files are not in a shared drive.