Speed up cleanbuild

Is there a way to speed up cleanbuild? Every time I test a snap, it takes some time to install deps, etc. Or is there a better way to do test builds without polluting the parent system?

Thanks!

Check Per project containers out :slight_smile:

3 Likes

Thanks a ton! Will look into that!

Note that you can also just create a new lxc container and install snapcraft in there. You can even make a profile to preinstall snapcraft. For example, assuming your new profile name is “snapcraft”:

  1. Start with the default profile

     $ lxc profile copy default snapcraft
    
  2. Modify it to preinstall snapcraft (this uses cloud-init):

     $ echo -e "#cloud-config\npackages: [snapcraft]" | lxc profile set snapcraft user.user-data -
    

    Note that you can see the results with lxc profile show snapcraft. Mine looks like this:

     config:
       user.user-data: |
         #cloud-config
         packages: [snapcraft]
     description: ""
     devices:
       eth0:
         name: eth0
         nictype: bridged
         parent: lxdbr0
         type: nic
     name: snapcraft
    

Now you can create containers with snapcraft preinstalled like so:

$ lxc launch ubuntu:xenial -p snapcraft

This is what I do to hack on a new snap, or help someone out with theirs. Sometimes I’ll even make them ephemeral so they disappear when I turn them off:

$ lxc launch ubuntu:xenial -e -p snapcraft

This is similar to what I was originally going to do before learning about cleanbuild. Was considering mounting a drive so that I can edit my yaml in my fav text editor.

I do that occasionally as well, but then you run into needing either a privileged container or uid mapping.

Good point. I’m actually just going to look into the ssh-import-id as well.

Hmm I get neither key or package.

So I’ll plug on that and then get the snapcraft pkg in there. Makes sense. appreciated.

config:
  user.user-data: |
    packages: [snapcraft]
  user.vendor-data: |
    users:
      - name: root
      ssh-import-id: gh:bashfulrobot
      shell: /bin/bash
description: Default LXD profile
devices:
  eth0:
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default

Hey all,

Just popping back on this, but with a different take. I seem to remember reading (or maybe even asking) that cleanbuild now had an option to reuse and existing container. Am I remembering this correctly? I have been poking around and have not (yet) found anything definitive.

Thank you all for your time.

I don’t think that is the case, what you have is from @Saviq’s reply related to using persistent build containers to pass through snapcraft commands (orthogonal to cleanbuild)

1 Like