release: bump version to 0.84.2
This commit is contained in:
1 parent
5e6352f524
commit
30b44ec00d
77 files changed
+3312
-1039
No files matched your search
@@ -107,6 +107,8 @@ function readRepoText(relativePath) {
|
||||
return readFileSync(new URL(`../../${relativePath}`, import.meta.url), 'utf8')
|
||||
}
|
||||
|
||||
const smokeAppVersion = readRepoText('VERSION').trim() || '0.0.0'
|
||||
|
||||
function extractBalanced(text, start, openChar, closeChar) {
|
||||
let depth = 0
|
||||
let quote = null
|
||||
@@ -932,8 +934,14 @@ function tokenResponse() {
|
||||
})
|
||||
}
|
||||
|
||||
function apiPayloadFor(requestUrl, method) {
|
||||
// Single opaque RGB (128, 0, 0) pixel encodes sea level in Terrarium.
|
||||
const smokeTerrainPng = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNoYGAAAAGEAIH5/mWIAAAAAElFTkSuQmCC'
|
||||
|
||||
function apiPayloadFor(requestUrl, method, postData) {
|
||||
const url = new URL(requestUrl)
|
||||
if (method === 'GET' && url.pathname === '/api/health') {
|
||||
return jsonResponse({ status: 'healthy', version: smokeAppVersion })
|
||||
}
|
||||
const path = url.pathname.replace(/^\/api\/v1/, '') || '/'
|
||||
|
||||
if (method === 'GET' && earthGeoJsonPaths.has(path)) {
|
||||
@@ -1546,6 +1554,19 @@ function apiPayloadFor(requestUrl, method) {
|
||||
if (method === 'DELETE' && /^\/earth\/tiles\/[a-z0-9_]+\/cache$/.test(path)) {
|
||||
return jsonResponse({ removed_files: 5 })
|
||||
}
|
||||
if (method === 'POST' && path === '/visualization/terrain/terrarium/batch') {
|
||||
const { tiles } = JSON.parse(postData ?? '{}')
|
||||
if (!Array.isArray(tiles) || tiles.length === 0) {
|
||||
return jsonResponse({ detail: 'Expected terrain tile coordinates' }, 422)
|
||||
}
|
||||
return jsonResponse({
|
||||
tiles: tiles.map(({ z, x, y }) => ({ z, x, y, content_type: 'image/png', data: smokeTerrainPng })),
|
||||
errors: [],
|
||||
})
|
||||
}
|
||||
if (method === 'GET' && /^\/visualization\/terrain\/terrarium\/\d+\/\d+\/\d+\.png$/.test(path)) {
|
||||
return { status: 200, contentType: 'image/png', body: Buffer.from(smokeTerrainPng, 'base64') }
|
||||
}
|
||||
if (path === '/earth/wind/meta') {
|
||||
return jsonResponse({
|
||||
available: true,
|
||||
@@ -1921,7 +1942,8 @@ function apiPayloadFor(requestUrl, method) {
|
||||
|
||||
async function installApiMocks(context) {
|
||||
await context.route('**/api/**', async (route) => {
|
||||
const response = apiPayloadFor(route.request().url(), route.request().method())
|
||||
const request = route.request()
|
||||
const response = apiPayloadFor(request.url(), request.method(), request.postData())
|
||||
await route.fulfill(response)
|
||||
})
|
||||
}
|
||||
@@ -3141,7 +3163,7 @@ async function main() {
|
||||
&& !english.classList.contains('is-active')
|
||||
&& getComputedStyle(segmented).getPropertyValue('--active-index').trim() === '0'
|
||||
)
|
||||
}, null, { timeout: 5000 })
|
||||
}, null, { polling: 100, timeout: SMOKE_RENDER_TIMEOUT_MS })
|
||||
const zhSystemText = await earthFrame.evaluate(() => (
|
||||
document.querySelector('.earth-settings-sheet [data-settings-tab-panel="system"]')?.innerText || ''
|
||||
))
|
||||
@@ -3164,7 +3186,7 @@ async function main() {
|
||||
&& !chinese.classList.contains('is-active')
|
||||
&& getComputedStyle(segmented).getPropertyValue('--active-index').trim() === '1'
|
||||
)
|
||||
}, null, { timeout: 5000 })
|
||||
}, null, { polling: 100, timeout: SMOKE_RENDER_TIMEOUT_MS })
|
||||
const hdTextureStatus = await earthFrame.evaluate(async () => {
|
||||
const { earthMessage, formatEarthMessage } = await import('/earth/js/i18n.js?frontend_smoke_i18n')
|
||||
const ui = await import('/earth/js/ui.js?frontend_smoke_i18n')
|
||||
@@ -3383,7 +3405,7 @@ async function main() {
|
||||
const ui = await import('/earth/js/ui.js')
|
||||
ui.setLoading(false)
|
||||
ui.showStatusMessage('成功加载 12 条电缆', 'success')
|
||||
await new Promise((resolve) => window.setTimeout(resolve, 360))
|
||||
// Read the temporary toast before a startup notification can replace it.
|
||||
const status = document.getElementById('status-message')
|
||||
const brand = document.getElementById('brand-panel')
|
||||
const ticker = document.getElementById('desktop-news-ticker')
|
||||
@@ -3396,7 +3418,7 @@ async function main() {
|
||||
stacked: status?.classList.contains('earth-status-message--ticker-stack') === true,
|
||||
left: rect?.left || 0,
|
||||
right: rect?.right || 0,
|
||||
top: rect?.top || 0,
|
||||
top: status?.offsetTop || 0,
|
||||
brandRight: brandRect?.right || 0,
|
||||
tickerLeft: tickerRect?.left || 0,
|
||||
tickerTop: tickerRect?.top || 0,
|
||||
@@ -3408,9 +3430,8 @@ async function main() {
|
||||
status.style.minWidth = '260px'
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
}
|
||||
const stackedRect = status?.getBoundingClientRect()
|
||||
const stackedWhenConstrained = status?.classList.contains('earth-status-message--ticker-stack') === true
|
||||
const stackedTop = stackedRect?.top || 0
|
||||
const stackedTop = status?.offsetTop || 0
|
||||
if (status instanceof HTMLElement) {
|
||||
status.style.minWidth = ''
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
|
||||
@@ -473,7 +473,7 @@ class ScopedReleaseTests(unittest.TestCase):
|
||||
self.assertEqual(rc, 0)
|
||||
stdout = out.getvalue()
|
||||
self.assertIn("scope_client_mode: hotfix", stdout)
|
||||
self.assertIn("gitea_release: create", stdout)
|
||||
self.assertIn("gitea_release: skip", stdout)
|
||||
self.assertIn("assets_count: 1", stdout)
|
||||
self.assertIn("planet-earth-bundle-0.80.1.tar.gz", stdout)
|
||||
self.assertNotIn("Planet-0.80.1.exe", stdout)
|
||||
@@ -515,6 +515,236 @@ class ScopedReleaseTests(unittest.TestCase):
|
||||
pub_mock.assert_not_called()
|
||||
self.assertIn("skipped Gitea Release: no client update", out.getvalue())
|
||||
|
||||
def test_release_publish_hotfix_skips_gitea_release(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
manifest = {
|
||||
"schema_version": 1,
|
||||
"tag": "v0.84.2",
|
||||
"commit": "a" * 40,
|
||||
"previous_tag": "v0.84.0",
|
||||
"components": ["earth-hotfix"],
|
||||
"changed_services": [],
|
||||
"services": {
|
||||
k: f"gitea.rclaw.top/linkong/planet/{k}:v0.84.0@sha256:{'1' * 64}"
|
||||
for k in registry.SERVICES
|
||||
},
|
||||
"client": {
|
||||
"mode": "hotfix",
|
||||
"shell_version": "0.84.0",
|
||||
"min_shell_version": "0.84.0",
|
||||
"bundle": "planet-earth-bundle-0.84.2.tar.gz",
|
||||
"bundle_sha256": "a" * 64,
|
||||
"bundle_storage": "oci",
|
||||
},
|
||||
}
|
||||
(root / registry.MANIFEST_NAME).write_text(json.dumps(manifest))
|
||||
changelog = root / "CHANGELOG.md"
|
||||
changelog.write_text("# Changelog\n")
|
||||
|
||||
@contextmanager
|
||||
def fake_prepare(*_args, **_kwargs):
|
||||
yield root, changelog
|
||||
|
||||
out = io.StringIO()
|
||||
with (
|
||||
patch.object(
|
||||
publish,
|
||||
"run_git_origin_url",
|
||||
return_value="https://gitea.rclaw.top/linkong/planet.git",
|
||||
),
|
||||
patch.object(publish, "git_credential_authorization", return_value="token test"),
|
||||
patch.object(publish, "api_request", return_value=(404, None)),
|
||||
patch.object(publisher, "prepare", side_effect=fake_prepare),
|
||||
patch.object(publish, "publish_release") as pub_mock,
|
||||
redirect_stdout(out),
|
||||
):
|
||||
rc = publish.main(["--tag", "v0.84.2", "--scope", "hotfix", "--use-git-credential"])
|
||||
self.assertEqual(rc, 0)
|
||||
pub_mock.assert_not_called()
|
||||
self.assertIn("skipped Gitea Release to preserve /releases/latest", out.getvalue())
|
||||
|
||||
def test_resolve_release_bundle_oci_extracts_and_verifies_bundle_and_notes(self):
|
||||
tag = "v1.1.0"
|
||||
commit = "f" * 40
|
||||
bundle_name = "planet-earth-bundle-1.1.0.tar.gz"
|
||||
bundle_data = hotfix(tag)
|
||||
bundle_sha = hashlib.sha256(bundle_data).hexdigest()
|
||||
|
||||
layer_buf = io.BytesIO()
|
||||
with tarfile.open(fileobj=layer_buf, mode="w:gz") as layer_tar:
|
||||
for name, content in {
|
||||
bundle_name: bundle_data,
|
||||
registry.RELEASE_NOTES_NAME: b"## 1.1.0\n\n- Fixed cloud shader",
|
||||
}.items():
|
||||
info = tarfile.TarInfo(name)
|
||||
info.size = len(content)
|
||||
layer_tar.addfile(info, io.BytesIO(content))
|
||||
layer_bytes = layer_buf.getvalue()
|
||||
layer_digest = registry.digest(layer_bytes)
|
||||
|
||||
cfg = json.dumps(
|
||||
{
|
||||
"os": "linux",
|
||||
"architecture": "amd64",
|
||||
"config": {"Labels": {"org.opencontainers.image.revision": commit}},
|
||||
}
|
||||
).encode()
|
||||
oci_manifest = json.dumps(
|
||||
{
|
||||
"config": {"digest": registry.digest(cfg)},
|
||||
"layers": [{"digest": layer_digest}],
|
||||
}
|
||||
).encode()
|
||||
release_manifest = {
|
||||
"schema_version": 1,
|
||||
"tag": tag,
|
||||
"commit": commit,
|
||||
"services": {
|
||||
k: f"gitea.rclaw.top/linkong/planet/{k}:v1.0.0@sha256:{'1' * 64}"
|
||||
for k in registry.SERVICES
|
||||
},
|
||||
"client": {
|
||||
"mode": "hotfix",
|
||||
"shell_version": "1.0.0",
|
||||
"min_shell_version": "1.0.0",
|
||||
"bundle": bundle_name,
|
||||
"bundle_sha256": bundle_sha,
|
||||
"bundle_storage": "oci",
|
||||
},
|
||||
}
|
||||
|
||||
with patch.object(
|
||||
registry,
|
||||
"read_url",
|
||||
side_effect=[b'{"token":"read"}', oci_manifest, cfg, layer_bytes],
|
||||
):
|
||||
name, data, sha, notes = registry.resolve_release_bundle_oci(tag, commit, release_manifest)
|
||||
self.assertEqual(name, bundle_name)
|
||||
self.assertEqual(data, bundle_data)
|
||||
self.assertEqual(sha, bundle_sha)
|
||||
self.assertIn("Fixed cloud shader", notes)
|
||||
|
||||
bad_manifest = {
|
||||
**release_manifest,
|
||||
"client": {**release_manifest["client"], "bundle_sha256": "0" * 64},
|
||||
}
|
||||
with (
|
||||
patch.object(
|
||||
registry,
|
||||
"read_url",
|
||||
side_effect=[b'{"token":"read"}', oci_manifest, cfg, layer_bytes],
|
||||
),
|
||||
self.assertRaisesRegex(ValueError, "SHA-256"),
|
||||
):
|
||||
registry.resolve_release_bundle_oci(tag, commit, bad_manifest)
|
||||
|
||||
empty_buf = io.BytesIO()
|
||||
with tarfile.open(fileobj=empty_buf, mode="w:gz") as empty_tar:
|
||||
info = tarfile.TarInfo("release-manifest.json")
|
||||
info.size = 2
|
||||
empty_tar.addfile(info, io.BytesIO(b"{}"))
|
||||
empty_layer = empty_buf.getvalue()
|
||||
empty_oci = json.dumps(
|
||||
{
|
||||
"config": {"digest": registry.digest(cfg)},
|
||||
"layers": [{"digest": registry.digest(empty_layer)}],
|
||||
}
|
||||
).encode()
|
||||
with patch.object(
|
||||
registry,
|
||||
"read_url",
|
||||
side_effect=[b'{"token":"read"}', empty_oci, cfg, empty_layer],
|
||||
):
|
||||
self.assertIsNone(registry.resolve_release_bundle_oci(tag, commit, release_manifest))
|
||||
|
||||
def test_deploy_discovers_and_rolls_out_oci_hotfix_without_gitea_release(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
base = Path(temp)
|
||||
host = deploy.Host(base / "host", base / "settings", base / "state")
|
||||
host.state.mkdir()
|
||||
(host.directory("v1.0.0")).mkdir(parents=True)
|
||||
for name in deploy.HOST_FILES:
|
||||
(host.directory("v1.0.0") / name).write_text("host-managed")
|
||||
deploy.point_current(host, "v1.0.0")
|
||||
|
||||
old_refs = {
|
||||
"aiprovider": f"gitea.rclaw.top/linkong/planet/aiprovider:v1.0.0@sha256:{'1' * 64}",
|
||||
"backend": f"gitea.rclaw.top/linkong/planet/backend:v1.0.0@sha256:{'2' * 64}",
|
||||
"admin": f"gitea.rclaw.top/linkong/planet/admin:v1.0.0@sha256:{'3' * 64}",
|
||||
}
|
||||
bundle_name = "planet-earth-bundle-1.1.0.tar.gz"
|
||||
bundle_data = hotfix("v1.1.0")
|
||||
bundle_sha = hashlib.sha256(bundle_data).hexdigest()
|
||||
manifest = {
|
||||
"schema_version": 1,
|
||||
"tag": "v1.1.0",
|
||||
"commit": "f" * 40,
|
||||
"previous_tag": "v1.0.0",
|
||||
"components": ["earth-hotfix"],
|
||||
"changed_services": [],
|
||||
"services": old_refs,
|
||||
"client": {
|
||||
"mode": "hotfix",
|
||||
"shell_version": "1.0.0",
|
||||
"min_shell_version": "1.0.0",
|
||||
"bundle": bundle_name,
|
||||
"bundle_sha256": bundle_sha,
|
||||
"bundle_storage": "oci",
|
||||
},
|
||||
}
|
||||
host.env.write_text(
|
||||
"\n".join(
|
||||
[f"{registry.SERVICES[k]}={v}" for k, v in old_refs.items()]
|
||||
+ ["CLIENT_UPDATE_PUBLISH_TOKEN=tok"]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
live_manifest = base / "manifest.json"
|
||||
live_manifest.write_bytes(b"{}")
|
||||
tags_payload = json.dumps(
|
||||
[
|
||||
{"name": "v1.1.0", "commit": {"sha": "f" * 40}},
|
||||
{"name": "v1.0.0", "commit": {"sha": "a" * 40}},
|
||||
]
|
||||
).encode()
|
||||
|
||||
with (
|
||||
patch.object(deploy, "read_url", return_value=tags_payload),
|
||||
patch.object(deploy, "resolve_release_manifest_oci", return_value=manifest),
|
||||
patch.object(deploy, "release_by_tag") as release_by_tag_mock,
|
||||
patch.object(deploy, "resolved_images", return_value=old_refs),
|
||||
patch.object(
|
||||
deploy,
|
||||
"resolve_release_bundle_oci",
|
||||
return_value=(bundle_name, bundle_data, bundle_sha, "OCI notes"),
|
||||
),
|
||||
patch.object(deploy, "inspect", side_effect=lambda name: {"Config": {"Image": old_refs[name]}, "State": {"Health": {"Status": "healthy"}}}),
|
||||
patch.object(deploy, "data_containers", return_value={"postgres": "same", "redis": "same"}),
|
||||
patch.object(deploy, "live_manifest_path", return_value=live_manifest),
|
||||
patch.object(deploy, "docker") as docker_mock,
|
||||
patch.object(deploy, "backup_database", side_effect=lambda p: p.write_bytes(b"ok")),
|
||||
patch.object(deploy, "rollout_services") as rollout_mock,
|
||||
patch.object(deploy, "check_routes"),
|
||||
patch.object(deploy, "publish_hotfix_bundle") as hotfix_mock,
|
||||
patch.object(deploy, "check_hotfix") as check_hotfix_mock,
|
||||
):
|
||||
deploy.reconcile(host)
|
||||
deploy.reconcile(host, check=True)
|
||||
|
||||
self.assertEqual(host.current(), "v1.1.0")
|
||||
release_by_tag_mock.assert_not_called()
|
||||
docker_mock.assert_not_called()
|
||||
rollout_mock.assert_not_called()
|
||||
self.assertEqual(hotfix_mock.call_args.kwargs["notes"], "OCI notes")
|
||||
self.assertEqual(hotfix_mock.call_args.kwargs["shell_version"], "1.0.0")
|
||||
self.assertEqual(
|
||||
hotfix_mock.call_args.kwargs["release_html_url"],
|
||||
"https://gitea.rclaw.top/linkong/planet/releases/tag/v1.0.0",
|
||||
)
|
||||
self.assertEqual(check_hotfix_mock.call_count, 2)
|
||||
check_hotfix_mock.assert_called_with("v1.1.0", bundle_sha, shell_version="1.0.0")
|
||||
|
||||
def test_deploy_discovers_server_only_release_from_tags_and_oci_without_gitea_release(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
base = Path(temp)
|
||||
|
||||
@@ -30,6 +30,7 @@ if __package__:
|
||||
release_by_tag,
|
||||
release_manifest,
|
||||
resolve_image,
|
||||
resolve_release_bundle_oci,
|
||||
resolve_release_manifest_oci,
|
||||
resolve_service_ref,
|
||||
tag_commit,
|
||||
@@ -47,6 +48,7 @@ else:
|
||||
release_by_tag,
|
||||
release_manifest,
|
||||
resolve_image,
|
||||
resolve_release_bundle_oci,
|
||||
resolve_release_manifest_oci,
|
||||
resolve_service_ref,
|
||||
tag_commit,
|
||||
@@ -382,15 +384,31 @@ def resolved_images(tag, commit, manifest=None):
|
||||
return images
|
||||
|
||||
|
||||
def _load_release_bundle_and_notes(release, tag, commit, manifest):
|
||||
"""Load the L1 hotfix bundle and release notes from Gitea Release or OCI manifest."""
|
||||
client_mode = (manifest.get("client") or {}).get("mode", "full") if manifest else "full"
|
||||
if client_mode == "none":
|
||||
return None, None, None, ""
|
||||
if release is None:
|
||||
oci_bundle = resolve_release_bundle_oci(tag, commit, manifest)
|
||||
if oci_bundle is None:
|
||||
raise RuntimeError(f"Missing OCI hotfix bundle for {tag}")
|
||||
return oci_bundle
|
||||
name, data, sha = release_bundle(release, tag)
|
||||
return name, data, sha, (release or {}).get("body") or ""
|
||||
|
||||
|
||||
def deploy(host, release, previous, tag, images, commit, *, manifest=None):
|
||||
client_mode = (manifest.get("client") or {}).get("mode", "full") if manifest else "full"
|
||||
client_info = (manifest or {}).get("client") or {}
|
||||
if client_mode == "none":
|
||||
name, data, sha = None, None, None
|
||||
name, data, sha, release_notes = None, None, None, ""
|
||||
minimum = None
|
||||
shell_version = client_info.get("shell_version")
|
||||
else:
|
||||
name, data, sha = release_bundle(release, tag)
|
||||
name, data, sha, release_notes = _load_release_bundle_and_notes(
|
||||
release, tag, commit, manifest
|
||||
)
|
||||
minimum = client_info.get("min_shell_version") or minimum_shell(data, tag)
|
||||
shell_version = client_info.get("shell_version") or tag[1:]
|
||||
|
||||
@@ -447,7 +465,7 @@ def deploy(host, release, previous, tag, images, commit, *, manifest=None):
|
||||
publish_url=PUBLIC,
|
||||
publish_token=token,
|
||||
tag=tag,
|
||||
notes=(release or {}).get("body") or "",
|
||||
notes=release_notes,
|
||||
release_html_url=f"{SERVER}/{REPO}/releases/tag/v{shell_version}",
|
||||
assets=[(archive, sha)],
|
||||
min_shell_version=minimum,
|
||||
@@ -510,7 +528,10 @@ def discover_latest_release(previous, *, check=False):
|
||||
commit = sha if (isinstance(sha, str) and re.fullmatch("[0-9a-f]{40,64}", sha)) else tag_commit(tag)
|
||||
manifest = resolve_release_manifest_oci(tag, commit)
|
||||
if manifest is not None:
|
||||
if manifest["client"]["mode"] == "none":
|
||||
mode = manifest["client"]["mode"]
|
||||
if mode == "none":
|
||||
return tag, commit, manifest, None
|
||||
if mode == "hotfix" and manifest["client"].get("bundle_storage") == "oci":
|
||||
return tag, commit, manifest, None
|
||||
release = release_by_tag(tag)
|
||||
if release is not None:
|
||||
@@ -550,7 +571,7 @@ def reconcile(host, *, check=False, retry=False):
|
||||
sha = None
|
||||
shell_version = (manifest or {}).get("client", {}).get("shell_version") if manifest else tag[1:]
|
||||
if client_mode != "none":
|
||||
_, data, sha = release_bundle(release, tag)
|
||||
_, data, sha, _ = _load_release_bundle_and_notes(release, tag, commit, manifest)
|
||||
minimum_shell(data, tag)
|
||||
if tag == previous:
|
||||
for name, ref in images.items():
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
import tarfile
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
@@ -16,6 +18,7 @@ REGISTRY = urllib.parse.urlsplit(SERVER).netloc
|
||||
API = f"{SERVER}/api/v1/repos/{REPO}"
|
||||
MANIFEST_NAME = "release-manifest.json"
|
||||
MANIFEST_IMAGE = "release-manifest"
|
||||
RELEASE_NOTES_NAME = "release-notes.md"
|
||||
DEFAULT_USER_AGENT = "Planet-Release-Deploy/1.0"
|
||||
SERVICES = {
|
||||
"aiprovider": "AI_PROVIDER_IMAGE_NAME",
|
||||
@@ -189,8 +192,8 @@ def descriptor_digest(desc):
|
||||
return value
|
||||
|
||||
|
||||
def _fetch_oci_config(repository, name, tag, commit):
|
||||
"""Fetch and verify the linux/amd64 OCI manifest digest and revision label."""
|
||||
def _fetch_oci_manifest_and_config(repository, name, tag, commit):
|
||||
"""Fetch and verify the linux/amd64 OCI manifest, config digest, and revision label."""
|
||||
query = urllib.parse.urlencode(
|
||||
{"service": "container_registry", "scope": f"repository:{repository}:pull"}
|
||||
)
|
||||
@@ -228,7 +231,16 @@ def _fetch_oci_config(repository, name, tag, commit):
|
||||
raise ValueError(f"{name}:{tag} is not a linux/amd64 image")
|
||||
if labels.get("org.opencontainers.image.revision") != commit:
|
||||
raise ValueError(f"{name}:{tag} belongs to a different commit")
|
||||
return digest(raw), labels
|
||||
return digest(raw), manifest, labels, token
|
||||
|
||||
|
||||
def _fetch_oci_config(repository, name, tag, commit):
|
||||
"""Fetch and verify the linux/amd64 OCI manifest digest and revision label."""
|
||||
fetched = _fetch_oci_manifest_and_config(repository, name, tag, commit)
|
||||
if fetched is None:
|
||||
return None
|
||||
manifest_digest, _manifest, labels, _token = fetched
|
||||
return manifest_digest, labels
|
||||
|
||||
|
||||
def resolve_image(service, tag, commit):
|
||||
@@ -257,3 +269,62 @@ def resolve_release_manifest_oci(tag, commit):
|
||||
raise ValueError(f"{name}:{tag} is missing planet.release.manifest label")
|
||||
manifest = json.loads(raw_manifest)
|
||||
return _validate_release_manifest(manifest, tag)
|
||||
|
||||
|
||||
def resolve_release_bundle_oci(tag, commit, manifest):
|
||||
"""Read and verify an L1 hotfix bundle embedded in OCI release-manifest:<tag>."""
|
||||
version(tag)
|
||||
client = (manifest or {}).get("client") or {}
|
||||
bundle_name = client.get("bundle")
|
||||
expected_sha = client.get("bundle_sha256")
|
||||
if (
|
||||
not isinstance(bundle_name, str)
|
||||
or not bundle_name
|
||||
or not isinstance(expected_sha, str)
|
||||
or not re.fullmatch(r"[a-f0-9]{64}", expected_sha)
|
||||
):
|
||||
raise ValueError("Release manifest is missing hotfix bundle metadata")
|
||||
|
||||
name = manifest_image_name()
|
||||
fetched = _fetch_oci_manifest_and_config(f"{REPO}/{MANIFEST_IMAGE}", name, tag, commit)
|
||||
if fetched is None:
|
||||
return None
|
||||
_manifest_digest, oci_manifest, _labels, token = fetched
|
||||
headers = {"Authorization": "Bearer " + token}
|
||||
base = f"{SERVER}/v2/{REPO}/{MANIFEST_IMAGE}"
|
||||
|
||||
for layer in reversed(oci_manifest.get("layers") or []):
|
||||
layer_digest = descriptor_digest(layer)
|
||||
blob = read_url(
|
||||
f"{base}/blobs/{layer_digest}",
|
||||
headers=headers,
|
||||
limit=32 * 1024 * 1024,
|
||||
)
|
||||
if digest(blob) != layer_digest:
|
||||
raise ValueError("OCI release manifest layer failed digest verification")
|
||||
|
||||
notes = ""
|
||||
bundle_data = None
|
||||
bundle_sha = None
|
||||
with tarfile.open(fileobj=io.BytesIO(blob), mode="r:*") as archive:
|
||||
for member in archive.getmembers():
|
||||
member_name = member.name.lstrip("./")
|
||||
if not member.isfile():
|
||||
continue
|
||||
if member_name == RELEASE_NOTES_NAME and member.size <= 64 * 1024:
|
||||
extracted = archive.extractfile(member)
|
||||
if extracted is not None:
|
||||
notes = extracted.read().decode("utf-8", errors="replace").strip()
|
||||
elif member_name == bundle_name:
|
||||
if not 0 < member.size <= 32 * 1024 * 1024:
|
||||
raise ValueError("OCI hotfix bundle exceeds allowed size")
|
||||
extracted = archive.extractfile(member)
|
||||
if extracted is None:
|
||||
raise ValueError("Could not extract OCI hotfix bundle")
|
||||
bundle_data = extracted.read()
|
||||
bundle_sha = hashlib.sha256(bundle_data).hexdigest()
|
||||
if bundle_sha != expected_sha:
|
||||
raise ValueError("OCI hotfix bundle failed SHA-256 verification")
|
||||
if bundle_data is not None and bundle_sha is not None:
|
||||
return bundle_name, bundle_data, bundle_sha, notes
|
||||
return None
|
||||
@@ -18,6 +18,7 @@ if __package__:
|
||||
from .production_registry import (
|
||||
API,
|
||||
MANIFEST_NAME,
|
||||
RELEASE_NOTES_NAME,
|
||||
REPO,
|
||||
SERVER,
|
||||
SERVICES,
|
||||
@@ -27,16 +28,19 @@ if __package__:
|
||||
release_by_tag,
|
||||
release_manifest,
|
||||
resolve_image,
|
||||
resolve_release_bundle_oci,
|
||||
resolve_release_manifest_oci,
|
||||
resolve_service_ref,
|
||||
tag_commit,
|
||||
version,
|
||||
)
|
||||
from .release_publish import extract_release_notes
|
||||
from .release_scope import resolve_release_scope
|
||||
else:
|
||||
from production_registry import (
|
||||
API,
|
||||
MANIFEST_NAME,
|
||||
RELEASE_NOTES_NAME,
|
||||
REPO,
|
||||
SERVER,
|
||||
SERVICES,
|
||||
@@ -46,11 +50,13 @@ else:
|
||||
release_by_tag,
|
||||
release_manifest,
|
||||
resolve_image,
|
||||
resolve_release_bundle_oci,
|
||||
resolve_release_manifest_oci,
|
||||
resolve_service_ref,
|
||||
tag_commit,
|
||||
version,
|
||||
)
|
||||
from release_publish import extract_release_notes
|
||||
from release_scope import resolve_release_scope
|
||||
|
||||
|
||||
@@ -248,22 +254,34 @@ def resolve_previous_release_state(previous_tag):
|
||||
return pins, previous_tag[1:], previous_tag[1:]
|
||||
|
||||
|
||||
def ensure_release_manifest_image(tag, commit, manifest):
|
||||
def ensure_release_manifest_image(tag, commit, manifest, *, bundle_path=None, release_notes=None):
|
||||
"""Push and verify the minimal OCI release-manifest:<tag> metadata artifact."""
|
||||
bundle_in_oci = (manifest.get("client") or {}).get("bundle_storage") == "oci"
|
||||
existing = resolve_release_manifest_oci(tag, commit)
|
||||
if existing is not None:
|
||||
if existing != manifest:
|
||||
raise RuntimeError(f"Published OCI release manifest for {tag} differs from expected manifest")
|
||||
if bundle_in_oci and resolve_release_bundle_oci(tag, commit, manifest) is None:
|
||||
raise RuntimeError(f"Published OCI release manifest for {tag} is missing embedded hotfix bundle")
|
||||
print(f"Verified OCI {manifest_image_name()}:{tag}", flush=True)
|
||||
return existing
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="planet-manifest-") as tmp:
|
||||
ctx = Path(tmp)
|
||||
(ctx / "release-manifest.json").write_text(
|
||||
payload = ctx / "payload"
|
||||
payload.mkdir()
|
||||
(payload / MANIFEST_NAME).write_text(
|
||||
json.dumps(manifest, indent=2) + "\n", encoding="utf-8"
|
||||
)
|
||||
if bundle_path is not None:
|
||||
shutil.copy2(bundle_path, payload / bundle_path.name)
|
||||
if release_notes:
|
||||
(payload / RELEASE_NOTES_NAME).write_text(
|
||||
release_notes.strip()[:32768] + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(ctx / "Dockerfile").write_text(
|
||||
"FROM scratch\nCOPY release-manifest.json /release-manifest.json\n",
|
||||
"FROM scratch\nCOPY payload/ /\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
cmd = [
|
||||
@@ -294,6 +312,8 @@ def ensure_release_manifest_image(tag, commit, manifest):
|
||||
verified = resolve_release_manifest_oci(tag, commit)
|
||||
if verified != manifest:
|
||||
raise RuntimeError(f"Pushed OCI release manifest is missing or mismatched for {tag}")
|
||||
if bundle_in_oci and resolve_release_bundle_oci(tag, commit, manifest) is None:
|
||||
raise RuntimeError(f"Pushed OCI release manifest is missing embedded hotfix bundle for {tag}")
|
||||
print(f"Verified OCI {manifest_image_name()}:{tag}", flush=True)
|
||||
return verified
|
||||
|
||||
@@ -308,6 +328,15 @@ def build_release_manifest(tag, commit, scope, service_refs, packages, *, shell_
|
||||
else:
|
||||
resolved_shell = shell_version or ver
|
||||
resolved_min_shell = min_shell_version or resolved_shell
|
||||
client_info = {
|
||||
"mode": scope.client_mode,
|
||||
"shell_version": resolved_shell,
|
||||
"min_shell_version": resolved_min_shell,
|
||||
"bundle": bundle_path.name if bundle_path else None,
|
||||
"bundle_sha256": package_hash(bundle_path) if bundle_path else None,
|
||||
}
|
||||
if bundle_path is not None:
|
||||
client_info["bundle_storage"] = "oci" if scope.client_mode == "hotfix" else "release"
|
||||
return {
|
||||
"schema_version": 1,
|
||||
"tag": tag,
|
||||
@@ -316,13 +345,7 @@ def build_release_manifest(tag, commit, scope, service_refs, packages, *, shell_
|
||||
"components": list(scope.components),
|
||||
"changed_services": list(scope.services),
|
||||
"services": dict(service_refs),
|
||||
"client": {
|
||||
"mode": scope.client_mode,
|
||||
"shell_version": resolved_shell,
|
||||
"min_shell_version": resolved_min_shell,
|
||||
"bundle": bundle_path.name if bundle_path else None,
|
||||
"bundle_sha256": package_hash(bundle_path) if bundle_path else None,
|
||||
},
|
||||
"client": client_info,
|
||||
}
|
||||
|
||||
|
||||
@@ -406,7 +429,22 @@ def prepare(tag, assets_dir, suffixes, *, already_published=False, scope_overrid
|
||||
shell_version=prev_shell_version,
|
||||
min_shell_version=prev_min_shell_version,
|
||||
)
|
||||
ensure_release_manifest_image(tag, commit, manifest)
|
||||
oci_bundle_path = None
|
||||
oci_release_notes = None
|
||||
if (manifest.get("client") or {}).get("bundle_storage") == "oci" and not already_published:
|
||||
bundle_name = (manifest.get("client") or {}).get("bundle")
|
||||
oci_bundle_path = next(
|
||||
(p for p in staged_packages if p.name == bundle_name),
|
||||
None,
|
||||
)
|
||||
oci_release_notes = extract_release_notes(worktree / "docs/CHANGELOG.md", tag)
|
||||
ensure_release_manifest_image(
|
||||
tag,
|
||||
commit,
|
||||
manifest,
|
||||
bundle_path=oci_bundle_path,
|
||||
release_notes=oci_release_notes,
|
||||
)
|
||||
(stage / MANIFEST_NAME).write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
||||
yield stage, worktree / "docs/CHANGELOG.md"
|
||||
# The verified public release now holds these bytes. Keep the cache on upload failure.
|
||||
|
||||
@@ -575,9 +575,13 @@ def main(argv: list[str] | None = None) -> int:
|
||||
print(f"scope_components: {','.join(scope.components)}")
|
||||
print(f"scope_services: {','.join(scope.services) or 'none'}")
|
||||
print(f"scope_client_mode: {scope.client_mode}")
|
||||
print(
|
||||
f"gitea_release: {'skip (no client update)' if scope.client_mode == 'none' else 'create'}"
|
||||
)
|
||||
if scope.client_mode == "full":
|
||||
gitea_release_action = "create"
|
||||
elif scope.client_mode == "hotfix":
|
||||
gitea_release_action = "skip (OCI hotfix; preserves /releases/latest desktop installers)"
|
||||
else:
|
||||
gitea_release_action = "skip (no client update)"
|
||||
print(f"gitea_release: {gitea_release_action}")
|
||||
print(f"scope_previous_tag: {scope.previous_tag or 'none'}")
|
||||
print(f"notes_length: {len(notes)}")
|
||||
print(f"assets_count: {len(assets)}")
|
||||
@@ -630,6 +634,17 @@ def main(argv: list[str] | None = None) -> int:
|
||||
flush=True,
|
||||
)
|
||||
return 0
|
||||
if client_mode == "hotfix":
|
||||
if published:
|
||||
raise RuntimeError(
|
||||
f"Hotfix-only release {args.tag} must not have a published Gitea Release"
|
||||
)
|
||||
print(
|
||||
f"Published hotfix release {args.tag} via OCI manifest and bundle "
|
||||
"(skipped Gitea Release to preserve /releases/latest)",
|
||||
flush=True,
|
||||
)
|
||||
return 0
|
||||
if published:
|
||||
pub_manifest = release_manifest(public, args.tag)
|
||||
if pub_manifest is None or pub_manifest["client"]["mode"] != "none":
|
||||
|
||||
Reference in new issue
Block a user