Add frozen TikZRefinery demo baseline and build pipeline
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
ARG RUNTIME_IMAGE
|
||||
FROM ${RUNTIME_IMAGE}
|
||||
ENV HOME=/tmp XDG_CACHE_HOME=/tmp/.cache
|
||||
COPY --chown=1000:1000 . /opt/tikzrefinery/
|
||||
ENTRYPOINT ["/opt/tikzrefinery/TikZRefinery"]
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# Compile disposable copies; never refresh the frozen source's canonical PDFs/index.
|
||||
set -eu
|
||||
source=/workspace/demo/tikzrefinery
|
||||
out=/output/report
|
||||
mkdir -p "$out/source" "$out/results"
|
||||
cp -a "$source/." "$out/source/"
|
||||
cd "$out/source/documents/latex"
|
||||
for edition in TikZRefinerySubmission TikZRefinery; do
|
||||
folder="$out/results/$edition"
|
||||
mkdir -p "$folder"
|
||||
echo "Compiling $edition: LaTeX, bibliography, index and cross-references"
|
||||
if ! latexmk -pdf -interaction=nonstopmode -halt-on-error -file-line-error \
|
||||
-outdir="$folder" "$edition.tex" > "$folder/console.txt" 2>&1; then
|
||||
tail -60 "$folder/console.txt"; exit 1
|
||||
fi
|
||||
if grep -Eq '(^!|undefined references|undefined citations|Citation .* undefined|Reference .* undefined|Rerun to get cross-references right|Label\(s\) may have changed)' "$folder/$edition.log"; then
|
||||
echo "Unresolved report diagnostics: $edition" >&2; exit 1
|
||||
fi
|
||||
test -s "$folder/$edition.pdf"
|
||||
done
|
||||
# The upstream checker binds its index to all source inputs and final shipout maps.
|
||||
python3 ../update-diagram-index.py --build-directory "$out/results" --record-sources
|
||||
python3 ../update-diagram-index.py --build-directory "$out/results"
|
||||
cp "$out/results/TikZRefinerySubmission/TikZRefinerySubmission.pdf" /output/artifacts/TikZRefinery-report.pdf
|
||||
cp ../diagram-index.json /output/artifacts/diagram-index.json
|
||||
@@ -0,0 +1,56 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$QtKit = 'C:/Qt/6.12.0/mingw_64',
|
||||
[string]$CompilerBin = 'C:/Qt/Tools/mingw1310_64/bin',
|
||||
[string]$CMakeBin = 'C:/Qt/Tools/CMake_64/bin',
|
||||
[string]$NinjaBin = 'C:/Qt/Tools/Ninja',
|
||||
[string]$DeliveryVersion = '1.0.0',
|
||||
[string]$OutputDirectory = 'build/demo-windows',
|
||||
[string]$BuildDirectory,
|
||||
[string]$PythonExecutable = 'python'
|
||||
)
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$PSNativeCommandUseErrorActionPreference = $true
|
||||
$repository = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path
|
||||
if ($DeliveryVersion -notmatch '^\d+\.\d+\.\d+$') { throw 'Use major.minor.changelist' }
|
||||
Push-Location $repository
|
||||
try {
|
||||
& $PythonExecutable demo/ci/verify-snapshot.py
|
||||
$output = (New-Item -ItemType Directory -Force $OutputDirectory).FullName
|
||||
$build = if ($BuildDirectory) { [IO.Path]::GetFullPath($BuildDirectory) } else { Join-Path $output 'build' }
|
||||
$package = Join-Path $output "TikZRefinery-windows-$DeliveryVersion"
|
||||
if (Test-Path $package) { throw "Preserve existing package; choose another output directory: $package" }
|
||||
$env:Path = "$QtKit/bin;$CompilerBin;$NinjaBin;" + $env:Path
|
||||
$cmake = Join-Path $CMakeBin 'cmake.exe'
|
||||
& $cmake -S demo/tikzrefinery/code -B $build -G Ninja -DCMAKE_BUILD_TYPE=Release `
|
||||
"-DCMAKE_PREFIX_PATH=$QtKit" "-DCMAKE_CXX_COMPILER=$CompilerBin/g++.exe" `
|
||||
"-DCMAKE_MAKE_PROGRAM=$NinjaBin/ninja.exe"
|
||||
& $cmake --build $build --parallel 4
|
||||
& (Join-Path $CMakeBin 'ctest.exe') --test-dir $build --output-on-failure `
|
||||
--output-junit (Join-Path $output 'tests.xml')
|
||||
New-Item -ItemType Directory -Path "$package/shape-plugins" -Force | Out-Null
|
||||
Copy-Item "$build/TikZRefinery.exe" $package
|
||||
Copy-Item "$build/shape-plugins/tkr_rectangle.dll" "$package/shape-plugins"
|
||||
& "$QtKit/bin/windeployqt.exe" --release --compiler-runtime --no-translations `
|
||||
--no-opengl-sw --no-system-d3d-compiler "$package/TikZRefinery.exe"
|
||||
# windeployqt selects qwindows for normal desktop use. Include the matching
|
||||
# offscreen plugin as well so package smoke checks need no visible window.
|
||||
Copy-Item "$QtKit/plugins/platforms/qoffscreen.dll" "$package/platforms"
|
||||
Copy-Item "$build/build-info.json" $package
|
||||
Copy-Item demo/snapshot.json "$package/upstream-snapshot.json"
|
||||
Copy-Item demo/tikzrefinery/code/examples "$package/examples" -Recurse
|
||||
$downstream = (& git rev-parse HEAD).Trim()
|
||||
$state = (& git status --porcelain --untracked-files=normal) -join "`n"
|
||||
[ordered]@{
|
||||
delivery_version = $DeliveryVersion
|
||||
upstream_commit = 'f4e3193d49a98efcf2f16c2aa22d6085ebe70f36'
|
||||
application_baseline = '0.1.4-alpha'
|
||||
downstream_commit = $downstream
|
||||
downstream_modified = [bool]$state
|
||||
execution = 'Windows command-line rehearsal; not a Jenkins run'
|
||||
} | ConvertTo-Json | Set-Content "$package/delivery-info.json" -Encoding utf8
|
||||
& $PythonExecutable demo/ci/verify-snapshot.py
|
||||
Compress-Archive -LiteralPath $package -DestinationPath "$package.zip"
|
||||
Get-FileHash "$package.zip" -Algorithm SHA256 | Format-List
|
||||
} finally { Pop-Location }
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Generate source-based diagrams, separate from the authored architecture."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
output = Path('/output/architecture')
|
||||
output.mkdir(exist_ok=True)
|
||||
configuration = output / 'Doxyfile'
|
||||
configuration.write_text('''PROJECT_NAME = TikZRefinery
|
||||
OUTPUT_DIRECTORY = /output/architecture
|
||||
INPUT = /workspace/demo/tikzrefinery/code/src /workspace/demo/tikzrefinery/code/plugins /workspace/demo/tikzrefinery/code/plugin-api
|
||||
RECURSIVE = YES
|
||||
FILE_PATTERNS = *.h *.cpp
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = YES
|
||||
GENERATE_HTML = YES
|
||||
GENERATE_LATEX = NO
|
||||
HAVE_DOT = YES
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
DOT_IMAGE_FORMAT = svg
|
||||
INTERACTIVE_SVG = NO
|
||||
QUIET = YES
|
||||
WARN_IF_UNDOCUMENTED = NO
|
||||
WARN_LOGFILE = /output/reports/doxygen-warnings.txt
|
||||
''')
|
||||
subprocess.run(['doxygen', str(configuration)], check=True)
|
||||
graphs = list((output / 'html').glob('*coll*graph.svg')) + list((output / 'html').glob('*inherit*graph.svg'))
|
||||
assert graphs, 'No source-based class graph was generated'
|
||||
print(f'PASS: generated {len(graphs)} class/collaboration graphs from C++ source')
|
||||
@@ -0,0 +1,96 @@
|
||||
"""Package only successful tested builds; keep delivery and upstream identities separate."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
|
||||
root = Path.cwd()
|
||||
out = root / 'build/demo'
|
||||
version = os.environ.get('DELIVERY_VERSION', '1.0.0')
|
||||
assert re.fullmatch(r'\d+\.\d+\.\d+', version), 'Use major.minor.changelist'
|
||||
|
||||
def run(*args, **kwargs):
|
||||
return subprocess.check_output(args, text=True, stderr=subprocess.STDOUT, **kwargs).strip()
|
||||
|
||||
def digest(path):
|
||||
with path.open('rb') as stream:
|
||||
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
|
||||
tests = ET.parse(out / 'reports/tests.xml')
|
||||
cases = tests.findall('.//testcase')
|
||||
assert len(cases) == 8 and all(case.find('failure') is None and case.find('error') is None
|
||||
and case.find('skipped') is None for case in cases), 'Require all eight baseline suites'
|
||||
expected = {'rectangle_plugin_contract','core_foundations','rectangle_display',
|
||||
'segment_display','whole_element_drag','rectangle_resize','workspace_sidebar','session_history'}
|
||||
assert {case.attrib['name'] for case in cases} == expected, 'Wrong suite set'
|
||||
assert (out / 'artifacts/TikZRefinery-report.pdf').is_file()
|
||||
assert (out / 'architecture/html/index.html').is_file()
|
||||
snapshot = json.loads((root / 'demo/snapshot.json').read_text())
|
||||
jenkins = bool(os.environ.get('BUILD_URL'))
|
||||
try:
|
||||
downstream = run('git', 'rev-parse', 'HEAD')
|
||||
modified = bool(run('git', 'status', '--porcelain', '--untracked-files=normal'))
|
||||
except subprocess.CalledProcessError:
|
||||
assert not jenkins, 'Jenkins must retain its real checkout identity'
|
||||
downstream = os.environ.get('DOWNSTREAM_PARENT_COMMIT', 'unavailable')
|
||||
modified = True
|
||||
source_hashes = {p.relative_to(root / 'demo').as_posix(): hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
for p in sorted((root / 'demo').rglob('*')) if p.is_file()}
|
||||
record = dict(delivery_version=version, application_baseline=snapshot['application_baseline'],
|
||||
upstream_repository=snapshot['upstream_repository'], upstream_commit=snapshot['upstream_commit'],
|
||||
downstream_commit_or_parent=downstream, downstream_modified=modified,
|
||||
execution='Jenkins' if jenkins else 'SSH command-line rehearsal; not a Jenkins run',
|
||||
build_url=os.environ.get('BUILD_URL'), source_sha256=source_hashes,
|
||||
toolchain=json.loads((root / 'demo/toolchain.json').read_text()))
|
||||
bundle = out / 'application-bundle'
|
||||
bundle.mkdir(exist_ok=True)
|
||||
(bundle / 'shape-plugins').mkdir(exist_ok=True)
|
||||
for source, destination in [(out/'native/TikZRefinery',bundle/'TikZRefinery'),
|
||||
(out/'native/shape-plugins/tkr_rectangle.so',bundle/'shape-plugins/tkr_rectangle.so'),
|
||||
(out/'native/build-info.json',bundle/'build-info.json'),
|
||||
(root/'demo/snapshot.json',bundle/'upstream-snapshot.json')]:
|
||||
shutil.copy2(source, destination)
|
||||
(bundle / 'delivery-info.json').write_text(json.dumps(record, indent=2) + '\n')
|
||||
image = ('ssw590-tikzrefinery' if jenkins else 'ssw590-tikzrefinery-rehearsal') + ':' + version
|
||||
exists = subprocess.run(['docker','image','inspect',image], stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL).returncode == 0
|
||||
assert not exists, f'Preserve existing artifact {image}; select a new delivery version'
|
||||
environment = dict(os.environ, DOCKER_BUILDKIT='0')
|
||||
subprocess.run(['docker','build','--memory=512m','--memory-swap=768m','--cpu-quota=50000',
|
||||
'--build-arg','RUNTIME_IMAGE=ssw590-demo-runtime:20261125',
|
||||
'-t',image,'-f','demo/ci/application.Dockerfile',str(bundle)],check=True,env=environment)
|
||||
record['application_image'] = image
|
||||
record['application_image_id'] = run('docker','image','inspect','-f','{{.Id}}',image)
|
||||
smoke = subprocess.run(['docker','run','--rm','--network','none','--read-only','--cap-drop','ALL',
|
||||
'--security-opt','no-new-privileges','--memory=256m','--memory-swap=384m',
|
||||
'--cpus=0.5','--pids-limit=128','--tmpfs','/tmp:rw,nosuid,nodev,size=32m',
|
||||
'--entrypoint','sh',image,'-c','timeout 5s ./TikZRefinery'],
|
||||
stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
|
||||
(out/'reports/application-smoke.txt').write_text(smoke.stdout)
|
||||
assert smoke.returncode == 124, ('Expected GUI event loop to remain running offscreen',smoke.returncode,smoke.stdout)
|
||||
archive = out / 'artifacts' / f'TikZRefinery-{version}-linux-image.tar.gz'
|
||||
with subprocess.Popen(['docker','save',image],stdout=subprocess.PIPE) as process:
|
||||
import gzip
|
||||
with gzip.open(archive, 'wb') as stream:
|
||||
shutil.copyfileobj(process.stdout,stream)
|
||||
assert process.wait() == 0
|
||||
with tarfile.open(archive,'r:gz') as tar:
|
||||
manifest = json.load(tar.extractfile('manifest.json'))
|
||||
assert image in manifest[0]['RepoTags']
|
||||
record['image_archive_sha256'] = digest(archive)
|
||||
(out/'artifacts/delivery-info.json').write_text(json.dumps(record,indent=2)+'\n')
|
||||
with zipfile.ZipFile(out/'artifacts'/f'TikZRefinery-{version}-architecture.zip','w',zipfile.ZIP_DEFLATED) as archive_docs:
|
||||
for file in sorted((out/'architecture/html').rglob('*')):
|
||||
if file.is_file():
|
||||
archive_docs.write(file,file.relative_to(out/'architecture'))
|
||||
checksums = []
|
||||
for path in sorted((out/'artifacts').iterdir()):
|
||||
if path.is_file() and path.name != 'SHA256SUMS':
|
||||
checksums.append(digest(path) + ' ' + path.name)
|
||||
(out/'artifacts/SHA256SUMS').write_text('\n'.join(checksums)+'\n')
|
||||
print(json.dumps({key:record[key] for key in ['delivery_version','execution','application_image','application_image_id']},indent=2))
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# Administrator preparation on the existing host; no application/service restart.
|
||||
set -eu
|
||||
base=ssw590-manual-ci:20261007
|
||||
expected=sha256:5d24657a4578977fc7709165b82fc869f09a654a58ab4a0c8defd9d2cd662d5d
|
||||
[ "$(docker image inspect -f '{{.Id}}' "$base")" = "$expected" ] || {
|
||||
echo 'Existing manual toolchain ID differs; investigate before building.' >&2; exit 1;
|
||||
}
|
||||
mkdir -p build/demo
|
||||
export DOCKER_BUILDKIT=0
|
||||
docker build --force-rm --memory=512m --memory-swap=768m --cpu-quota=50000 \
|
||||
-t ssw590-demo-toolchain:20261125 -f demo/ci/toolchain.Dockerfile demo/ci
|
||||
docker build --force-rm --memory=512m --memory-swap=768m --cpu-quota=50000 \
|
||||
-t ssw590-demo-runtime:20261125 -f demo/ci/runtime.Dockerfile demo/ci
|
||||
python3 - <<'PY'
|
||||
import json, subprocess
|
||||
from pathlib import Path
|
||||
def identity(name):
|
||||
return subprocess.check_output(['docker','image','inspect','-f','{{.Id}}',name],text=True).strip()
|
||||
record = {name: identity(name) for name in ['ssw590-demo-toolchain:20261125','ssw590-demo-runtime:20261125']}
|
||||
Path('build/demo/toolchain-observed.json').write_text(json.dumps(record,indent=2)+'\n')
|
||||
print(json.dumps(record,indent=2))
|
||||
PY
|
||||
@@ -0,0 +1,15 @@
|
||||
"""Clear per-run staging outputs, retaining compiler/report caches and archived runs."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
root = Path.cwd().resolve()
|
||||
assert (root / 'demo/snapshot.json').is_file(), 'Run from the demo repository root'
|
||||
for name in ('artifacts', 'reports'):
|
||||
target = root / 'build/demo' / name
|
||||
resolved = target.resolve()
|
||||
assert not target.is_symlink() and resolved == root / 'build/demo' / name
|
||||
assert resolved.is_relative_to(root / 'build/demo')
|
||||
if target.exists():
|
||||
shutil.rmtree(target)
|
||||
target.mkdir(parents=True)
|
||||
print('Fresh per-run artifacts/reports; build caches retained')
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/bin/sh
|
||||
# The same stages are used by Jenkins and explicitly labelled SSH rehearsals.
|
||||
set -eu
|
||||
phase=${1:?choose native, report, architecture or package}
|
||||
root=$(pwd)
|
||||
out="$root/build/demo"
|
||||
if [ "$phase" = native ]; then python3 demo/ci/reset-output.py; fi
|
||||
# The Docker daemon resolves bind sources on the host. Jenkins' workspace lives
|
||||
# inside its named volume, so its container-visible path is not a host path.
|
||||
case "$root" in
|
||||
/home/jenkins/agent/*)
|
||||
volume_root=$(docker volume inspect -f '{{.Mountpoint}}' ssw590-delivery-workspace)
|
||||
host_root="$volume_root/${root#/home/jenkins/agent/}"
|
||||
;;
|
||||
*) host_root="$root";;
|
||||
esac
|
||||
mkdir -p "$out/artifacts" "$out/reports"
|
||||
python3 demo/ci/verify-snapshot.py
|
||||
test -s demo/toolchain.json || { echo 'Prepare and verify the host images before this pipeline.' >&2; exit 1; }
|
||||
python3 - <<'PY'
|
||||
import json, subprocess
|
||||
for name, expected in json.load(open('demo/toolchain.json')).items():
|
||||
actual=subprocess.check_output(['docker','image','inspect','-f','{{.Id}}',name],text=True).strip()
|
||||
assert actual==expected, (name, 'local toolchain changed')
|
||||
PY
|
||||
toolchain=ssw590-demo-toolchain:20261125
|
||||
python3 demo/ci/sample-load.py "$out/reports/$phase-load.csv" &
|
||||
sampler=$!
|
||||
trap 'kill "$sampler" 2>/dev/null || true; wait "$sampler" 2>/dev/null || true' EXIT HUP INT TERM
|
||||
run() {
|
||||
docker run --rm --network none --read-only --cap-drop ALL \
|
||||
--security-opt no-new-privileges --memory=768m --memory-swap=1536m \
|
||||
--cpus=0.75 --pids-limit=256 --user "$(id -u):$(id -g)" \
|
||||
--tmpfs /tmp:rw,nosuid,nodev,size=128m -e HOME=/tmp -e QT_QPA_PLATFORM=offscreen \
|
||||
-e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory -e GIT_CONFIG_VALUE_0=/workspace \
|
||||
--mount "type=bind,source=$host_root,target=/workspace,readonly" \
|
||||
--mount "type=bind,source=$host_root/build/demo,target=/output" \
|
||||
-w /workspace "$toolchain" sh -eu -c "$1"
|
||||
}
|
||||
case "$phase" in
|
||||
native)
|
||||
echo '=== Build C++/Qt application and provider; run all registered CTests ==='
|
||||
run 'cmake -S demo/tikzrefinery/code -B /output/native -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build /output/native --parallel 1
|
||||
ctest --test-dir /output/native --output-on-failure --output-junit /output/reports/tests.xml
|
||||
cp /opt/demo-toolchain/packages.txt /output/reports/toolchain-packages.txt'
|
||||
;;
|
||||
report)
|
||||
echo '=== Compile both authored report editions ==='
|
||||
run 'sh demo/ci/build-report.sh'
|
||||
;;
|
||||
architecture)
|
||||
echo '=== Extract architecture from the frozen C++ source ==='
|
||||
run 'python3 demo/ci/extract-architecture.py'
|
||||
;;
|
||||
package)
|
||||
echo '=== Package versioned deployable application image and reports ==='
|
||||
python3 demo/ci/package.py
|
||||
python3 demo/ci/verify-artifacts.py
|
||||
;;
|
||||
*) echo 'Unknown phase' >&2; exit 1;;
|
||||
esac
|
||||
python3 demo/ci/verify-snapshot.py
|
||||
@@ -0,0 +1,8 @@
|
||||
FROM node:22-bookworm-slim@sha256:c3de60bf2f9dd0ac6370e6117950ff62d6e339527e7472301c9c78a017978392
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
libqt6widgets6 libqt6gui6 libqt6core6 qt6-qpa-plugins fonts-dejavu-core \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
ENV QT_QPA_PLATFORM=offscreen
|
||||
USER node
|
||||
WORKDIR /opt/tikzrefinery
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Read /proc host counters visible to the cloud agent; never inspect processes."""
|
||||
import csv
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
running = True
|
||||
def stop(*_):
|
||||
global running
|
||||
running = False
|
||||
signal.signal(signal.SIGTERM, stop)
|
||||
signal.signal(signal.SIGINT, stop)
|
||||
|
||||
def cpu():
|
||||
fields = [int(n) for n in Path('/proc/stat').read_text().splitlines()[0].split()[1:9]]
|
||||
return sum(fields), fields[3] + fields[4]
|
||||
|
||||
last_total, last_idle = cpu()
|
||||
with open(sys.argv[1], 'w', newline='') as stream:
|
||||
writer = csv.writer(stream)
|
||||
writer.writerow(['utc','host_cpu_percent','host_mem_available_kib','filesystem_free_bytes'])
|
||||
while running:
|
||||
time.sleep(1)
|
||||
total, idle = cpu()
|
||||
memory = dict(line.split(':', 1) for line in Path('/proc/meminfo').read_text().splitlines())
|
||||
usage = 100 * (1 - (idle-last_idle) / max(1, total-last_total))
|
||||
writer.writerow([datetime.now(timezone.utc).isoformat(),round(usage,2),
|
||||
int(memory['MemAvailable'].split()[0]),shutil.disk_usage('.').free])
|
||||
stream.flush()
|
||||
last_total, last_idle = total, idle
|
||||
@@ -0,0 +1,11 @@
|
||||
# Existing, tested TeX compiler image transferred to The-Ocean on November 14.
|
||||
# prepare-images.sh verifies its complete local image ID before this build.
|
||||
FROM ssw590-manual-ci:20261007
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
build-essential cmake ninja-build qt6-base-dev qt6-qpa-plugins \
|
||||
fonts-dejavu-core doxygen graphviz \
|
||||
&& mkdir -p /opt/demo-toolchain \
|
||||
&& dpkg-query -W -f='${Package} ${Version}\n' > /opt/demo-toolchain/packages.txt \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /workspace
|
||||
@@ -0,0 +1,39 @@
|
||||
"""Check transport hashes and the saved OCI manifest/configuration/layer chain."""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
|
||||
folder = Path(sys.argv[1] if len(sys.argv) > 1 else 'build/demo/artifacts').resolve()
|
||||
for line in (folder / 'SHA256SUMS').read_text().splitlines():
|
||||
expected, name = line.split(' ', 1)
|
||||
assert Path(name).name == name and re.fullmatch(r'[0-9a-f]{64}', expected)
|
||||
with (folder / name).open('rb') as stream:
|
||||
assert hashlib.file_digest(stream, 'sha256').hexdigest() == expected, name
|
||||
record = json.loads((folder / 'delivery-info.json').read_text())
|
||||
version = record['delivery_version']
|
||||
assert re.fullmatch(r'\d+\.\d+\.\d+', version)
|
||||
with tarfile.open(folder / f'TikZRefinery-{version}-linux-image.tar.gz', 'r:gz') as archive:
|
||||
compatibility = json.load(archive.extractfile('manifest.json'))[0]
|
||||
assert record['application_image'] in compatibility['RepoTags']
|
||||
index = json.load(archive.extractfile('index.json'))
|
||||
descriptor = next(row for row in index['manifests'] if row['digest'] == record['application_image_id'])
|
||||
def blob_name(digest):
|
||||
assert re.fullmatch(r'sha256:[0-9a-f]{64}', digest)
|
||||
return 'blobs/sha256/' + digest.split(':')[1]
|
||||
manifest_bytes = archive.extractfile(blob_name(descriptor['digest'])).read()
|
||||
assert 'sha256:' + hashlib.sha256(manifest_bytes).hexdigest() == descriptor['digest']
|
||||
manifest = json.loads(manifest_bytes)
|
||||
references = [manifest['config'], *manifest['layers']]
|
||||
members = {member.name: member for member in archive.getmembers()}
|
||||
for reference in sorted(references, key=lambda row: members[blob_name(row['digest'])].offset_data):
|
||||
name = blob_name(reference['digest'])
|
||||
assert members[name].isfile(), name
|
||||
with archive.extractfile(name) as stream:
|
||||
assert 'sha256:' + hashlib.file_digest(stream, 'sha256').hexdigest() == reference['digest'], name
|
||||
with zipfile.ZipFile(folder / f'TikZRefinery-{version}-architecture.zip') as docs:
|
||||
assert 'html/index.html' in docs.namelist()
|
||||
print(f'PASS: version {version}, artifact checksums, OCI manifest/config/{len(manifest["layers"])} layers and architecture ZIP')
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Verify the exact frozen source input, independent of either Git checkout."""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
DEMO = Path(__file__).resolve().parents[1]
|
||||
SOURCE = DEMO / 'tikzrefinery'
|
||||
manifest = json.loads((DEMO / 'snapshot.json').read_text(encoding='utf-8'))
|
||||
expected = manifest['files']
|
||||
actual = {p.relative_to(SOURCE).as_posix() for p in SOURCE.rglob('*') if p.is_file()}
|
||||
assert actual == set(expected), {'missing': sorted(set(expected) - actual),
|
||||
'extra': sorted(actual - set(expected))}
|
||||
for name, identity in expected.items():
|
||||
data = (SOURCE / name).read_bytes()
|
||||
assert hashlib.sha256(data).hexdigest() == identity['sha256'], name
|
||||
git_blob = hashlib.sha1(b'blob ' + str(len(data)).encode() + b'\0' + data).hexdigest()
|
||||
assert git_blob == identity['git_blob'], name
|
||||
print(json.dumps({'result': 'passed', 'upstream_commit': manifest['upstream_commit'],
|
||||
'application_baseline': manifest['application_baseline'],
|
||||
'verified_files': len(expected)}, indent=2))
|
||||
Reference in New Issue
Block a user