From b058a3bca1b60d7778a9a223afa9a8e0c038e36c Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Fri, 6 Nov 2026 19:59:21 +0800 Subject: [PATCH] fix(deploy): stream verified Git sources and reuse loaded images --- scripts/git-incremental-deploy.ps1 | 8 +++++-- scripts/git-incremental-deploy.test.mjs | 29 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/scripts/git-incremental-deploy.ps1 b/scripts/git-incremental-deploy.ps1 index 31a57d0e..27f9c7fe 100644 --- a/scripts/git-incremental-deploy.ps1 +++ b/scripts/git-incremental-deploy.ps1 @@ -1045,7 +1045,11 @@ if [ "$SKIP_DEPLOY" != "1" ]; then ok "Pinned production image: $REGISTRY_COMMIT ($EXPECTED_IMAGE_ID)" start_remote_step "Deploy on Production Server" log "Ensuring production server can access image $REGISTRY_COMMIT" - if prod_ssh "docker pull '$REGISTRY_COMMIT'" >/tmp/git-deploy-prod-pull.log 2>&1; then + EXISTING_PROD_IMAGE_ID="$(prod_ssh "docker image inspect --format '{{.Id}}' '$REGISTRY_TAG' 2>/dev/null" | tr -d '\r\n' || true)" + if [ "$EXISTING_PROD_IMAGE_ID" = "$EXPECTED_IMAGE_ID" ]; then + REGISTRY_COMMIT="$REGISTRY_TAG" + ok "Production already has the verified exact-SHA image" + elif prod_ssh "docker pull '$REGISTRY_COMMIT'" >/tmp/git-deploy-prod-pull.log 2>&1; then ok "Production server pulled image from registry" else warn "Production server could not pull image directly; streaming image from build server" @@ -1068,7 +1072,7 @@ if [ "$SKIP_DEPLOY" != "1" ]; then ok "Production image revision label matches $COMMIT_SHA" # Bundle from the exact fetched checkout, not workstation WIP or old image files. - MATERIAL_PREVIEW_GATE_MODULE="$(docker run --rm --network none --read-only --mount "type=bind,source=${REMOTE_BUILD_DIR},target=/source,readonly" --entrypoint node "$REGISTRY_TAG" /source/scripts/material-preview-release-gate.mjs bundle)" || fail "Material preview release gate could not be bundled from the exact checkout" + MATERIAL_PREVIEW_GATE_MODULE="$(git -C "$REMOTE_BUILD_DIR" archive "$COMMIT_SHA" scripts/material-preview-release-gate.mjs scripts/check-material-preview-health.mjs scripts/export-material-preview-health-manifest.mjs scripts/check-legacy-storage-boundaries.mjs scripts/fixtures/material-preview-known-legacy-20261023.json lib/url-rewrite.ts lib/proxy-media-security.ts app/api/proxy-media/route.ts lib/s3.ts lib/network-detection.ts | docker run --rm -i --network none --read-only --user 0:0 --cap-drop ALL --tmpfs /source:rw,noexec,nosuid,size=16m --entrypoint sh "$REGISTRY_TAG" -c 'tar -xf - -C /source && node /source/scripts/material-preview-release-gate.mjs bundle')" || fail "Material preview release gate could not be bundled from the exact checkout" [[ "$MATERIAL_PREVIEW_GATE_MODULE" = data:text/javascript\;base64,* ]] || fail "Material preview release gate bundle is invalid" [ "${#MATERIAL_PREVIEW_GATE_MODULE}" -le 524288 ] || fail "Material preview gate bundle exceeds its fixed transport budget" diff --git a/scripts/git-incremental-deploy.test.mjs b/scripts/git-incremental-deploy.test.mjs index 62765867..f1703bf0 100644 --- a/scripts/git-incremental-deploy.test.mjs +++ b/scripts/git-incremental-deploy.test.mjs @@ -28,15 +28,21 @@ test('generated remote deployment payload is valid bash', () => { }) test('preview bundle uses the verified application Node without relying on the build host Node', () => { - const line = deploySource().split('\n').find(value => value.includes('MATERIAL_PREVIEW_GATE_MODULE=') && value.includes(' bundle)')) + const line = deploySource().split('\n').find(value => value.includes('MATERIAL_PREVIEW_GATE_MODULE=') && value.includes(' bundle')) assert.ok(line) const result = spawnSync(bash, ['-s'], { encoding: 'utf8', input: `set -eu REMOTE_BUILD_DIR=/verified/repository REGISTRY_TAG=verified-image +COMMIT_SHA=verified-commit node() { echo HOST_NODE_CALLED; return 1; } fail() { echo "$*" >&2; exit 1; } +git() { + [ "$1 $2 $3 $4" = "-C /verified/repository archive verified-commit" ] || return 1 + printf 'committed-git-sources' +} docker() { - [ "$*" = "run --rm --network none --read-only --mount type=bind,source=/verified/repository,target=/source,readonly --entrypoint node verified-image /source/scripts/material-preview-release-gate.mjs bundle" ] || return 1 + [ "$*" = "run --rm -i --network none --read-only --user 0:0 --cap-drop ALL --tmpfs /source:rw,noexec,nosuid,size=16m --entrypoint sh verified-image -c tar -xf - -C /source && node /source/scripts/material-preview-release-gate.mjs bundle" ] || return 1 + [ "$(cat)" = committed-git-sources ] || return 1 printf 'verified-runtime-bundle' } ${line} @@ -46,6 +52,25 @@ printf '%s' "$MATERIAL_PREVIEW_GATE_MODULE" assert.equal(result.stdout, 'verified-runtime-bundle') }) +test('an already loaded exact production image skips another pull and SSH image stream', () => { + const source = deploySource() + const start = source.indexOf(' EXISTING_PROD_IMAGE_ID=') + const end = source.indexOf('\n\n ACTUAL_PROD_IMAGE_ID=', start) + assert.ok(start >= 0 && end > start) + const result = spawnSync(bash, ['-s'], { encoding: 'utf8', input: `set -eu +REGISTRY_TAG=verified-image +REGISTRY_COMMIT=registry-image +EXPECTED_IMAGE_ID=verified-id +prod_ssh() { case "$*" in *'docker image inspect'*) printf verified-id;; *) echo UNEXPECTED_TRANSFER; return 1;; esac; } +docker() { echo UNEXPECTED_TRANSFER; return 1; } +ok() { :; } +${source.slice(start, end)} +printf '%s' "$REGISTRY_COMMIT" +` }) + assert.equal(result.status, 0, result.stderr) + assert.equal(result.stdout, 'verified-image') +}) + test('server admission blocks proxy changes before any reload or unit rewrite', () => { for (const phase of ['missing', 'unattested']) { const input = `set -eu