From 83b9826b3e5c6c198d2ac8b0933a89d3c677b51f Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Sun, 8 Nov 2026 09:11:22 +0800 Subject: [PATCH] fix(deploy): ship vendored crate patches in market image contexts The root manifest patches `tao` and `wry` to in-tree paths, and Cargo resolves every `[patch.crates-io]` entry from the workspace root even for a service-only build. The miniapp and skin Dockerfiles only copied `third_party/eioc`, so a clean checkout failed with: error: failed to load source for dependency `tao` Caused by: unable to update /build/third_party/tao Copy both vendored engines and allowlist them in the per-Dockerfile ignore files. Because those ignore files are hand-maintained whitelists, add a contract test that keeps `[patch.crates-io]` paths, third_party COPY sources and the committed `ppt-live` bundle in sync with the build context. Verified by building both images from the repository root. --- .github/workflows/ci.yml | 3 + scripts/market/market-image-context.test.mjs | 121 ++++++++++++++++++ src/apps/miniapp-market-server/Dockerfile | 4 + .../Dockerfile.dockerignore | 4 + src/apps/skin-market-server/Dockerfile | 4 + .../Dockerfile.dockerignore | 4 + 6 files changed, 140 insertions(+) create mode 100644 scripts/market/market-image-context.test.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 354105c812..38f8227423 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,6 +100,9 @@ jobs: - name: Validate Relay deployment and packaging contracts run: node --test scripts/relay/*.test.mjs + - name: Validate market image build contexts + run: node --test scripts/market/*.test.mjs + - name: Verify minisign download fallback run: | set -euo pipefail diff --git a/scripts/market/market-image-context.test.mjs b/scripts/market/market-image-context.test.mjs new file mode 100644 index 0000000000..3f03e17ce2 --- /dev/null +++ b/scripts/market/market-image-context.test.mjs @@ -0,0 +1,121 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import test from 'node:test'; + +const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..'); +const read = (relativePath) => + fs.readFileSync(path.join(repoRoot, relativePath), 'utf8'); +const exists = (relativePath) => fs.existsSync(path.join(repoRoot, relativePath)); + +// Both markets build from the repo root with a per-Dockerfile ignore file, so +// the build context is a hand-maintained whitelist. Anything the Dockerfile +// copies must be allowlisted there, otherwise the COPY resolves to nothing. +const marketImages = [ + { + name: 'miniapp', + dockerfile: 'src/apps/miniapp-market-server/Dockerfile', + ignoreFile: 'src/apps/miniapp-market-server/Dockerfile.dockerignore', + }, + { + name: 'skin', + dockerfile: 'src/apps/skin-market-server/Dockerfile', + ignoreFile: 'src/apps/skin-market-server/Dockerfile.dockerignore', + }, +]; + +function patchSectionPaths(cargoToml) { + const lines = cargoToml.split('\n'); + const start = lines.findIndex((line) => /^\[patch\.crates-io\]\s*$/.test(line.trim())); + assert.ok(start >= 0, 'Cargo.toml is expected to declare [patch.crates-io]'); + + const paths = []; + for (const line of lines.slice(start + 1)) { + const trimmed = line.trim(); + if (trimmed.startsWith('[')) break; + if (!trimmed || trimmed.startsWith('#')) continue; + const match = /=\s*\{[^}]*\bpath\s*=\s*"([^"]+)"/.exec(trimmed); + if (match) paths.push(match[1].replace(/\/+$/, '')); + } + return paths; +} + +function copiedPaths(dockerfile) { + return dockerfile + .split('\n') + .filter((line) => line.startsWith('COPY ') && !line.includes('--from=')) + .map((line) => line.slice('COPY '.length).trim().split(/\s+/)[0]) + .filter((source) => source !== '.'); +} + +function allowsDirectory(ignore, directory) { + const escaped = directory.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + return new RegExp(`^!${escaped}/(?:\\*\\*)?$`, 'm').test(ignore); +} + +test('vendored crate patches ship with the market build contexts', () => { + const patched = patchSectionPaths(read('Cargo.toml')); + assert.ok(patched.length > 0, 'expected at least one patched path dependency'); + + for (const image of marketImages) { + const dockerfile = read(image.dockerfile); + const ignore = read(image.ignoreFile); + + for (const cratePath of patched) { + assert.ok( + exists(cratePath), + `${cratePath} is referenced by [patch.crates-io] but missing from the checkout`, + ); + assert.match( + dockerfile, + new RegExp(`^COPY ${cratePath}/ ${cratePath}/$`, 'm'), + `${image.name} image must COPY ${cratePath}/; Cargo resolves [patch.crates-io] paths even for a service-only build`, + ); + assert.ok( + allowsDirectory(ignore, cratePath), + `${image.name} build context must allowlist ${cratePath}/`, + ); + } + } +}); + +test('every third_party COPY source is allowlisted in its build context', () => { + for (const image of marketImages) { + const ignore = read(image.ignoreFile); + const sources = copiedPaths(read(image.dockerfile)).filter((source) => + source.startsWith('third_party/'), + ); + assert.ok(sources.length > 0, `${image.name} Dockerfile should copy third_party sources`); + + for (const source of sources) { + const directory = source.replace(/\/+$/, ''); + assert.ok( + allowsDirectory(ignore, directory), + `${image.name} build context must allowlist ${directory}/`, + ); + } + } +}); + +test('committed builtin assets survive the dist pruning rules', () => { + // `product-domains` include_str!s this bundle, and it lives under a `dist` + // directory, which the market context otherwise prunes wholesale. + const bundle = + 'src/crates/contracts/product-domains/src/miniapp/builtin/assets/ppt-live/dist/ui.bundle.js'; + assert.ok(exists(bundle), `${bundle} is committed and must stay in the tree`); + + for (const image of marketImages) { + const ignore = read(image.ignoreFile); + assert.match( + ignore, + /^\*\*\/dist$/m, + `${image.name} build context is expected to prune dist directories`, + ); + assert.match( + ignore, + new RegExp(`^!${bundle}$`, 'm'), + `${image.name} build context must re-allowlist ${bundle}`, + ); + } +}); diff --git a/src/apps/miniapp-market-server/Dockerfile b/src/apps/miniapp-market-server/Dockerfile index 4c10c84906..be845fd2f7 100644 --- a/src/apps/miniapp-market-server/Dockerfile +++ b/src/apps/miniapp-market-server/Dockerfile @@ -46,6 +46,10 @@ RUN apt-get update \ COPY Cargo.toml Cargo.lock ./ COPY third_party/eioc/ third_party/eioc/ +# Cargo resolves `[patch.crates-io]` path entries from the root manifest even for +# a service-only build, so the vendored engine patches must be present. +COPY third_party/tao/ third_party/tao/ +COPY third_party/wry/ third_party/wry/ COPY src/ src/ RUN --mount=type=cache,id=openbitfun-market-cargo-registry,target=/usr/local/cargo/registry,sharing=locked \ diff --git a/src/apps/miniapp-market-server/Dockerfile.dockerignore b/src/apps/miniapp-market-server/Dockerfile.dockerignore index e132ea72cb..a96646e57f 100644 --- a/src/apps/miniapp-market-server/Dockerfile.dockerignore +++ b/src/apps/miniapp-market-server/Dockerfile.dockerignore @@ -7,6 +7,10 @@ !third_party/eioc/Cargo.toml !third_party/eioc/src/ !third_party/eioc/src/** +!third_party/tao/ +!third_party/tao/** +!third_party/wry/ +!third_party/wry/** !package.json !pnpm-lock.yaml !pnpm-workspace.yaml diff --git a/src/apps/skin-market-server/Dockerfile b/src/apps/skin-market-server/Dockerfile index 2e27588506..ea47eeae6d 100644 --- a/src/apps/skin-market-server/Dockerfile +++ b/src/apps/skin-market-server/Dockerfile @@ -46,6 +46,10 @@ RUN apt-get update \ COPY Cargo.toml Cargo.lock ./ COPY third_party/eioc/ third_party/eioc/ +# Cargo resolves `[patch.crates-io]` path entries from the root manifest even for +# a service-only build, so the vendored engine patches must be present. +COPY third_party/tao/ third_party/tao/ +COPY third_party/wry/ third_party/wry/ COPY src/ src/ RUN --mount=type=cache,id=openbitfun-skin-market-cargo-registry,target=/usr/local/cargo/registry,sharing=locked \ diff --git a/src/apps/skin-market-server/Dockerfile.dockerignore b/src/apps/skin-market-server/Dockerfile.dockerignore index 12552aaf05..185a3e9209 100644 --- a/src/apps/skin-market-server/Dockerfile.dockerignore +++ b/src/apps/skin-market-server/Dockerfile.dockerignore @@ -7,6 +7,10 @@ !third_party/eioc/Cargo.toml !third_party/eioc/src/ !third_party/eioc/src/** +!third_party/tao/ +!third_party/tao/** +!third_party/wry/ +!third_party/wry/** !package.json !pnpm-lock.yaml !pnpm-workspace.yaml