Files
likang 7ddc3c22c5
CI / typecheck + test + build (push) Has been cancelled
commit
2026-11-16 17:50:15 +08:00

77 lines
5.9 KiB
JavaScript

// Package only the built PCB application; never include server configuration or secrets.
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { execFileSync } from 'node:child_process';
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)));
export function packagePcb({ source = join(ROOT, 'designer/dist'), output = join(ROOT, 'dist') } = {}) {
source = resolve(source);
output = resolve(output);
if (!existsSync(join(source, 'index.html'))) throw new Error('PCB build missing: run ./build.sh first.');
const config = JSON.parse(readFileSync(join(source, 'pcb-service-config.json'), 'utf8'));
if (config.base !== '/pcb/') throw new Error('The independent PCB package requires the /pcb/ build base.');
mkdirSync(output, { recursive: true });
const stage = mkdtempSync(join(output, '.pcb-package-'));
const directory = join(output, 'vibemake-pcb');
const archive = join(output, 'vibemake-pcb.zip');
const buildId = Date.now().toString(36);
try {
const pcb = join(stage, 'contents');
cpSync(source, pcb, {
recursive: true,
filter: file => !/(?:^|\/)(?:\.DS_Store|Thumbs\.db|\.env(?:\.[^/]*)?|node_modules)(?:\/|$)/.test(file),
});
writeFileSync(join(pcb, 'build-info.json'), JSON.stringify({
scope: 'pcb', buildId, builtAt: new Date().toISOString(), base: '/pcb/', archive: 'vibemake-pcb.zip',
}, null, 2) + '\n');
writeFileSync(join(pcb, 'DEPLOY.md'), `# PCB independent deployment
Extract vibemake-pcb.zip directly into <website-root>/pcb/. The ZIP root contains index.html, assets/ and the other PCB frontend files, with no enclosing pcb/ or vibemake-pcb/ directory.
mkdir -p /path/to/vibemake/pcb
unzip -o /path/to/vibemake-pcb.zip -d /path/to/vibemake/pcb
The result must be <website-root>/pcb/index.html, never pcb/pcb/index.html. Do not extract this package into the website root or copy the ZIP without extracting it.
This package updates only pcb/. Preserve the main site, cad/, js/cad/, existing server configuration and backend services. Never clear the website or PCB directory before extraction.
Check /pcb/build-info.json after deployment: scope=pcb, buildId=${buildId}.
Configure frontend routes to fall back to /pcb/index.html. Keep /pcb/pcb-api/ routed to the separately running AI PCB service before applying the frontend fallback; static hosting does not start that backend. Keep existing account /api/ proxy and CORS settings.
The browser uses same-origin /pcb/pcb-api/ requests. Choose an upstream reachable from OpenResty's own network namespace. The backend Compose publishes 8003 only on the server's 127.0.0.1; proxying to the public IP will not reach that loopback binding. For OpenResty using the same server's host network, add or update this location before the PCB frontend fallback:
location ^~ /pcb/pcb-api/ {
proxy_pass http://127.0.0.1:8003/api/;
proxy_http_version 1.1;
proxy_set_header Host $proxy_host;
proxy_set_header Origin http://127.0.0.1:5173;
proxy_buffering off;
proxy_read_timeout 3600s;
add_header Cache-Control "no-store" always;
}
For OpenResty in a bridge-network container, its 127.0.0.1 is OpenResty itself. Join both containers to the same Docker network and use proxy_pass http://pcb-backend:8003/api/; instead. Use a remote server address only when its backend deliberately listens on an address reachable by OpenResty. Do not expose port 8003 publicly just to bypass a network mismatch.
Verify /pcb/pcb-api/ready returns HTTP 200 with ok=true after deployment; checking or unavailable environments return HTTP 503. /pcb/pcb-api/health is only a liveness check. Deploy the backend with sh codex_pcb/deploy.sh, which waits for the real runtime healthcheck and fails on unavailable environments. The AI entry is enabled in this build and appears only after opening a project and loading its workbench.
If an API returns HTTP 502/503/504 with HTML, inspect the backend container and OpenResty error log. If it returns HTTP 200 with HTML, check the API location priority and frontend fallback. A healthy HTTP endpoint does not verify EDA execution permissions or Codex sandbox availability; run python -m codex_pcb.preflight inside the backend container before approving a real design.
This build also requires /pcb/pcb-api/readiness and /pcb/pcb-api/providers from the updated backend. Project entry checks readiness immediately, shows persistent failures and blocks generation/approval/resume until the native EDA bridge is verified. Backend admission checks also reject these actions when unavailable. Readiness opens only a blank diagnostic session, calls a read-only API and closes that session; it makes no model request or design. New designs can select OpenAI, DeepSeek or Doubao; OpenAI is the default. Configure each provider's key only in the backend environment, never in the frontend ZIP. Unconfigured providers remain disabled.
Serve index.html, sw.js, registerSW.js, build-info.json and the web manifest with Cache-Control: no-cache. Hashed assets can use immutable caching. Keep old hashed assets for already open editors.
`);
execFileSync('zip', ['-qr', join(stage, 'vibemake-pcb.zip'), '.'], { cwd: pcb });
execFileSync('unzip', ['-tq', join(stage, 'vibemake-pcb.zip')], { stdio: 'pipe' });
rmSync(directory, { recursive: true, force: true });
renameSync(pcb, directory);
renameSync(join(stage, 'vibemake-pcb.zip'), archive);
return { archive, directory, buildId };
} finally {
rmSync(stage, { recursive: true, force: true });
}
}
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const result = packagePcb();
console.log(`PCB directory: ${result.directory}`);
console.log(`PCB package ZIP: ${result.archive}`);
console.log('Extract the ZIP directly into <website-root>/pcb/; index.html is at the ZIP root.');
}