Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Publish signed pacman repositories with each release

fbdb3818bc53560d022234c741c539e59c82bc41 · Keenan Nemetz · 14d ago · parent fd86ba87

Publish signed pacman repositories with each release

Build Arch packages with the same nfpm contents, publish one pacman database per architecture, and sign the packages and databases with the release key. repo-add stamps tar entries from the clock, so the databases are repacked with the tag time before signing. The maintainer script becomes post_install/post_upgrade bodies, so it no longer exits the shell. Document pacman-key, SigLevel, installation, and upgrades, and build and verify the Arch tree in CI.

scripts/build-package-repos.py +112−19

@@ -1,27 +1,32 @@
1 1 #!/usr/bin/env python3
2 """Turn a release's packages into the repositories apt and dnf read.
2 """Turn a release's packages into the repositories apt, dnf, and pacman read.
3 3
4 4 `vole release attach` publishes a directory tree, and a channel gives one URL
5 5 that follows a release, but neither is a repository on its own: apt reads a flat
6 `Packages` file and the `Release` that hashes it, while dnf reads
7 `repodata/repomd.xml`. This script takes the `.deb` and `.rpm` files the release
8 workflow just built and writes both trees beside them:
6 `Packages` file and the `Release` that hashes it, dnf reads
7 `repodata/repomd.xml`, and pacman reads a per-architecture `vole.db`. This script
8 takes the `.deb`, `.rpm`, and Arch packages the release workflow just built and
9 writes the three trees beside them:
9 10
10 11 dist/apt/ vole_<version>-1_<arch>.deb, Packages, Packages.gz, Release
11 12 dist/yum/ vole-<version>-1.<rpmarch>.rpm, repodata/
13 dist/pacman/<arch>/ vole-<version>-1-<arch>.pkg.tar.zst,
14 vole.db, vole.files, and the packages' .sig files
12 15
13 16 The release attaches `dist`, so the release root keeps the binaries, the SBOM,
14 and SHA256SUMS beside `apt/` and `yum/`. A channel then makes one stable URL:
17 and SHA256SUMS beside `apt/`, `yum/`, and `pacman/`. A channel then makes one
18 stable URL:
15 19
16 deb [trusted=yes] https://host/repo/channels/stable/apt ./
20 deb [signed-by=/etc/apt/keyrings/vole.asc] https://host/repo/channels/stable/apt ./
17 21 baseurl=https://host/repo/channels/stable/yum/
22 Server = https://host/repo/channels/stable/pacman/$arch
18 23
19 Both trees are byte-for-byte reproducible from a tag. `--epoch` is the tag's
20 commit time, and it supplies the `Date` in `Release`, the timestamps in
24 All three trees are byte-for-byte reproducible from a tag. `--epoch` is the
25 tag's commit time, and it supplies the `Date` in `Release`, the timestamps in
21 26 `repomd.xml`, and the copied packages' mtimes, which createrepo_c records as
22 27 each package's file time. The `Packages` stanzas are sorted rather than left in
23 directory order, and `Packages.gz` is written without a filename or clock in its
24 header.
28 directory order, `Packages.gz` is written without a filename or clock in its
29 header, and the pacman databases are repacked with a fixed time and owner.
25 30
26 31 It needs dpkg-dev (dpkg-scanpackages) and createrepo-c (createrepo_c), which the
27 32 release and verify images install. Nothing here signs anything: Vole does not
@@ -33,18 +38,21 @@ import argparse
33 38 import email.utils
34 39 import gzip
35 40 import hashlib
41 import io
36 42 import os
37 43 import shutil
38 44 import subprocess
39 45 import sys
46 import tarfile
40 47 import time
41 48 import xml.etree.ElementTree as ET
42 49 from pathlib import Path
43 50
44 # The architecture names differ between the two formats: nfpm writes Debian's
45 # `amd64` and RPM's `x86_64` for the same build.
51 # The architecture names differ between the formats: nfpm writes Debian's
52 # `amd64`, RPM's `x86_64`, and Arch's `x86_64` for the same build.
46 53 DEB_ARCH = {"amd64": "amd64", "arm64": "arm64"}
47 54 RPM_ARCH = {"amd64": "x86_64", "arm64": "aarch64"}
55 PACMAN_ARCH = {"amd64": "x86_64", "arm64": "aarch64"}
48 56
49 57 REPOMD_NS = {"r": "http://linux.duke.edu/metadata/repo"}
50 58
@@ -124,6 +132,76 @@ def write_apt(apt: Path, debs: list[tuple[Path, str]], epoch: int) -> None:
124 132 (apt / "Release").write_text("\n".join(lines) + "\n", encoding="utf-8")
125 133
126 134
135 def normalize_tar(path: Path, epoch: int) -> None:
136 """Rewrite a repository database with a fixed time, owner, and order.
137
138 repo-add stamps tar entry times from the clock, so two builds of one release
139 differ even when every field in the database is identical. The database is a
140 small tar; rewriting it costs little and makes a rebuild byte-identical.
141 """
142 with tarfile.open(path, "r:gz") as archive:
143 members = []
144 for member in archive.getmembers():
145 data = archive.extractfile(member).read() if member.isfile() else None
146 member.mtime = epoch
147 member.uid = 0
148 member.gid = 0
149 member.uname = ""
150 member.gname = ""
151 members.append((member, data))
152 buffer = io.BytesIO()
153 with tarfile.open(fileobj=buffer, mode="w", format=tarfile.USTAR_FORMAT) as archive:
154 for member, data in sorted(members, key=lambda item: item[0].name):
155 archive.addfile(member, io.BytesIO(data) if data is not None else None)
156 path.write_bytes(gzip.compress(buffer.getvalue(), compresslevel=9, mtime=0))
157
158
159 def write_pacman(pacman: Path, packages: dict[str, list[Path]], epoch: int) -> int:
160 """Write a per-architecture pacman database from the built packages.
161
162 A release signs the packages before this runs, so repo-add records
163 %PGPSIG% and pacman can require it. A local run without the release key has
164 no .sig files; the database is then unsigned, and sign-release.py refuses to
165 sign the database unless every package beside it is signed.
166 """
167 total = 0
168 for arch, sources in packages.items():
169 directory = pacman / arch
170 directory.mkdir(parents=True)
171 for source in sources:
172 signature = source.with_name(source.name + ".sig")
173 shutil.copyfile(source, directory / source.name)
174 (directory / source.name).chmod(0o644)
175 os.utime(directory / source.name, (epoch, epoch))
176 if signature.is_file():
177 shutil.copyfile(signature, directory / signature.name)
178 (directory / signature.name).chmod(0o644)
179 # repo-add writes vole.db.tar.gz and vole.files.tar.gz and points the
180 # names pacman requests at them with symlinks. Vole's artifact walker
181 # publishes regular files only, so the databases become real files.
182 subprocess.run(
183 ["repo-add", "--quiet", "--nocolor", "vole.db.tar.gz",
184 *[source.name for source in sources]],
185 cwd=directory,
186 check=True,
187 )
188 for name, entry in (("vole.db", "desc"), ("vole.files", "files")):
189 source = directory / (name + ".tar.gz")
190 target = directory / name
191 if not source.is_file():
192 sys.exit(f"repo-add produced no {name}.tar.gz in {directory}")
193 if target.is_symlink() or target.exists():
194 target.unlink()
195 shutil.copyfile(source, target)
196 source.unlink()
197 normalize_tar(target, epoch)
198 with tarfile.open(target, "r:gz") as archive:
199 if not any(member.name.endswith("/" + entry) for member in archive.getmembers()):
200 sys.exit(f"{target} has no {entry} entry")
201 total += len(sources)
202 return total
203
204
127 205 def write_yum(yum: Path, epoch: int) -> None:
128 206 """Write repodata for an RPM repository with a pinned revision and clock."""
129 207 subprocess.run(
@@ -155,7 +233,7 @@ def write_yum(yum: Path, epoch: int) -> None:
155 233 def main() -> None:
156 234 parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
157 235 parser.add_argument("--dist", default="dist", help="directory holding the built packages (default: dist)")
158 parser.add_argument("--version", required=True, help="release version without the leading v, as nfpm was given it")
236 parser.add_argument("--version", required=True, help="release version without the leading v; the Arch form is derived from it")
159 237 parser.add_argument(
160 238 "--epoch",
161 239 type=int,
@@ -172,21 +250,29 @@ def main() -> None:
172 250 args = parser.parse_args()
173 251 architectures = args.architectures or sorted(DEB_ARCH)
174 252
175 for tool in ("dpkg-scanpackages", "createrepo_c"):
253 for tool, package in (
254 ("dpkg-scanpackages", "dpkg-dev"),
255 ("createrepo_c", "createrepo-c"),
256 ("repo-add", "pacman-package-manager"),
257 ("bsdtar", "libarchive-tools"),
258 ):
176 259 if shutil.which(tool) is None:
177 260 sys.exit(
178 261 f"{tool} is not installed; the workflow images carry "
179 "dpkg-dev and createrepo-c, which provide both tools"
262 f"{package}, which provides it"
180 263 )
181 264
182 265 dist = Path(args.dist).resolve()
183 266 if not dist.is_dir():
184 267 sys.exit(f"{args.dist} is not a directory")
185 # nfpm rewrites a prerelease hyphen to a tilde for both formats, so a tag
186 # v0.3.0-rc1 builds vole_0.3.0~rc1-1_amd64.deb.
268 # nfpm rewrites a prerelease hyphen to a tilde for Debian and RPM, so a tag
269 # v0.3.0-rc1 builds vole_0.3.0~rc1-1_amd64.deb. Arch's pkgver cannot carry
270 # that hyphen, so the same tag builds vole-0.3.0rc1-1-x86_64.pkg.tar.zst.
187 271 package_version = args.version.replace("-", "~")
272 pacman_version = args.version.replace("-", "")
188 273 apt = dist / "apt"
189 274 yum = dist / "yum"
275 pacman = dist / "pacman"
190 276
191 277 # A package missing here would publish a repository that cannot install the
192 278 # release on the architecture it names, and a tag cannot be rebuilt.
@@ -198,12 +284,17 @@ def main() -> None:
198 284 dist / f"vole-{package_version}-1.{RPM_ARCH[arch]}.rpm"
199 285 for arch in architectures
200 286 ]
287 pacman_packages = {
288 PACMAN_ARCH[arch]: [dist / f"vole-{pacman_version}-1-{PACMAN_ARCH[arch]}.pkg.tar.zst"]
289 for arch in architectures
290 }
201 291 missing = [str(path) for path, _ in deb_sources if not path.is_file()]
202 292 missing += [str(path) for path in rpm_sources if not path.is_file()]
293 missing += [str(path) for paths in pacman_packages.values() for path in paths if not path.is_file()]
203 294 if missing:
204 295 sys.exit("the packages for this release are not in " + args.dist + ":\n " + "\n ".join(missing))
205 296
206 for directory in (apt, yum):
297 for directory in (apt, yum, pacman):
207 298 if directory.is_dir():
208 299 shutil.rmtree(directory)
209 300 directory.mkdir(parents=True)
@@ -225,10 +316,12 @@ def main() -> None:
225 316
226 317 write_apt(apt, debs, args.epoch)
227 318 write_yum(yum, args.epoch)
319 pacman_count = write_pacman(pacman, pacman_packages, args.epoch)
228 320
229 321 print(
230 322 f"apt: {len(debs)} package(s) in {apt}\n"
231 f"yum: {len(architectures)} package(s) in {yum}"
323 f"yum: {len(architectures)} package(s) in {yum}\n"
324 f"pacman: {pacman_count} package(s) in {pacman}"
232 325 )
233 326
234 327