Import ECS deployed relay source and historical patches (2026-10-27)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import tarfile
|
||||
|
||||
from scripts.fetch_official_images import export_image, digest_file
|
||||
|
||||
|
||||
def test_offline_docker_archive_preserves_config_and_rootfs(tmp_path):
|
||||
cache, output = tmp_path / "cache", tmp_path / "out"
|
||||
cache.mkdir()
|
||||
output.mkdir()
|
||||
layer = io.BytesIO()
|
||||
with tarfile.open(fileobj=layer, mode="w") as tar:
|
||||
content = b"hello ARM64\n"
|
||||
info = tarfile.TarInfo("test.txt")
|
||||
info.size, info.mode = len(content), 0o644
|
||||
tar.addfile(info, io.BytesIO(content))
|
||||
raw = layer.getvalue()
|
||||
raw_digest = hashlib.sha256(raw).hexdigest()
|
||||
import gzip
|
||||
compressed = gzip.compress(raw)
|
||||
blob_digest = hashlib.sha256(compressed).hexdigest()
|
||||
(cache / (blob_digest + ".blob")).write_bytes(compressed)
|
||||
config = json.dumps({"architecture": "arm64", "os": "linux", "config": {"Env": []},
|
||||
"rootfs": {"type": "layers", "diff_ids": ["sha256:" + raw_digest]}}).encode()
|
||||
config_digest = hashlib.sha256(config).hexdigest()
|
||||
(cache / (config_digest + ".blob")).write_bytes(config)
|
||||
record = {"name": "test", "tag": "arm64", "config": {"digest": "sha256:" + config_digest},
|
||||
"layers": [{"digest": "sha256:" + blob_digest}]}
|
||||
export_image(record, cache, output)
|
||||
path = output / record["archive"]
|
||||
assert record["archive_sha256"] == digest_file(path)
|
||||
with tarfile.open(path) as tar:
|
||||
manifest = json.load(tar.extractfile("manifest.json"))[0]
|
||||
assert manifest["RepoTags"] == ["test:arm64"]
|
||||
assert tar.extractfile(manifest["Config"]).read() == config
|
||||
assert tar.extractfile(manifest["Layers"][0]).read() == raw
|
||||
Reference in New Issue
Block a user