Snapcraft LXC/LXD custom profiles or configuration

I am using snapcraft with --provider lxd option to build my snaps which require some resources from the host, like binding a directory from the host to the LXC container. Because snapcraft doesn’t use LXC profiles for creating its own class of containers, I had to change the default profile and add those configure sections to the containers. But this is not a good practice in general, because it would be applied to all the containers that will not be necessary related to my build environment. I went through the code on GitHub a little bit, and I didn’t notice anywhere that you apply a specific configuration or profile so I can provide one. A workaround is to create the containers manually, apply the profiles, and then the snapcraft will skip the creation, which seems more like a hack to me and obviously is not a stable solution. My request from the snapcraft team is:

  • Provide means to apply LXC profiles that are for example provided in the snap directory of the project. So the snapcraft should check if a file like lxc.config is in the snap directory of the project, and if it’s the case, then apply this config by creating a profile or directly to the container. Another option would be to pass a list of profiles in an environment variable like SNAPCRAFT_LXC_PROFILES as a comma-separated list, and then call lxc assign to apply these profiles to the builder containers directly, then delegate the task of populating the profiles to the users. I suppose the second solution could be applied in few lines of the code.
  • The same feature for Multipass would also be great. In general I’m not familiar with how you can edit the Multipass configurations as it is with LXC profiles, so I cannot use them with my project at all or give you comments on how you can possibly make this feature.
1 Like

We have some work ongoing to support LXD projects (https://linuxcontainers.org/lxd/docs/master/projects). Once available, I think you may be able to use custom-configured project for Snapcraft to launch new instances with the desired configuration.

Do you think that would address your particular use case?

1 Like

Thanks for your rapid response. This would be even better than what I’ve expected. Would you please let me know how I can track the status of this feature, so when it’s available, I could add it directly to my projects. Also, do you have something similar planned for Multipass, or I should stick with LXD and encourage the users of my project to just use LXD as the build provider?