fix(images): ship Linux codecs and preserve original-image fallback

Vendor the locked sharp Linux runtime and verify it during Docker builds. Add complete image response lengths and persistent frontend fallbacks, with real-codec HTTP and isolated release regression tests. Refresh tested API, admin and customer release artifacts.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
mahmood
2026-11-26 18:12:21 +03:30
co-authored by Claude Code
parent a085c279f8
commit 3e9f532c6c
346 changed files with 33359 additions and 240 deletions
+52 -1
View File
@@ -10,8 +10,11 @@ const {
cpSync,
realpathSync,
readdirSync,
readFileSync,
writeFileSync,
} = require('fs');
const path = require('path');
const { createRequire } = require('module');
// Only this engine ships to Docker; see apps/api/Dockerfile (bookworm/OpenSSL 3).
const RUNTIME_ENGINE = 'libquery_engine-debian-openssl-3.0.x.so.node';
@@ -52,7 +55,7 @@ function copyPrismaIntoRelease() {
// Drop engines for other platforms (local Windows dll, stale musl builds) so the
// committed artifact stays small.
for (const name of readdirSync(prismaEngineDest)) {
const isEngine = name.endsWith('.so.node') || name.endsWith('.dll.node');
const isEngine = /^(?:lib)?query_engine-/.test(name) || name.endsWith('.so.node') || name.endsWith('.dll.node');
if (isEngine && name !== RUNTIME_ENGINE) {
rmSync(path.join(prismaEngineDest, name), { force: true });
}
@@ -65,6 +68,52 @@ function copyPrismaIntoRelease() {
}
}
// Copy the locked runtime closure, not Windows binaries or pnpm's symlinks.
// Both native packages must remain siblings: sharp's ELF RUNPATH finds libvips
// relative to @img/sharp-linux-x64. Runtime installation is deliberately offline.
function copySharpIntoRelease() {
const versions = {};
function copyPackage(name, from) {
let source;
try {
// sharp 0.35 hides package.json behind exports; packaging must locate
// the installed manifest without loading a native binary on Windows.
const search = createRequire(path.join(from, 'package.json')).resolve.paths(name) ?? [];
const manifest = search.map((dir) => path.join(dir, name, 'package.json')).find(existsSync);
if (!manifest) throw new Error('Package not installed');
source = realpathSync(path.dirname(manifest));
} catch {
throw new Error(`Missing image runtime package ${name}. Run pnpm install with the workspace supportedArchitectures settings before building release.`);
}
const pkg = JSON.parse(readFileSync(path.join(source, 'package.json'), 'utf8'));
if (versions[name]) {
if (versions[name] !== pkg.version) throw new Error(`Conflicting image runtime versions for ${name}`);
return;
}
versions[name] = pkg.version;
const dest = path.join(vendorDir, name);
mkdirSync(path.dirname(dest), { recursive: true });
cpSync(source, dest, { recursive: true, dereference: true });
for (const dependency of Object.keys(pkg.dependencies ?? {})) copyPackage(dependency, source);
if (name === 'sharp') {
copyPackage('@img/sharp-linux-x64', source);
copyPackage('@img/sharp-libvips-linux-x64', source);
}
}
copyPackage('sharp', root);
for (const [name, extension] of [
['@img/sharp-linux-x64', '.node'],
['@img/sharp-libvips-linux-x64', '.so'],
]) {
const lib = path.join(vendorDir, name, 'lib');
if (!existsSync(lib) || !readdirSync(lib).some((file) => file.includes(extension))) {
throw new Error(`Incomplete Linux image runtime: ${name}`);
}
}
writeFileSync(path.join(releaseDir, 'image-runtime.json'), JSON.stringify({ platform: 'linux', arch: 'x64', versions }, null, 2) + '\n');
cpSync(path.join(__dirname, 'verify-release-images.cjs'), path.join(releaseDir, 'verify-release-images.cjs'));
}
async function main() {
const entry = config.entryPoints[0];
const fallbackEntry = path.join(root, 'dist', 'src', 'main.js');
@@ -82,6 +131,7 @@ async function main() {
await esbuild.build(config);
copyPrismaIntoRelease();
copySharpIntoRelease();
// SQL migrations are read at runtime by src/prisma/migrate.ts
cpSync(path.join(root, 'prisma', 'migrations'), path.join(releaseDir, 'migrations'), {
@@ -97,6 +147,7 @@ async function main() {
console.log('نوشت:', config.outfile);
console.log('Prisma client در release/vendor کپی شد.');
console.log('sharp و وابستگی‌های native لینوکس در release/vendor کپی شدند.');
console.log('migrations و seed.js در release کپی شدند.');
}