I’m trying to build snap on my Mac and got multiple problems (it builds without issues on Linux).
I had this project structure:
.
├── buildroot
├── camera
├── controller
└── snap
└── snapcraft.yaml
that builds buildrood based camera firmware as asset for nodejs based controller application i.e. on Linux I’m building without issue in ./snap/ but when tried to build on Mac it didn’t mount …/buildroot, …/camera and build failed. Solution was to move snapcraft.yaml in the project root like:
.
├── buildroot
├── camera
├── controller
└── snapcraft.yaml
And to change paths in snapcraft.yaml from:
camera-firmware:
plugin: kbuild
override-pull: |
export SNAP_ROOT="../../../"
make -C $SNAP_ROOT/../buildroot/ O=$SNAPCRAFT_PART_SRC BR2_EXTERNAL=../camera/ scanner_camera_defconfig
to:
camera-firmware:
plugin: kbuild
override-pull: |
export SNAP_ROOT="../../../project"
make -C $SNAP_ROOT/buildroot/ O=$SNAPCRAFT_PART_SRC BR2_EXTERNAL=../camera/ scanner_camera_defconfig
With these changes the buildroot camera firmware was successfully build but the node firmware failed with these errors:
sh: 1: node-gyp: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: netlink-notify@github:treedys/netlink-notify (node_modules/netlink-notify):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Error while executing:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: /usr/bin/git ls-remote -h -t ssh://git@github.com/treedys/netlink-notify.git
npm WARN optional SKIPPING OPTIONAL DEPENDENCY:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fatal: Could not change back to '/root/parts/treedys-controller/build': Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: exited with error code: 128
First one is caused by lack of github credentials (which I have on my Mac):
snapcraft-treedys-controller ../parts/treedys-controller/build# /usr/bin/git ls-remote -h -t ssh://git@github.com/treedys/netlink-notify.git
The authenticity of host 'github.com (140.82.118.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,140.82.118.4' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Second one seems to be related to the fact the snapcraft uses root account for multipass builds and somehow npm messes with user file ownership. For example .npm directory is owned by multipass user which is highly suspicious:
snapcraft-treedys-controller # ls -al /root/
total 60
drwx------ 12 root root 4096 Aug 8 07:17 .
drwxr-xr-x 23 root root 4096 Aug 8 05:40 ..
-rw-r--r-- 1 root root 121 Aug 8 05:40 .bashrc
drwxr-xr-x 19 root root 4096 Aug 8 06:45 .buildroot-ccache
drwxr-xr-x 3 root root 4096 Aug 8 05:40 .cache
drwx------ 4 root root 4096 Aug 8 05:44 .config
drwxr-xr-x 6 multipass multipass 4096 Aug 8 07:17 .npm
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 4096 Aug 8 07:32 .ssh
drwxr-xr-x 4 root root 4096 Aug 8 05:41 parts
drwxr-xr-x 2 root root 4096 Aug 8 05:41 prime
drwxr-xr-x 1 root root 352 Aug 8 07:51 project
drwxr-xr-x 3 root root 4096 Aug 8 05:40 snap
drwxr-xr-x 2 root root 4096 Aug 8 05:41 stage
-rw-r--r-- 1 root root 1921 Aug 8 05:41 state
So my questions are:
- How to pass from snapcraft to multipass which directory to mount to avoid moving snapcraft.yaml from ./snap to ./ ?
- How to get SNAP_ROOT environment variable pointing to the directory where the snapcraft.yaml file is or where is the multipass mount i.e. the idea is to have stable path to base all relative part paths on.
- How to pass .ssh credentials from the host machine to the multipass VM (i.e. adding ssh -A parameter for example)?
- Do we need to build in multipass as root user? Why not to build as multipass or ubuntu or user defined user?