test: serve QA standalone static assets
This commit is contained in:
1 parent
d2cc9780e7
commit
28a433386e
2 files changed
+24
-6
No files matched your search
@@ -23,6 +23,7 @@ const markerName = ".homarr-release-v2-qa-root.json";
|
|||||||
const runtimeMode = "production-standalone" as const;
|
const runtimeMode = "production-standalone" as const;
|
||||||
const runtimeBundler = "webpack" as const;
|
const runtimeBundler = "webpack" as const;
|
||||||
const candidateBuildHeapLimitMb = 16_384;
|
const candidateBuildHeapLimitMb = 16_384;
|
||||||
|
const candidateBuildManifestSchemaVersion = 2;
|
||||||
const profiles = ["main-writable", "main-readonly", "onboarding-fresh", "degraded"] as const;
|
const profiles = ["main-writable", "main-readonly", "onboarding-fresh", "degraded"] as const;
|
||||||
|
|
||||||
type Profile = (typeof profiles)[number];
|
type Profile = (typeof profiles)[number];
|
||||||
@@ -84,12 +85,15 @@ export const createCandidateBuildPaths = (candidateSha: string) => {
|
|||||||
const buildDir = path.join(appRoot, distDirName);
|
const buildDir = path.join(appRoot, distDirName);
|
||||||
const standaloneRoot = path.join(buildDir, "standalone");
|
const standaloneRoot = path.join(buildDir, "standalone");
|
||||||
const standaloneAppDir = path.join(standaloneRoot, "apps/nextjs");
|
const standaloneAppDir = path.join(standaloneRoot, "apps/nextjs");
|
||||||
|
const standaloneStaticDir = path.join(standaloneAppDir, distDirName, "static");
|
||||||
return {
|
return {
|
||||||
appRoot,
|
appRoot,
|
||||||
distDirName,
|
distDirName,
|
||||||
buildDir,
|
buildDir,
|
||||||
standaloneRoot,
|
standaloneRoot,
|
||||||
standaloneAppDir,
|
standaloneAppDir,
|
||||||
|
standaloneStaticDir,
|
||||||
|
standaloneStaticChunksDir: path.join(standaloneStaticDir, "chunks"),
|
||||||
generatedServerPath: path.join(standaloneAppDir, "server.js"),
|
generatedServerPath: path.join(standaloneAppDir, "server.js"),
|
||||||
serverPath: path.join(standaloneAppDir, "server.cjs"),
|
serverPath: path.join(standaloneAppDir, "server.cjs"),
|
||||||
markerPath: path.join(buildDir, "qa-build-manifest.json"),
|
markerPath: path.join(buildDir, "qa-build-manifest.json"),
|
||||||
@@ -388,15 +392,17 @@ const candidateBuildIsReady = async (candidateSha: string) => {
|
|||||||
bundler?: string;
|
bundler?: string;
|
||||||
};
|
};
|
||||||
const serverStats = await stat(buildPaths.serverPath);
|
const serverStats = await stat(buildPaths.serverPath);
|
||||||
const staticStats = await stat(path.join(buildPaths.standaloneAppDir, ".next/static"));
|
const staticStats = await stat(buildPaths.standaloneStaticDir);
|
||||||
|
const staticChunksStats = await stat(buildPaths.standaloneStaticChunksDir);
|
||||||
const publicStats = await stat(path.join(buildPaths.standaloneAppDir, "public"));
|
const publicStats = await stat(path.join(buildPaths.standaloneAppDir, "public"));
|
||||||
return (
|
return (
|
||||||
marker.schemaVersion === 1 &&
|
marker.schemaVersion === candidateBuildManifestSchemaVersion &&
|
||||||
marker.candidateSha === candidateSha &&
|
marker.candidateSha === candidateSha &&
|
||||||
marker.runtimeMode === runtimeMode &&
|
marker.runtimeMode === runtimeMode &&
|
||||||
marker.bundler === runtimeBundler &&
|
marker.bundler === runtimeBundler &&
|
||||||
serverStats.isFile() &&
|
serverStats.isFile() &&
|
||||||
staticStats.isDirectory() &&
|
staticStats.isDirectory() &&
|
||||||
|
staticChunksStats.isDirectory() &&
|
||||||
publicStats.isDirectory()
|
publicStats.isDirectory()
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -427,18 +433,29 @@ const ensureCandidateBuild = async (runRoot: string, candidateSha: string) => {
|
|||||||
SKIP_ENV_VALIDATION: "true",
|
SKIP_ENV_VALIDATION: "true",
|
||||||
});
|
});
|
||||||
|
|
||||||
const staticTarget = path.join(buildPaths.standaloneAppDir, ".next/static");
|
|
||||||
const publicTarget = path.join(buildPaths.standaloneAppDir, "public");
|
const publicTarget = path.join(buildPaths.standaloneAppDir, "public");
|
||||||
await mkdir(path.dirname(staticTarget), { recursive: true });
|
await assertSafeContainedPath(
|
||||||
await cp(path.join(buildPaths.buildDir, "static"), staticTarget, { recursive: true, force: true });
|
buildPaths.standaloneAppDir,
|
||||||
|
buildPaths.standaloneStaticDir,
|
||||||
|
"QA standalone static directory",
|
||||||
|
);
|
||||||
|
await mkdir(path.dirname(buildPaths.standaloneStaticDir), { recursive: true });
|
||||||
|
await cp(path.join(buildPaths.buildDir, "static"), buildPaths.standaloneStaticDir, {
|
||||||
|
recursive: true,
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
await cp(path.join(buildPaths.appRoot, "public"), publicTarget, { recursive: true, force: true });
|
await cp(path.join(buildPaths.appRoot, "public"), publicTarget, { recursive: true, force: true });
|
||||||
// The app package is ESM, while Next emits a CommonJS standalone launcher.
|
// The app package is ESM, while Next emits a CommonJS standalone launcher.
|
||||||
// Give the generated launcher an explicit CommonJS extension before executing it.
|
// Give the generated launcher an explicit CommonJS extension before executing it.
|
||||||
await rename(buildPaths.generatedServerPath, buildPaths.serverPath);
|
await rename(buildPaths.generatedServerPath, buildPaths.serverPath);
|
||||||
const serverStats = await stat(buildPaths.serverPath);
|
const serverStats = await stat(buildPaths.serverPath);
|
||||||
if (!serverStats.isFile()) throw new Error(`Standalone server is missing after build: ${buildPaths.serverPath}`);
|
if (!serverStats.isFile()) throw new Error(`Standalone server is missing after build: ${buildPaths.serverPath}`);
|
||||||
|
const staticChunksStats = await stat(buildPaths.standaloneStaticChunksDir);
|
||||||
|
if (!staticChunksStats.isDirectory()) {
|
||||||
|
throw new Error(`Standalone static chunks are missing after build: ${buildPaths.standaloneStaticChunksDir}`);
|
||||||
|
}
|
||||||
await writeJsonAtomic(buildPaths.markerPath, {
|
await writeJsonAtomic(buildPaths.markerPath, {
|
||||||
schemaVersion: 1,
|
schemaVersion: candidateBuildManifestSchemaVersion,
|
||||||
candidateSha,
|
candidateSha,
|
||||||
runtimeMode,
|
runtimeMode,
|
||||||
bundler: runtimeBundler,
|
bundler: runtimeBundler,
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ describe("release-v2 QA app execution contract", () => {
|
|||||||
expect(paths.generatedServerPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.js`);
|
expect(paths.generatedServerPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.js`);
|
||||||
expect(paths.serverPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.cjs`);
|
expect(paths.serverPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.cjs`);
|
||||||
expect(paths.standaloneRoot).toBe(`${paths.buildDir}/standalone`);
|
expect(paths.standaloneRoot).toBe(`${paths.buildDir}/standalone`);
|
||||||
|
expect(paths.standaloneStaticDir).toBe(`${paths.buildDir}/standalone/apps/nextjs/${paths.distDirName}/static`);
|
||||||
expect(() => createCandidateBuildPaths("not-a-commit")).toThrow(/40-character lowercase commit SHA/u);
|
expect(() => createCandidateBuildPaths("not-a-commit")).toThrow(/40-character lowercase commit SHA/u);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user