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 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
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.
Integration with other systems, such as continuous integration, may require setting Launchpad credentials. These are stored in
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.