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?

share|improve this question
    
Could you try Proxy Configuration from this ref insights.ubuntu.com/2016/03/16/… – user.dz Apr 20 '17 at 14:38
1  
@user.dz Unless I'm mistaken that's configuration for the LXD daemon, not for the LXD containers. At any rate, I installed apt-cacher-ng and set it as the proxy according to those instances, but a new run of snapcraft cleanbuild isn't using it (apt-cacher-ng has no changes in logs or in the cache dir) – muru Apr 20 '17 at 15:13
1  
(The configuration did take effect: a-c-ng doesn't like HTTPS CONNECT requests and I had to unset the HTTPS proxy setting before LXD started working again.) – muru Apr 20 '17 at 15:15
1  
Here's a nice article which details how you can use a package proxy on the host computer, and configure lxd to use that. – popey May 15 '17 at 11:01
1  
@popey thanks! Would you write an answer summarizing that? I used environment.http_proxy instead of user.user-data/apt, and a more general squid/apt-cacher-ng proxy instead of squid-deb-proxy, but the core idea is there – muru May 18 '17 at 19:06
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.