Reduce Docker build memory use on small VPS
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 7m39s
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 7m39s
This commit is contained in:
43
scripts/build-docker.mjs
Normal file
43
scripts/build-docker.mjs
Normal file
@@ -0,0 +1,43 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
// Release each child's memory before starting the next expensive build phase.
|
||||
// In particular, do not type-check while a compiled bundler is still resident.
|
||||
function run(label, args, typechecked = false) {
|
||||
console.log(`[build:docker] ${label}`);
|
||||
const started = Date.now();
|
||||
const child = spawnSync(process.execPath, args, {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_OPTIONS: "--max-old-space-size=640",
|
||||
NEXT_TELEMETRY_DISABLED: "1",
|
||||
MINEGEO_DOCKER_TYPECHECKED: typechecked ? "1" : "0",
|
||||
},
|
||||
});
|
||||
if (child.error) throw child.error;
|
||||
if (child.status !== 0) {
|
||||
console.error(
|
||||
`[build:docker] ${label} failed (${child.signal || `exit ${child.status}`}).`,
|
||||
);
|
||||
process.exit(child.status || 1);
|
||||
}
|
||||
console.log(
|
||||
`[build:docker] ${label} finished in ${Math.round((Date.now() - started) / 1000)}s.`,
|
||||
);
|
||||
}
|
||||
|
||||
run("Clean build cache", ["scripts/clean-build.mjs"]);
|
||||
run("Generate route types", ["node_modules/next/dist/bin/next", "typegen"]);
|
||||
run("Check TypeScript", [
|
||||
"node_modules/typescript/bin/tsc",
|
||||
"--noEmit",
|
||||
"--incremental",
|
||||
"false",
|
||||
]);
|
||||
// Type errors fail the preceding step. Only this invocation skips the duplicate
|
||||
// check; regular npm run build still performs Next.js's normal type checking.
|
||||
run(
|
||||
"Compile production application",
|
||||
["node_modules/next/dist/bin/next", "build", "--webpack"],
|
||||
true,
|
||||
);
|
||||
Reference in New Issue
Block a user