iso/container held five media while the catalog advertised retention_per_variant 3: publish-container-runner.py only appends a version, and publish-hardware.py carried the whole tree into every new generation without pruning. Add prune_media()/prune_version_records() to publish-hardware.py, use them on the container carry-over and after a container publication, and derive the existing ISO history slice and catalog field from RETENTION_PER_VARIANT instead of a literal. Applied to the live tree: 5 media/13 GB -> 3 media/7.9 GB; removed versions now 404, retained media, aliases and per-version records still serve. Correct the publisher docstring, which still claimed Container Runner has no catalog card.
109 lines
6.2 KiB
Python
109 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Publish a standalone Container Runner build (D-100): refs, signed summary, ISO.
|
|
|
|
This is intentionally separate from `publish-hardware.py`: the Container Runner
|
|
edition has no acceptance scenarios (D-100), but it must still create signed OSTree
|
|
refs, expose its installation medium and append its own ISO catalog card. Existing
|
|
channels (`stable/core`, `stable/gnome`, `stable/kde`) are not modified.
|
|
"""
|
|
import argparse
|
|
import fcntl
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
|
|
spec = importlib.util.spec_from_file_location('publisher', Path(__file__).with_name('publish-hardware.py'))
|
|
publisher = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(publisher)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('public', type=Path)
|
|
parser.add_argument('build', type=Path)
|
|
parser.add_argument('--version', required=True)
|
|
parser.add_argument('--iso', type=Path)
|
|
parser.add_argument('--gpg-home', type=Path, required=True)
|
|
parser.add_argument('--gpg-key', required=True)
|
|
args = parser.parse_args()
|
|
build_repo = args.build / 'repo'
|
|
image = publisher.ostree(build_repo, 'rev-parse', 'core')
|
|
core_layer = publisher.ostree(build_repo, 'rev-parse', 'layers/core')
|
|
purpose_layer = publisher.ostree(build_repo, 'rev-parse', 'layers/purpose/server/container-runner')
|
|
iso = args.iso
|
|
sha256 = publisher.digest(iso) if iso else None
|
|
with (args.public / '.publish.lock').open('a') as lock:
|
|
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
current = (args.public / 'current').resolve(strict=True)
|
|
images, layers = current / 'ostree/images', current / 'ostree/layers'
|
|
publisher.ostree(images, 'pull-local', '--depth=0', str(build_repo), image)
|
|
publisher.ostree(layers, 'pull-local', '--depth=0', str(build_repo), core_layer)
|
|
publisher.ostree(layers, 'pull-local', '--depth=0', str(build_repo), purpose_layer)
|
|
publisher.ostree(images, 'refs', '--force', '--create=stable/container', image)
|
|
publisher.ostree(layers, 'refs', '--force', '--create=stable/container', core_layer)
|
|
publisher.ostree(layers, 'refs', '--force', '--create=purpose/server/container-runner', purpose_layer)
|
|
for repo in (images, layers):
|
|
publisher.ostree(repo, 'prune', '--refs-only', '--depth=0')
|
|
commits = {publisher.ostree(repo, 'rev-parse', ref)
|
|
for ref in publisher.ostree(repo, 'refs').splitlines()}
|
|
for commit in commits:
|
|
publisher.ostree(repo, 'gpg-sign', '--delete', '--gpg-homedir=' + str(args.gpg_home), commit, args.gpg_key)
|
|
publisher.ostree(repo, 'gpg-sign', '--gpg-homedir=' + str(args.gpg_home), commit, args.gpg_key)
|
|
publisher.ostree(repo, 'summary', '--update', '--gpg-sign=' + args.gpg_key,
|
|
'--gpg-homedir=' + str(args.gpg_home))
|
|
record = dict(apiVersion='archipelago.container-runner/v1', version=args.version,
|
|
image_commit=image, layer_commit=core_layer,
|
|
purpose_layer_commit=purpose_layer, sha256=None, size_bytes=None,
|
|
url=None, acceptance='not requested (D-100)')
|
|
if iso:
|
|
name = 'archipelago-container.iso'
|
|
destination = current / 'iso/container' / args.version
|
|
destination.mkdir(parents=True, exist_ok=True)
|
|
target = destination / name
|
|
shutil.copyfile(iso, target)
|
|
if publisher.digest(target) != sha256:
|
|
raise ValueError('Copied ISO checksum mismatch')
|
|
(destination / (name + '.sha256')).write_text(sha256 + ' ' + name + '\n')
|
|
for alias_name in (name, 'archipelago-container-runner.iso'):
|
|
alias = current / 'iso' / alias_name
|
|
if alias.exists() or alias.is_symlink():
|
|
alias.unlink()
|
|
os.link(target, alias)
|
|
(current / 'iso' / (alias_name + '.sha256')).write_text(sha256 + ' ' + alias_name + '\n')
|
|
record.update(sha256=sha256, size_bytes=target.stat().st_size,
|
|
url='/archipelago/iso/container/' + args.version + '/' + name)
|
|
(current / 'v1').mkdir(exist_ok=True)
|
|
(current / 'v1/container-runner.json').write_text(json.dumps(record, indent=2) + '\n')
|
|
if iso:
|
|
(current / 'v1/container-runner-iso.json').write_text(json.dumps(record, indent=2) + '\n')
|
|
item = dict(variant='container', architecture='x86_64', channel='stable',
|
|
version=record['version'], sha256=record['sha256'],
|
|
image_commit=record['image_commit'], layer_commit=record['layer_commit'],
|
|
size_bytes=record['size_bytes'], current=True, url=record['url'],
|
|
checksum_url=record['url'] + '.sha256',
|
|
acceptance=record['acceptance'])
|
|
if record.get('purpose_layer_commit'):
|
|
item['purpose_layer_commit'] = record['purpose_layer_commit']
|
|
catalog_path = current / 'v1/releases.json'
|
|
if catalog_path.is_file():
|
|
catalog = json.loads(catalog_path.read_text())
|
|
catalog['releases'] = [entry for entry in catalog.get('releases', [])
|
|
if entry.get('variant') != 'container']
|
|
catalog['releases'].append(item)
|
|
catalog_path.write_text(json.dumps(catalog, indent=2) + '\n')
|
|
detail = current / 'v1/releases/container' / (record['version'] + '.json')
|
|
detail.parent.mkdir(parents=True, exist_ok=True)
|
|
detail.write_text(json.dumps(dict(apiVersion='archipelago.releases/v1', release=item), indent=2) + '\n')
|
|
# D-098 retention: this publisher only ever appends a version, so the
|
|
# media tree and the per-version records are pruned here, after the new
|
|
# version is in place. Without it `iso/container` grew without bound
|
|
# while the catalog still advertised `retention_per_variant` media.
|
|
publisher.prune_media(current / 'iso/container')
|
|
publisher.prune_version_records(current)
|
|
print(json.dumps(record, indent=2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|