Can't build snaps inside Docker container


#1

Hi, I’m new to Snapcraft and I’m trying to build a simple snap inside a Docker container. I’ve tried with edge, beta and stable versions of the snapcore/snapcraft image but no luck with any of them. I can successfully build this snap in an Ubuntu 16.04 VM.

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.2
BuildVersion: 18C54

$ docker --version
Docker version 18.09.1, build 4c52b90

`$ docker run --rm -v “$PWD”:/build -w /build snapcore/snapcraft:edge bash -c “apt update && snapcraft”

Sorry, an error occurred in Snapcraft:
Traceback (most recent call last):
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/file_utils.py”, line 109, in link_or_copy
link(source, destination, follow_symlinks=follow_symlinks)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/file_utils.py”, line 143, in link
os.link(source_path, destination, follow_symlinks=False)
OSError: [Errno 5] Input/output error: ‘/build/parts/gateway-health/install/usr/share/doc/python2.7/changelog.gz’ -> ‘/build/stage/usr/share/doc/python2.7/changelog.gz’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/snap/snapcraft/current/legacy_snapcraft/bin/snapcraft”, line 11, in
load_entry_point(‘snapcraft==2.43.1’, ‘console_scripts’, ‘snapcraft’)()
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 1043, in invoke
return Command.invoke(self, ctx)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/cli/_runner.py”, line 114, in run
ctx.forward(lifecyclecli.commands[“snap”])
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 553, in forward
return self.invoke(cmd, **kwargs)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py”, line 209, in snap
_execute(steps.PRIME, parts=[], pack_project=True, output=output, **kwargs)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py”, line 98, in _execute
lifecycle.execute(step, project_config, parts)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py”, line 90, in execute
executor.run(step, part_names)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py”, line 194, in run
self._handle_step(part_names, part, step, current_step, cli_config)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py”, line 208, in _handle_step
getattr(self, “run{}”.format(current_step.name))(part)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py”, line 272, in _run_stage
self._run_step(step=steps.STAGE, part=part, progress=“Staging”)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py”, line 327, in _run_step
getattr(part, step.name)()
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/init.py”, line 687, in stage
self._runner.stage()
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py”, line 109, in stage
“override-stage”, self._override_stage_scriptlet, self._stagedir
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py”, line 162, in _run_scriptlet
scriptlet_name, function_call.strip()
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py”, line 218, in _handle_builtin_function
function(**function_args)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/init.py”, line 709, in _do_stage
fixup_func=fixup_func,
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/init.py”, line 1085, in _migrate_files
file_utils.link_or_copy(src, dst, follow_symlinks=follow_symlinks)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/file_utils.py”, line 117, in link_or_copy
copy(source, destination, follow_symlinks=follow_symlinks)
File “/snap/snapcraft/current/legacy_snapcraft/lib/python3.5/site-packages/snapcraft/file_utils.py”, line 166, in copy
shutil.copy2(source, destination, follow_symlinks=follow_symlinks)
File “/snap/snapcraft/current/legacy_snapcraft/usr/lib/python3.5/shutil.py”, line 251, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File “/snap/snapcraft/current/legacy_snapcraft/usr/lib/python3.5/shutil.py”, line 112, in copyfile
os.symlink(os.readlink(src), dst)
FileExistsError: [Errno 17] File exists: ‘NEWS.gz’ -> ‘/build/stage/usr/share/doc/python2.7/changelog.gz’
We would appreciate it if you anonymously reported this issue.`


#2

Alternatively, have you tried installing snapcraft from homebrew?

Snaps do not easily work inside a docker container, it is possible, just requires extra tweaking.


#3

Here’s the documentation for docker fwiw https://docs.snapcraft.io/build-on-docker/4158

There is an issue with linking when mounting your hfs+ filesystem inside a container which is what I think is what you are experimenting. If you do the clone while inside a docker shell, this might just work.