← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad-buildd/snap-image-info into lp:launchpad-buildd

 

Colin Watson has proposed merging lp:~cjwatson/launchpad-buildd/snap-image-info into lp:launchpad-buildd.

Commit message:
Pass build URL to snapcraft using SNAPCRAFT_IMAGE_INFO.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/snap-image-info/+merge/341806

This is needed to improve supportability/auditability of seeded snaps.

See https://github.com/snapcore/snapcraft/pull/1997.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad-buildd/snap-image-info into lp:launchpad-buildd.
=== modified file 'debian/changelog'
--- debian/changelog	2018-02-04 00:16:23 +0000
+++ debian/changelog	2018-03-21 09:19:54 +0000
@@ -5,6 +5,7 @@
     won't start any of them, including snapd itself, if any of them is
     forbidden.  Mask snapd.refresh.timer so that it doesn't cause trouble.
   * Allow optionally installing snapcraft as a snap (LP: #1737994).
+  * Pass build URL to snapcraft using SNAPCRAFT_IMAGE_INFO.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Fri, 02 Feb 2018 16:14:46 +0000
 

=== modified file 'lpbuildd/snap.py'
--- lpbuildd/snap.py	2018-02-04 00:16:23 +0000
+++ lpbuildd/snap.py	2018-03-21 09:19:54 +0000
@@ -39,6 +39,7 @@
         """Initiate a build with a given set of files and chroot."""
         self.name = extra_args["name"]
         self.channels = extra_args.get("channels", {})
+        self.build_url = extra_args.get("build_url")
         self.branch = extra_args.get("branch")
         self.git_repository = extra_args.get("git_repository")
         self.git_path = extra_args.get("git_path")
@@ -73,6 +74,8 @@
                 "Channels requested for unknown snaps: %s" %
                 " ".join(sorted(unknown_snaps)),
                 file=sys.stderr)
+        if self.build_url:
+            args.extend(["--build-url", self.build_url])
         if self.proxy_url:
             args.extend(["--proxy-url", self.proxy_url])
         if self.revocation_endpoint:

=== modified file 'lpbuildd/target/build_snap.py'
--- lpbuildd/target/build_snap.py	2018-02-04 00:16:23 +0000
+++ lpbuildd/target/build_snap.py	2018-03-21 09:19:54 +0000
@@ -56,6 +56,8 @@
             help=(
                 "install snapcraft as a snap from CHANNEL rather than as a "
                 ".deb"))
+        parser.add_argument(
+            "--build-url", help="URL of this build on Launchpad")
         build_from_group = parser.add_mutually_exclusive_group(required=True)
         build_from_group.add_argument(
             "--branch", metavar="BRANCH", help="build from this Bazaar branch")
@@ -183,6 +185,13 @@
                 get_output=True).rstrip("\n")
         self.save_status(status)
 
+    @property
+    def image_info(self):
+        data = {}
+        if self.args.build_url is not None:
+            data["build_url"] = self.args.build_url
+        return json.dumps(data)
+
     def pull(self):
         """Run pull phase."""
         logger.info("Running pull phase...")
@@ -192,6 +201,7 @@
         # XXX cjwatson 2017-11-24: Once we support building private snaps,
         # we'll need to make this optional in some way.
         env["SNAPCRAFT_BUILD_INFO"] = "1"
+        env["SNAPCRAFT_IMAGE_INFO"] = self.image_info
         if self.args.proxy_url:
             env["http_proxy"] = self.args.proxy_url
             env["https_proxy"] = self.args.proxy_url
@@ -208,6 +218,7 @@
         # XXX cjwatson 2017-11-24: Once we support building private snaps,
         # we'll need to make this optional in some way.
         env["SNAPCRAFT_BUILD_INFO"] = "1"
+        env["SNAPCRAFT_IMAGE_INFO"] = self.image_info
         if self.args.proxy_url:
             env["http_proxy"] = self.args.proxy_url
             env["https_proxy"] = self.args.proxy_url

=== modified file 'lpbuildd/target/tests/test_build_snap.py'
--- lpbuildd/target/tests/test_build_snap.py	2018-02-04 00:16:23 +0000
+++ lpbuildd/target/tests/test_build_snap.py	2018-03-21 09:19:54 +0000
@@ -278,6 +278,7 @@
             "SNAPCRAFT_LOCAL_SOURCES": "1",
             "SNAPCRAFT_SETUP_CORE": "1",
             "SNAPCRAFT_BUILD_INFO": "1",
+            "SNAPCRAFT_IMAGE_INFO": "{}",
             }
         self.assertThat(build_snap.backend.run.calls, MatchesListwise([
             RanBuildCommand(
@@ -288,6 +289,7 @@
         args = [
             "buildsnap",
             "--backend=fake", "--series=xenial", "--arch=amd64", "1",
+            "--build-url", "https://launchpad.example/build";,
             "--branch", "lp:foo", "--proxy-url", "http://proxy.example:3128/";,
             "test-snap",
             ]
@@ -297,6 +299,8 @@
             "SNAPCRAFT_LOCAL_SOURCES": "1",
             "SNAPCRAFT_SETUP_CORE": "1",
             "SNAPCRAFT_BUILD_INFO": "1",
+            "SNAPCRAFT_IMAGE_INFO": (
+                '{"build_url": "https://launchpad.example/build"}'),
             "http_proxy": "http://proxy.example:3128/";,
             "https_proxy": "http://proxy.example:3128/";,
             "GIT_PROXY_COMMAND": "/usr/local/bin/snap-git-proxy",
@@ -317,13 +321,14 @@
         self.assertThat(build_snap.backend.run.calls, MatchesListwise([
             RanBuildCommand(
                 ["snapcraft"], cwd="/build/test-snap",
-                SNAPCRAFT_BUILD_INFO="1"),
+                SNAPCRAFT_BUILD_INFO="1", SNAPCRAFT_IMAGE_INFO="{}"),
             ]))
 
     def test_build_proxy(self):
         args = [
             "buildsnap",
             "--backend=fake", "--series=xenial", "--arch=amd64", "1",
+            "--build-url", "https://launchpad.example/build";,
             "--branch", "lp:foo", "--proxy-url", "http://proxy.example:3128/";,
             "test-snap",
             ]
@@ -331,6 +336,8 @@
         build_snap.build()
         env = {
             "SNAPCRAFT_BUILD_INFO": "1",
+            "SNAPCRAFT_IMAGE_INFO": (
+                '{"build_url": "https://launchpad.example/build"}'),
             "http_proxy": "http://proxy.example:3128/";,
             "https_proxy": "http://proxy.example:3128/";,
             "GIT_PROXY_COMMAND": "/usr/local/bin/snap-git-proxy",
@@ -346,6 +353,7 @@
         args = [
             "buildsnap",
             "--backend=fake", "--series=xenial", "--arch=amd64", "1",
+            "--build-url", "https://launchpad.example/build";,
             "--branch", "lp:foo", "test-snap",
             ]
         build_snap = parse_args(args=args).operation
@@ -359,10 +367,14 @@
             AnyMatch(RanBuildCommand(
                 ["snapcraft", "pull"], cwd="/build/test-snap",
                 SNAPCRAFT_LOCAL_SOURCES="1", SNAPCRAFT_SETUP_CORE="1",
-                SNAPCRAFT_BUILD_INFO="1")),
+                SNAPCRAFT_BUILD_INFO="1",
+                SNAPCRAFT_IMAGE_INFO=(
+                    '{"build_url": "https://launchpad.example/build"}'))),
             AnyMatch(RanBuildCommand(
                 ["snapcraft"], cwd="/build/test-snap",
-                SNAPCRAFT_BUILD_INFO="1")),
+                SNAPCRAFT_BUILD_INFO="1",
+                SNAPCRAFT_IMAGE_INFO=(
+                    '{"build_url": "https://launchpad.example/build"}'))),
             ))
 
     def test_run_install_fails(self):


Follow ups