perf(build): keep test suites out of the image and cache CI builds durably
Three build-time improvements, all measured on this host. The build context no longer ships the test suites. `next build` type-checks the whole project, so `e2e/` and `integration/` in the context made the image build fail on a type error in test code and pulled @playwright/test, vitest, msw, testcontainers and drizzle-kit into the image. The CI runs those suites on the host. Type-check time in the build drops from 2.2s to 1.3s, and a contract test now fails if application code ever imports from those folders. The CI now exports the build cache to a directory outside the runner workspace: /var/cache/epicnext-cms-buildcache for the release and a separate map for branch preflights, so a branch can never feed the release cache. The workspace is wiped after every job and `docker builder prune` runs after every release, so the next build started with an empty cache and downloaded all 493 packages again (measured: reused 0, downloaded 493). With the durable export the frozen dependency layer is reused (measured: reused 493, downloaded 0) even after a full prune. A cache directory that is not writable only produces a warning; the release is never blocked. Investigated the remaining ~30s of Next.js build tracing: excluding the dev-only packages with `outputFileTracingExcludes` made it slower (35s vs 30s), because the traced output was already minimal (5 packages). The cost is Next's own page-config collection and file tracing over 329 routes, not the dependency set, so no configuration was kept.
This commit is contained in:
@@ -29,6 +29,7 @@ function simulate(
|
||||
scenario: string,
|
||||
previous = "epicnext-cms-app",
|
||||
both = false,
|
||||
extraEnv: Record<string, string> = {},
|
||||
) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "cms-deploy-test-"));
|
||||
try {
|
||||
@@ -58,6 +59,9 @@ function simulate(
|
||||
TEST_SHA: sha,
|
||||
SCENARIO: scenario,
|
||||
DEPLOY_BRANCH: "main",
|
||||
// Standaard uit: de tests rimen geen cache-map aan op de host.
|
||||
CMS_BUILD_CACHE_DIR: "",
|
||||
...extraEnv,
|
||||
},
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
@@ -180,6 +184,24 @@ describe("deployment transaction", () => {
|
||||
expect(result.calls).not.toContain("pnpm db:migrate");
|
||||
expect(result.calls).not.toContain("docker run");
|
||||
});
|
||||
// `docker builder prune` (na elke release) gooit de buildcache weg. Zonder
|
||||
// duurzame export downloadt de volgende build alle packages opnieuw.
|
||||
it("bouwt met een duurzame buildcache buiten de werkboom", () => {
|
||||
const cacheDirectory = mkdtempSync(join(tmpdir(), "cms-deploy-cache-"));
|
||||
try {
|
||||
const cache = join(cacheDirectory, "cache");
|
||||
const result = simulate("success", "epicnext-cms-app", false, {
|
||||
CMS_BUILD_CACHE_DIR: cache,
|
||||
});
|
||||
expect(result.status, result.output).toBe(0);
|
||||
expect(result.calls).toContain(`--cache-from type=local,src=${cache}`);
|
||||
expect(result.calls).toContain(
|
||||
`--cache-to type=local,dest=${cache},mode=max`,
|
||||
);
|
||||
} finally {
|
||||
rmSync(cacheDirectory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("legacy and CI container coexistence", () => {
|
||||
@@ -248,6 +270,8 @@ function simulateBlueGreen(scenario: string, livePort = 3002) {
|
||||
TEST_SHA: sha,
|
||||
SCENARIO: scenario,
|
||||
DEPLOY_BRANCH: "main",
|
||||
// Standaard uit: de tests rimen geen cache-map aan op de host.
|
||||
CMS_BUILD_CACHE_DIR: "",
|
||||
},
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
|
||||
Reference in New Issue
Block a user