Merge lp:~tribaal/launchpad-buildd/apt-proxy-injection into lp:launchpad-buildd

Proposed by Chris Glass
Status: Merged
Merged at revision: 323
Proposed branch: lp:~tribaal/launchpad-buildd/apt-proxy-injection
Merge into: lp:launchpad-buildd
Diff against target: 86 lines (+50/-0)
3 files modified
debian/changelog (+6/-0)
lpbuildd/target/build_livefs.py (+10/-0)
lpbuildd/target/tests/test_build_livefs.py (+34/-0)
To merge this branch: bzr merge lp:~tribaal/launchpad-buildd/apt-proxy-injection
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+335742@code.launchpad.net

Description of the change

This branch adds a "--apt-http-proxy" option to the buildlivefs command, injecting the http proxy it specifies into the chroot (by setting the appropriate env).

This allows speeding up local development of cloud images (for example) significantly by setting up a squid-deb-proxy or similar.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Please can you add a test for this? It should be possible to test the new behaviour in lpbuildd/target/tests/test_build_livefs.py.

Aside from the code review comments below, this is probably fine as far as it goes. However, I'd suggest some follow-up work (which could be in a separate branch).

One of my usual local tweaks to launchpad-buildd is to add this to the end of lpbuildd.target.apt.OverrideSourcesList.run:

        self.backend.copy_in(
            "/etc/apt/apt.conf.d/99proxy", "/etc/apt/apt.conf.d/99proxy")

This isn't totally satisfactory for various reasons, but it's been good enough as a local hack.

Now, if we were to polish this up, the most convenient approach would be if there were an item in the buildd's configuration file that gave a proxy URL. lpbuildd.debian.DebianBuildManager.doSourcesList could turn this into an option passed to override-sources-list, which could then inject an apt.conf.d file if that option is set. If we did that, it would make sense for lpbuildd.livefs to look at that same configuration item and pass the --apt-http-proxy option to buildlivefs too (which as it stands you're presumably having to do manually).

review: Needs Fixing
323. By Chris Glass

Addressed review comments:
* Added test
* Fixed style
* Fixed dch version
* Made --http-proxy a simple option (not a list)

Revision history for this message
Chris Glass (tribaal) wrote :

All comments should be addressed.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2017-11-29 14:19:20 +0000
3+++ debian/changelog 2018-01-09 10:54:42 +0000
4@@ -1,3 +1,9 @@
5+launchpad-buildd (158) UNRELEASED; urgency=medium
6+
7+ * Add support for passing apt proxies to the debootstrap/chroot.
8+
9+ -- Christopher Glass (Ubuntu) <tribaal@ubuntu.com> Fri, 05 Jan 2018 12:49:11 +0100
10+
11 launchpad-buildd (157) xenial; urgency=medium
12
13 [ Colin Watson ]
14
15=== modified file 'lpbuildd/target/build_livefs.py'
16--- lpbuildd/target/build_livefs.py 2017-11-13 16:07:55 +0000
17+++ lpbuildd/target/build_livefs.py 2018-01-09 10:54:42 +0000
18@@ -58,6 +58,9 @@
19 "--extra-ppa", dest="extra_ppas", default=[], action="append",
20 help="use this additional PPA")
21 parser.add_argument(
22+ "--http-proxy", default="", action="store",
23+ help="use this http proxy for apt.")
24+ parser.add_argument(
25 "--debug", default=False, action="store_true",
26 help="enable detailed live-build debugging")
27
28@@ -127,6 +130,13 @@
29 lb_env["PROPOSED"] = "1"
30 if self.args.extra_ppas:
31 lb_env["EXTRA_PPAS"] = " ".join(self.args.extra_ppas)
32+ if self.args.http_proxy:
33+ proxy_dict = {
34+ "http_proxy": self.args.http_proxy,
35+ "LB_APT_HTTP_PROXY": self.args.http_proxy
36+ }
37+ lb_env.update(proxy_dict)
38+ base_lb_env.update(proxy_dict)
39 self.run_build_command(["lb", "config"], env=lb_env)
40 self.run_build_command(["lb", "build"], env=base_lb_env)
41
42
43=== modified file 'lpbuildd/target/tests/test_build_livefs.py'
44--- lpbuildd/target/tests/test_build_livefs.py 2017-11-10 20:55:33 +0000
45+++ lpbuildd/target/tests/test_build_livefs.py 2018-01-09 10:54:42 +0000
46@@ -184,6 +184,40 @@
47 RanBuildCommand(["lb", "build"], PROJECT="ubuntu", ARCH="amd64"),
48 ]))
49
50+ def test_build_with_http_proxy(self):
51+ proxy = "http://example.com:8000"
52+ expected_env = {"PROJECT": "ubuntu-cpc",
53+ "ARCH": "amd64",
54+ "http_proxy": proxy,
55+ "LB_APT_HTTP_PROXY": proxy,
56+ }
57+ args = [
58+ "buildlivefs",
59+ "--backend=fake", "--series=xenial", "--arch=amd64",
60+ "--project=ubuntu-cpc",
61+ "--http-proxy={}".format(proxy), "1"
62+ ]
63+ build_livefs = parse_args(args=args).operation
64+ build_livefs.build()
65+ self.assertThat(build_livefs.backend.run.calls, MatchesListwise([
66+ RanBuildCommand(["rm", "-rf", "auto", "local"]),
67+ RanBuildCommand(["mkdir", "-p", "auto"]),
68+ RanBuildCommand(
69+ ["ln", "-s",
70+ "/usr/share/livecd-rootfs/live-build/auto/config", "auto/"]),
71+ RanBuildCommand(
72+ ["ln", "-s",
73+ "/usr/share/livecd-rootfs/live-build/auto/build", "auto/"]),
74+ RanBuildCommand(
75+ ["ln", "-s",
76+ "/usr/share/livecd-rootfs/live-build/auto/clean", "auto/"]),
77+ RanBuildCommand(["lb", "clean", "--purge"]),
78+ RanBuildCommand(
79+ ["lb", "config"],
80+ SUITE="xenial", **expected_env),
81+ RanBuildCommand(["lb", "build"], **expected_env),
82+ ]))
83+
84 def test_run_succeeds(self):
85 args = [
86 "buildlivefs",

Subscribers

People subscribed via source and target branches