conductor/scripts/build-upgrade-test-fixtures.py

21 lines
1.7 KiB
Python

"""Build test-only images; never modifies the archived kit or project source."""
import pathlib,subprocess,tarfile,tempfile,hashlib,json,shutil
ROOT=pathlib.Path(__file__).resolve().parent.parent
archive=ROOT.parent/'social-scheduler/release/social-scheduler-0.4.0.tar.gz'
node=shutil.which('node')
if not node:raise SystemExit('Use the developer Node.js 24 environment; the disposable VM itself needs no Node.js.')
if not archive.is_file():raise SystemExit('The original Social Scheduler 0.4.0 archive is required for the faithful legacy test.')
subprocess.run(['docker','build','-f',str(ROOT/'scripts/fixtures/slice12/Dockerfile'),'-t','conductor:slice12-test-host',str(ROOT/'scripts/fixtures/slice12')],check=True)
with tempfile.TemporaryDirectory(prefix='conductor-legacy-fixture-') as temporary:
with tarfile.open(archive) as tar:
for member in tar:
p=pathlib.PurePosixPath(member.name)
if p.is_absolute() or '..' in p.parts or not(member.isfile() or member.isdir()):raise SystemExit('Unsafe legacy archive.')
tar.extractall(temporary)
kit=pathlib.Path(temporary)/'social-scheduler'
subprocess.run([node,'scripts/build-conductor-copy.mjs','vendor/conductor'],cwd=kit,check=True)
context=kit/'.local/conductor-build'
subprocess.run(['docker','build','-f',str(context/'Dockerfile.production'),'-t','conductor:slice13-legacy',str(context)],check=True)
result=ROOT/'test-results/slice13';result.mkdir(parents=True,exist_ok=True)
(result/'legacy-fixture-source.json').write_text(json.dumps({'archive':archive.name,'sha256':hashlib.sha256(archive.read_bytes()).hexdigest(),'sourceChanges':False,'image':'conductor:slice13-legacy'},indent=2)+'\n')