9

snapcraft cleanbuild is supposed to let me build snaps in clean-room environments. Accordingly it starts from a minimal LXD image and installs necessary packages. However, it seems to use the base archive.ubuntu.com mirror, which is excruciatingly slow. How do I cache the packages it download?

I could set up apt-cacher-ng or another caching proxy, but there's still the problem of getting the snap/LXD combination to use it. It would be best if it had an internal cache like pbuilder does, but if not, then how do I convince it use a different mirror or a proxy for the mirror?

muru
  • 207,228

1 Answers1

1

The basic principles as outlined in popey's suggestion work:

  1. Set up a caching proxy on the host (or elsewhere, depending on your preferences, I'll assume host): apt-cacher-ng, squid-deb-proxy or squid itself.
  2. Get the host IP address (as seen by the container):

    export LXD_ADDRESS=$(ip -4 -o address show dev lxdbr0 | awk -F'[ /]*' '{print $4}')
    
  3. Use it to set the default profile proxy settings:

    printf '%s\n' '#cloud-config' 'apt:' " proxy: http://$LXD_ADDRESS:8000" |
      lxc profile set default user.user-data -
    
  4. Success!

However, there are a couple of caveats.

snapcraft cleanbuild downloads a lot of packages by some other mechanism than the usual apt-get, which isn't affected by this configuration. This insanity is seen in this part of the output:

Preparing to pull glue
Pulling glue
Preparing to pull cassandra
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
...
Get:46 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3004 B]
Fetched 26.0 MB in 6s (4237 kB/s)
Get:1 ca-certificates-java_20160321_all.deb [12.9 kB]
Fetched 12.9 kB in 0s (0 B/s)
Get:1 libxdmcp6_1.1.2-1.1_amd64.deb [11.0 kB]
Fetched 11.0 kB in 0s (0 B/s)
Get:1 init-system-helpers_1.29ubuntu4_all.deb [32.3 kB]
Fetched 32.3 kB in 0s (0 B/s)
Get:1 default-jre-headless_1.8-56ubuntu2_amd64.deb [4380 B]
Fetched 4380 B in 0s (0 B/s)
Get:1 default-jdk_1.8-56ubuntu2_amd64.deb [968 B]
Fetched 968 B in 0s (0 B/s)
Get:1 libkrb5-3_1.13.2+dfsg-5ubuntu2_amd64.deb [273 kB]

There are quite a few of these, and the individual requests make them slow as hell anyway, and that's not counting that that the apt proxy settings set earlier don't affect them.

So, I set the http_proxy environment variable instead:

lxc profile set default environment.http_proxy "http://$LXD_ADDRESS:3128"

And similarly for HTTPS, since some other downloads in the container used HTTPS. I usually prefer apt-cacher-ng, but it doesn't support HTTPS CONNECT, so I switched to squid.

muru
  • 207,228