Merge ~pappacena/launchpad-buildd:oci-build-arg into launchpad-buildd:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: 3d24c4ccf555e8f20cc7fbb571e50e84803f2e9a
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad-buildd:oci-build-arg
Merge into: launchpad-buildd:master
Diff against target: 161 lines (+71/-2)
5 files modified
README (+28/-0)
lpbuildd/oci.py (+6/-0)
lpbuildd/target/build_oci.py (+11/-0)
lpbuildd/target/tests/test_build_oci.py (+21/-0)
lpbuildd/tests/test_oci.py (+5/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+389869@code.launchpad.net

Commit message

Adding support for --build-arg when building OCI images

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
3d24c4c... by Thiago F. Pappacena

Improving docs and using lpbuildd.util.shell_escape instead of pipes

Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

Pushed the requested changes. This should be good to be landed now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/README b/README
index d2eb28e..05a74c8 100644
--- a/README
+++ b/README
@@ -29,6 +29,34 @@ fakeroot debian/rules clean
29rm launchpad-buildd*deb29rm launchpad-buildd*deb
30rm ../launchpad-buildd*changes30rm ../launchpad-buildd*changes
3131
32
33Developing
34************
35
36First of all, it is recommended that you create a lxc container, since the
37following steps will make changes in your system. And since some build types
38will only work with virtualized containers, creating a lxc vm is the best way
39to go. You can create a container with the following command:
40
41 lxc launch --vm ubuntu:18.04 lp-builddev
42
43Note that you may want to have a profile to share the source code with the
44container before running the above command.
45
46Then, inside the container, install the necessary dependencies:
47
48 sudo apt-get update
49 cat system-dependencies.txt | sudo xargs apt-get install -y
50
51This should be enough for you to be able to run `make check`, which runs the
52test suite both in python2 and python3.
53
54More information on how to integrate it with Launchpad can be found here:
55https://dev.launchpad.net/Soyuz/HowToDevelopWithBuildd
56
57Now, happy coding.
58
59
32Production deployment notes60Production deployment notes
33***************************61***************************
3462
diff --git a/lpbuildd/oci.py b/lpbuildd/oci.py
index 1fccada..480c5d6 100644
--- a/lpbuildd/oci.py
+++ b/lpbuildd/oci.py
@@ -21,6 +21,7 @@ from lpbuildd.debian import (
21 DebianBuildState,21 DebianBuildState,
22 )22 )
23from lpbuildd.snap import SnapBuildProxyMixin23from lpbuildd.snap import SnapBuildProxyMixin
24from lpbuildd.util import shell_escape
2425
2526
26RETCODE_SUCCESS = 027RETCODE_SUCCESS = 0
@@ -49,6 +50,7 @@ class OCIBuildManager(SnapBuildProxyMixin, DebianBuildManager):
49 self.git_repository = extra_args.get("git_repository")50 self.git_repository = extra_args.get("git_repository")
50 self.git_path = extra_args.get("git_path")51 self.git_path = extra_args.get("git_path")
51 self.build_file = extra_args.get("build_file")52 self.build_file = extra_args.get("build_file")
53 self.build_args = extra_args.get("build_args", {})
52 self.build_path = extra_args.get("build_path")54 self.build_path = extra_args.get("build_path")
53 self.proxy_url = extra_args.get("proxy_url")55 self.proxy_url = extra_args.get("proxy_url")
54 self.revocation_endpoint = extra_args.get("revocation_endpoint")56 self.revocation_endpoint = extra_args.get("revocation_endpoint")
@@ -70,6 +72,10 @@ class OCIBuildManager(SnapBuildProxyMixin, DebianBuildManager):
70 args.extend(["--git-path", self.git_path])72 args.extend(["--git-path", self.git_path])
71 if self.build_file is not None:73 if self.build_file is not None:
72 args.extend(["--build-file", self.build_file])74 args.extend(["--build-file", self.build_file])
75 if self.build_args:
76 for k, v in self.build_args.items():
77 args.extend([
78 "--build-arg=%s=%s" % (shell_escape(k), shell_escape(v))])
73 if self.build_path is not None:79 if self.build_path is not None:
74 args.extend(["--build-path", self.build_path])80 args.extend(["--build-path", self.build_path])
75 try:81 try:
diff --git a/lpbuildd/target/build_oci.py b/lpbuildd/target/build_oci.py
index 377fc68..af56671 100644
--- a/lpbuildd/target/build_oci.py
+++ b/lpbuildd/target/build_oci.py
@@ -42,6 +42,11 @@ class BuildOCI(SnapBuildProxyOperationMixin, VCSOperationMixin,
42 parser.add_argument(42 parser.add_argument(
43 "--build-path", default=".",43 "--build-path", default=".",
44 help="context directory for docker build")44 help="context directory for docker build")
45 parser.add_argument(
46 "--build-arg", default=[], action='append',
47 help="A docker build ARG in the format of key=value. "
48 "This option can be repeated many times. For example: "
49 "--build-arg VAR1=A --build-arg VAR2=B")
45 parser.add_argument("name", help="name of snap to build")50 parser.add_argument("name", help="name of snap to build")
4651
47 def __init__(self, args, parser):52 def __init__(self, args, parser):
@@ -127,6 +132,12 @@ class BuildOCI(SnapBuildProxyOperationMixin, VCSOperationMixin,
127 self.args.build_path, self.args.build_file)132 self.args.build_path, self.args.build_file)
128 self._check_path_escape(build_file_path)133 self._check_path_escape(build_file_path)
129 args.extend(["--file", build_file_path])134 args.extend(["--file", build_file_path])
135
136 # Keep this at the end, so we give the user a chance to override any
137 # build-arg we set automatically (like http_proxy).
138 for arg in self.args.build_arg:
139 args.extend(["--build-arg=%s" % arg])
140
130 build_context_path = os.path.join(141 build_context_path = os.path.join(
131 self.buildd_path, self.args.build_path)142 self.buildd_path, self.args.build_path)
132 self._check_path_escape(build_context_path)143 self._check_path_escape(build_context_path)
diff --git a/lpbuildd/target/tests/test_build_oci.py b/lpbuildd/target/tests/test_build_oci.py
index a2c67d7..e58344f 100644
--- a/lpbuildd/target/tests/test_build_oci.py
+++ b/lpbuildd/target/tests/test_build_oci.py
@@ -360,6 +360,27 @@ class TestBuildOCI(TestCase):
360 cwd="/home/buildd/test-image"),360 cwd="/home/buildd/test-image"),
361 ]))361 ]))
362362
363 def test_build_with_args(self):
364 args = [
365 "build-oci",
366 "--backend=fake", "--series=xenial", "--arch=amd64", "1",
367 "--branch", "lp:foo", "--build-file", "build-aux/Dockerfile",
368 "--build-path", "test-build-path",
369 "--build-arg=VAR1=xxx", "--build-arg=VAR2=yyy",
370 "test-image",
371 ]
372 build_oci = parse_args(args=args).operation
373 build_oci.backend.add_dir('/build/test-directory')
374 build_oci.build()
375 self.assertThat(build_oci.backend.run.calls, MatchesListwise([
376 RanBuildCommand(
377 ["docker", "build", "--no-cache", "--tag", "test-image",
378 "--file", "test-build-path/build-aux/Dockerfile",
379 "--build-arg=VAR1=xxx", "--build-arg=VAR2=yyy",
380 "/home/buildd/test-image/test-build-path"],
381 cwd="/home/buildd/test-image"),
382 ]))
383
363 def test_build_proxy(self):384 def test_build_proxy(self):
364 args = [385 args = [
365 "build-oci",386 "build-oci",
diff --git a/lpbuildd/tests/test_oci.py b/lpbuildd/tests/test_oci.py
index f2dd421..6079634 100644
--- a/lpbuildd/tests/test_oci.py
+++ b/lpbuildd/tests/test_oci.py
@@ -183,7 +183,7 @@ class TestOCIBuildManagerIteration(TestCase):
183 self.assertFalse(self.builder.wasCalled("buildFail"))183 self.assertFalse(self.builder.wasCalled("buildFail"))
184184
185 @defer.inlineCallbacks185 @defer.inlineCallbacks
186 def test_iterate_with_file(self):186 def test_iterate_with_file_and_args(self):
187 # This sha would change as it includes file attributes in the187 # This sha would change as it includes file attributes in the
188 # tar file. Fix it so we can test against a known value.188 # tar file. Fix it so we can test against a known value.
189 sha_mock = self.useFixture(189 sha_mock = self.useFixture(
@@ -195,12 +195,15 @@ class TestOCIBuildManagerIteration(TestCase):
195 "git_repository": "https://git.launchpad.dev/~example/+git/snap",195 "git_repository": "https://git.launchpad.dev/~example/+git/snap",
196 "git_path": "master",196 "git_path": "master",
197 "build_file": "build-aux/Dockerfile",197 "build_file": "build-aux/Dockerfile",
198 "build_args": {"VAR1": "xxx", "VAR2": "yyy"}
198 }199 }
199 expected_options = [200 expected_options = [
200 "--git-repository", "https://git.launchpad.dev/~example/+git/snap",201 "--git-repository", "https://git.launchpad.dev/~example/+git/snap",
201 "--git-path", "master",202 "--git-path", "master",
202 "--build-file", "build-aux/Dockerfile",203 "--build-file", "build-aux/Dockerfile",
203 ]204 "--build-arg=VAR1=xxx",
205 "--build-arg=VAR2=yyy",
206 ]
204 yield self.startBuild(args, expected_options)207 yield self.startBuild(args, expected_options)
205208
206 log_path = os.path.join(self.buildmanager._cachepath, "buildlog")209 log_path = os.path.join(self.buildmanager._cachepath, "buildlog")

Subscribers

People subscribed via source and target branches