Preview: Snapcraft remote build


#1

An often requested feature for Snapcraft is the ability to build snaps for foreign architectures directly from the command line. This is because the currently available web-based tools aren’t appropriate to every situation, and not everyone has the hardware needed to build native ARM binaries (for example).

This preview of remote building provides this functionality, allowing you to effortlessly target multiple architectures available in the Snap Store from any system capable of running Snapcraft. You can test it now from the beta/remote-build branch of Snapcraft.

This is what it looks like in action:

$ snapcraft remote-build --arch=arm64,armhf
snapcraft remote-build is offered as a preview. Authentication and transport mechanisms will change in future releases. Use with caution in scripts.
All data sent to remote builders is public. Are you sure you want to continue? [y/N]: y
Sending data to remote builder...
Building package for arm64 and armhf. This may take some time to finish.
If interrupted, resume with: 'snapcraft remote-build --recover 49111050'
Snapped figlet_2.2.5+git.b61ba79_arm64.snap
Snapped figlet_2.2.5+git.b61ba79_armhf.snap
Build complete.

As this release is a preview, a few extra steps are currently required to set up your environment, and there’s one important caveat: the project code sent to remote build will be public on Launchpad. Your code can be removed afterwards, but for now, remote building should only be used on projects where public availability won’t cause an issue.

Setting up the system

You will need a Launchpad account with a registered SSH public key to use remote build with this preview release.

If you don’t have an account, head over to Launchpad and click ‘Register’. You will then be able to login and add a pre-existing SSH public key, or follow the instructions on Launchpad’s Creating an SSH key page to create one as needed.

When you have a Launchpad account and a properly associated SSH public key, you can use snapcraft remote-build to build a project.

Using remote build

Snapcraft will first need to authorize access to the Launchpad account when remote build is run for the first time. It does this by opening a web page when running the snapcraft command:

$ snapcraft remote-build --user <your launchpad id>
snapcraft remote-build is offered as a preview. Authentication and transport mechanisms will change in future releases. Use with caution in scripts.
All data sent to remote builders is public. Are you sure you want to continue? [y/N]: y
Sending data to remote builder...
The authorization page: (https://launchpad.net/+authorize-token?oauth_token=...&allow_permission=DESKTOP_INTEGRATION)
should be opening in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.
Waiting to hear from Launchpad about your decision...

With Snapcraft properly authorized, the project is dispatched for remote build. Snapcraft will wait for the build to complete before retrieving the resultant snaps. The build time depends on the target architecture, the package size, and the availability of builder back-ends.

Building package. This may take some time to finish.
If interrupted, resume with: 'snapcraft remote-build --recover 49112457'
Snapped my-snap-name_0.1_amd64.snap
Snapped my-snap-name_0.1_i386.snap
Build complete.

If an architecture is not specified, snapcraft remote-build will default to amd64 and i386. Specific architectures can be listed in the snapcraft.yaml file, or passed as an argument to the --arch command line option. To build for all available architectures, use --arch=all.

When the code is on a local git repository

If the prospective build code is in a git repository, the --git option can be used to send the current branch HEAD instead of your working tree. This allows Snapcraft to correctly use git hashes when specifying version: 'git' in the snapcraft.yaml. Any uncommitted changes will be ignored.

Launchpad credentials

Integration with other systems, such as continuous integration, may require setting Launchpad credentials. These are stored in $HOME/.local/share/snapcraft/launchpad/credentials.

Future improvements

As mentioned in the command output, authentication and transport mechanisms will be changed for the final release and won’t require SSH keys to be registered on Launchpad.


Snap build fails to find required plugin
#2

Worth noting you can keep an eye on the build in a browser by visiting launchpad.net -> login -> click your name in the top right (or visit launchpad . net / ~your_lp_id ) -> scroll down and click “View snap packages”. The build will be at the top of the list. Click through to find the build logs.

e.g.

Click through to see the status…


#3

https://launchpad.net/~/+snaps

Or just click there, which will Do The Right Thing :tm:


#4

I encounter several errors that aren’t caused by build failure:

Priming desktop-qt5 
Priming launchers 
Priming patching 
Priming selective-checkout 
Priming main 
sed --file /build/snapcraft-fe18a192c056412982c7e9eba40d9ca0/stage/patching/patch-desktop-entries.sed --in-place share/applications/featherpad.desktop 
Priming scriptlets 
Snapping 'featherpad' ...

Snapped featherpad_0.10.0+pkg-8c14_ppc64el.snap
Revoking proxy token...
Failed to gather results: execv() arg 2 must contain only stringsRUN: /usr/share/launchpad-buildd/bin/in-target scan-for-processes --backend=lxd --series=bionic --arch=ppc64el SNAPBUILD-580422
Scanning for processes to kill in build SNAPBUILD-580422

Log: https://launchpad.net/~buo-ren-lin/+snap/snapcraft-fe18a192c056412982c7e9eba40d9ca0/+build/580422/+files/buildlog_snap_ubuntu_bionic_ppc64el_snapcraft-fe18a192c056412982c7e9eba40d9ca0_BUILDING.txt.gz

Can anyone check it out? /cc @cjwatson


#5

Please file this as a launchpad-buildd bug, and we’ll take it from there.


#6

Issue filed at https://bugs.launchpad.net/launchpad-buildd/+bug/1832072, apologies for any nuisance I might have caused.