perf(docker): reuse dependency layers and preserve build caches
This commit is contained in:
1 parent
31691c1c7d
commit
2840ef5d9d
4 files changed
+59
-34
No files matched your search
@@ -79,13 +79,15 @@ describe("deploy job", () => {
|
||||
expect(deployJob).toContain('"database":true');
|
||||
});
|
||||
|
||||
it("prunes old images, containers, volumes, networks and build cache", () => {
|
||||
expect(deployJob).toContain("docker image prune -af");
|
||||
expect(deployJob).toContain("docker container prune -f");
|
||||
expect(deployJob).toContain("docker volume prune -f");
|
||||
expect(deployJob).toContain("docker network prune -f");
|
||||
expect(deployJob).toContain("docker builder prune");
|
||||
expect(deployJob).toContain("Prune Docker cache");
|
||||
it("preserves recent build cache and avoids pruning application volumes", () => {
|
||||
expect(deployJob).toContain(
|
||||
'docker builder prune -af --filter "until=72h" --keep-storage=2g',
|
||||
);
|
||||
expect(deployJob).toContain('docker image prune -f --filter "until=168h"');
|
||||
expect(deployJob).not.toContain("docker volume prune");
|
||||
expect(deployJob).not.toContain("docker network prune");
|
||||
expect(deployJob).not.toContain("docker container prune");
|
||||
expect(deployJob).not.toContain("docker image prune -af");
|
||||
});
|
||||
|
||||
it("does not run pnpm test in deploy", () => {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dockerfile = readFileSync("Dockerfile", "utf8");
|
||||
|
||||
describe("Docker build cache", () => {
|
||||
it("installs frozen dependencies before copying application source", () => {
|
||||
const manifests = dockerfile.indexOf(
|
||||
"COPY package.json *lock* pnpm-workspace.yaml .npmrc ./",
|
||||
);
|
||||
const install = dockerfile.indexOf("pnpm install --frozen-lockfile");
|
||||
const source = dockerfile.indexOf("COPY . .");
|
||||
expect(manifests).toBeGreaterThan(-1);
|
||||
expect(install).toBeGreaterThan(manifests);
|
||||
expect(source).toBeGreaterThan(install);
|
||||
});
|
||||
it("retains the package store and Next compiler cache across source changes", () => {
|
||||
expect(dockerfile).toContain("id=epicnext-pnpm,target=/pnpm/store");
|
||||
expect(dockerfile).toContain("--store-dir=/pnpm/store");
|
||||
expect(dockerfile).toContain("id=epicnext-next,target=/app/.next/cache");
|
||||
});
|
||||
it("ships standalone output without a redundant dependency pruning step", () => {
|
||||
expect(dockerfile).toContain("/app/.next/standalone ./");
|
||||
expect(dockerfile).not.toContain("pnpm prune --prod");
|
||||
expect(dockerfile).not.toContain("npm prune --production");
|
||||
expect(dockerfile).not.toContain("yarn install --production");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user