Snapcraft configuration of multipass VM arguments?


#1

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?


#2

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.


#3

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


#4

That’s exactly what I needed, thanks!

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

#5

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?


#6

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?


#7

@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.


#8

@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.


#9

Also set the SNAPCRAFT_BUILD_ENVIRONMENT=managed-host environment variable.


#10

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


#11

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

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


#12

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


#13

I created this bug https://bugs.launchpad.net/snapcraft/+bug/1842376 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.