launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #28686
[Merge] ~cjwatson/launchpad-buildd:snap-log-sha512 into launchpad-buildd:master
Colin Watson has proposed merging ~cjwatson/launchpad-buildd:snap-log-sha512 into launchpad-buildd:master.
Commit message:
Log SHA-512 hash of built snaps
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1979844 in launchpad-buildd: "Allow verifying that a snap recipe build corresponds to a store revision"
https://bugs.launchpad.net/launchpad-buildd/+bug/1979844
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/425729
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:snap-log-sha512 into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index 4256c57..8b90a45 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,7 @@ launchpad-buildd (216) UNRELEASED; urgency=medium
[ Colin Watson ]
* Add a timeout when revoking proxy tokens.
+ * Log SHA-512 hash of built snaps (LP: #1979844).
-- Andrey Fedoseev <andrey.fedoseev@xxxxxxxxxxxxx> Mon, 27 Jun 2022 12:32:05 +0500
diff --git a/lpbuildd/target/build_snap.py b/lpbuildd/target/build_snap.py
index 5fdfcc8..751bb61 100644
--- a/lpbuildd/target/build_snap.py
+++ b/lpbuildd/target/build_snap.py
@@ -187,10 +187,13 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
env["SNAPCRAFT_BUILD_ENVIRONMENT"] = "host"
if self.args.target_architectures:
env["SNAPCRAFT_BUILD_TO"] = self.args.target_architectures[0]
- self.run_build_command(
- ["snapcraft"],
- cwd=os.path.join("/build", self.args.name),
- env=env)
+ output_path = os.path.join("/build", self.args.name)
+ self.run_build_command(["snapcraft"], cwd=output_path, env=env)
+ for entry in sorted(self.backend.listdir(output_path)):
+ if self.backend.islink(os.path.join(output_path, entry)):
+ continue
+ if entry.endswith(".snap"):
+ self.run_build_command(["sha512sum", entry], cwd=output_path)
def run(self):
try:
diff --git a/lpbuildd/target/tests/test_build_snap.py b/lpbuildd/target/tests/test_build_snap.py
index c625abe..644a2c2 100644
--- a/lpbuildd/target/tests/test_build_snap.py
+++ b/lpbuildd/target/tests/test_build_snap.py
@@ -47,6 +47,19 @@ class FakeRevisionID(FakeMethod):
return "%s\n" % self.revision_id
+class FakeSnapcraft(FakeMethod):
+
+ def __init__(self, backend, name):
+ super().__init__()
+ self.backend = backend
+ self.name = name
+
+ def __call__(self, run_args, *args, **kwargs):
+ super().__call__(run_args, *args, **kwargs)
+ if run_args[0] == "snapcraft" and "cwd" in kwargs:
+ self.backend.add_file(os.path.join(kwargs["cwd"], self.name), b"")
+
+
class TestBuildSnap(TestCase):
def test_install_bzr(self):
@@ -393,12 +406,16 @@ class TestBuildSnap(TestCase):
"--branch", "lp:foo", "test-snap",
]
build_snap = parse_args(args=args).operation
+ build_snap.backend.run = FakeSnapcraft(
+ build_snap.backend, "test-snap_1.snap")
build_snap.build()
self.assertThat(build_snap.backend.run.calls, MatchesListwise([
RanBuildCommand(
["snapcraft"], cwd="/build/test-snap",
SNAPCRAFT_BUILD_INFO="1", SNAPCRAFT_IMAGE_INFO="{}",
SNAPCRAFT_BUILD_ENVIRONMENT="host"),
+ RanBuildCommand(
+ ["sha512sum", "test-snap_1.snap"], cwd="/build/test-snap"),
]))
def test_build_proxy(self):
@@ -410,6 +427,8 @@ class TestBuildSnap(TestCase):
"test-snap",
]
build_snap = parse_args(args=args).operation
+ build_snap.backend.run = FakeSnapcraft(
+ build_snap.backend, "test-snap_1.snap")
build_snap.build()
env = {
"SNAPCRAFT_BUILD_INFO": "1",
@@ -423,6 +442,8 @@ class TestBuildSnap(TestCase):
}
self.assertThat(build_snap.backend.run.calls, MatchesListwise([
RanBuildCommand(["snapcraft"], cwd="/build/test-snap", **env),
+ RanBuildCommand(
+ ["sha512sum", "test-snap_1.snap"], cwd="/build/test-snap"),
]))
def test_build_private(self):
@@ -432,11 +453,15 @@ class TestBuildSnap(TestCase):
"--branch", "lp:foo", "--private", "test-snap",
]
build_snap = parse_args(args=args).operation
+ build_snap.backend.run = FakeSnapcraft(
+ build_snap.backend, "test-snap_1.snap")
build_snap.build()
self.assertThat(build_snap.backend.run.calls, MatchesListwise([
RanBuildCommand(
["snapcraft"], cwd="/build/test-snap",
SNAPCRAFT_IMAGE_INFO="{}", SNAPCRAFT_BUILD_ENVIRONMENT="host"),
+ RanBuildCommand(
+ ["sha512sum", "test-snap_1.snap"], cwd="/build/test-snap"),
]))
def test_build_including_build_request_id(self):
@@ -446,6 +471,8 @@ class TestBuildSnap(TestCase):
"--build-request-id", "13", "--branch", "lp:foo", "test-snap",
]
build_snap = parse_args(args=args).operation
+ build_snap.backend.run = FakeSnapcraft(
+ build_snap.backend, "test-snap_1.snap")
build_snap.build()
self.assertThat(build_snap.backend.run.calls, MatchesListwise([
RanBuildCommand(
@@ -453,6 +480,8 @@ class TestBuildSnap(TestCase):
SNAPCRAFT_BUILD_INFO="1",
SNAPCRAFT_IMAGE_INFO='{"build-request-id": "lp-13"}',
SNAPCRAFT_BUILD_ENVIRONMENT="host"),
+ RanBuildCommand(
+ ["sha512sum", "test-snap_1.snap"], cwd="/build/test-snap"),
]))
def test_build_including_build_request_timestamp(self):
@@ -463,6 +492,8 @@ class TestBuildSnap(TestCase):
"--branch", "lp:foo", "test-snap",
]
build_snap = parse_args(args=args).operation
+ build_snap.backend.run = FakeSnapcraft(
+ build_snap.backend, "test-snap_1.snap")
build_snap.build()
self.assertThat(build_snap.backend.run.calls, MatchesListwise([
RanBuildCommand(
@@ -471,6 +502,8 @@ class TestBuildSnap(TestCase):
SNAPCRAFT_IMAGE_INFO=(
'{"build-request-timestamp": "2018-04-13T14:50:02Z"}'),
SNAPCRAFT_BUILD_ENVIRONMENT="host"),
+ RanBuildCommand(
+ ["sha512sum", "test-snap_1.snap"], cwd="/build/test-snap"),
]))
def test_build_target_architectures(self):