Snapcraft configuration of multipass VM arguments?


I’m building a snap that has rather intense memory requirements (JVM application, gradle build). It’s a core18 snap so the build is running in a multipass VM. It occasionally fails due to running out of memory in the VM.

Is there a way to pass parameters through to multipass so I can give the build more memory?


You can launch it by hand, as long as it has the right name snapcraft runs with it.
The project directory is bind-mounted (use multipass mount), and it needs snapcraft and multipass installed (use multipass shell). I think that’s about it.


You can also use the SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY variable. It’s undocumented, but _CPU and _DISK are also available.


That’s exactly what I needed, thanks!

Launching a VM.
'SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY' was set to '8G' in the environment. Changing the default allocation upon user request


I tried using this SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY=8G env var, but I don’t see the message @cmars indicated, just Launching a VM - and it doesn’t appear to have any effect. Is this still [un]supported? Is there an alternative?


Hey @jungd-yii, are you sure you’re setting it right? Nothing changed to that code in 5 months. Can you show us a bit of your console log where you’re setting the variable and then how snapcraft reacts to it?


@Saviq I figured it out. Seems it is only applied when a new VM is created. Just running snapcraft doesn’t change it. As a new snapcraft user (given Snaps are supposed to be “easy”), I had to go and learn about what multipass is, how to use that command to stop the VM. However, that didn’t work either. So, I had to delete the VM - but that just causes snapcraft to complain the VM is delete and suggest purging it (not sure why it couldn’t have done that itself). After purging the deleted multipass VM and re-running, it does indeed take the parameter. Bit of a minefield for new users (- especially since initially I’d just killed the qemu process and then was faced with figuring out how to re-start the multipass daemon, which I could never figure out and just had to reboot my host machine). Thanks for your response though.


@jungd-yii there’s some rough edges for sure. Know that snapcraft clean would kill the instance for you, also snap restart multipass is how you restart snap services. Glad you got it going.


Also set the SNAPCRAFT_BUILD_ENVIRONMENT=managed-host environment variable.


We probably should delete and recreate the VM if the parameters don’t match…?


I believe --destructive-mode is the supported equivalent of that.

Yeah that makes sense. Care to file a bug for snapcraft?


Isn’t that equivalent to SNAPCRAFT_BUILD_ENVIRONMENT=host instead?

Sure: Bug #1822265 “SNAPCRAFT_BUILD_ENVIRONMENT_* change doesn’t apply to existing VM” : Bugs : Snapcraft


I created this bug because some software needs more than 2GiB of memory to be built and there is no way to specify that via some kind of metadata.

With --use-lxd it might be less of a problem if a container is not limited in terms of RAM allocation, however, OOM killer might decide to kill host OS processes.