From c4eff7b2bb4e5a29ae4a7ad8f85cb2f40c6680f4 Mon Sep 17 00:00:00 2001 From: chenpei Date: Wed, 12 Aug 2026 21:20:58 +0800 Subject: [PATCH] build: compile canvas without external binary download --- Dockerfile | 2 +- lib/__tests__/video-transcode-deploy-drain.test.ts | 1 + scripts/safe-production-migrate.test.mjs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ca9b37c..78c36bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN --mount=type=cache,target=/root/.npm \ lock_sha="$(sha256sum package-lock.json | awk '{print $1}')" && \ echo "Installing dependencies (using cache if available)..." && \ npm config set registry https://registry.npmmirror.com && \ - npm ci --prefer-offline --no-audit --no-fund --legacy-peer-deps && \ + npm_config_build_from_source=canvas npm ci --prefer-offline --no-audit --no-fund --legacy-peer-deps && \ test "$manifest_sha" = "$(sha256sum package.json | awk '{print $1}')" && \ test "$lock_sha" = "$(sha256sum package-lock.json | awk '{print $1}')" && \ node -e "const sharp=require('sharp'); sharp(Buffer.alloc(4),{raw:{width:1,height:1,channels:4}}).png().toBuffer().then(()=>console.log('sharp dependency smoke passed')).catch((error)=>{console.error(error);process.exit(1)})" && \ diff --git a/lib/__tests__/video-transcode-deploy-drain.test.ts b/lib/__tests__/video-transcode-deploy-drain.test.ts index bd373b1..4d609bd 100644 --- a/lib/__tests__/video-transcode-deploy-drain.test.ts +++ b/lib/__tests__/video-transcode-deploy-drain.test.ts @@ -467,6 +467,7 @@ describe('production video transcode drain gate', () => { const finalMigrationInclude = dockerignore.lastIndexOf('!prisma/migrations/**') expect(dockerfile).toContain('npm ci --prefer-offline') + expect(dockerfile).toContain('npm_config_build_from_source=canvas npm ci') expect(dockerfile).not.toContain('--omit=optional') expect(dockerfile).toContain("grep -Eq '^[0-9a-f]{40}$'") expect(dockerfile).toContain("const sharp=require('sharp')") diff --git a/scripts/safe-production-migrate.test.mjs b/scripts/safe-production-migrate.test.mjs index 78c05e0..0028d85 100644 --- a/scripts/safe-production-migrate.test.mjs +++ b/scripts/safe-production-migrate.test.mjs @@ -427,6 +427,7 @@ test('container supply chain and migrator image are immutable while SOP keeps co ) assert.match(deps, /^COPY package\.json package-lock\.json \.\/$/m) assert.match(deps, /npm ci --prefer-offline --no-audit --no-fund --legacy-peer-deps/) + assert.match(deps, /npm_config_build_from_source=canvas npm ci/) assert.doesNotMatch(deps, /--omit=optional/) assert.match(deps, /const sharp=require\('sharp'\)/) assert.doesNotMatch(deps, /\bnpm install\b|writeFileSync|delete pkg\.optionalDependencies/)