build(container): use turbo pruned web workspace

This commit is contained in:
vince 2026-06-20 07:01:15 +02:00
parent 220fb55a47
commit 3e46a2c0cc
5 changed files with 58 additions and 37 deletions

View file

@ -114,35 +114,47 @@ describe("workspace boundaries", () => {
);
});
test("stages web workspace dependency manifests before container install", () => {
const webPackage = JSON.parse(
readFileSync(join(root, "apps/web/package.json"), "utf8"),
) as { dependencies?: Record<string, string> };
const workspacePackages = [
"packages/ui/package.json",
"packages/dashboard-model/package.json",
].map((manifestPath) => {
const packageJson = JSON.parse(
readFileSync(join(root, manifestPath), "utf8"),
) as { name?: string };
return [packageJson.name, manifestPath] as const;
});
const manifestsByPackageName = new Map(workspacePackages);
test("builds the internal container from a turbo-pruned web workspace", () => {
const containerfile = readFileSync(
join(root, "apps/web/Containerfile"),
"utf8",
);
const pruneCommand = "turbo prune @dimensionlab/web --docker";
const jsonCopy = "COPY --from=pruner /repo/out/json/ ./";
const sourceCopy = "COPY --from=pruner /repo/out/full/ ./";
const tsconfigCopy =
"COPY --from=pruner /repo/tsconfig.base.json /repo/tsconfig.json ./";
const installCommand = "RUN bun install --frozen-lockfile";
const workspaceDependencyManifests = Object.entries(
webPackage.dependencies ?? {},
)
.filter(([, version]) => version.startsWith("workspace:"))
.map(([packageName]) => manifestsByPackageName.get(packageName));
expect(containerfile).toContain("AS pruner");
expect(containerfile).toContain(pruneCommand);
expect(containerfile).toContain(jsonCopy);
expect(containerfile).toContain(sourceCopy);
expect(containerfile).toContain(tsconfigCopy);
expect(containerfile).not.toContain(
"COPY packages/dashboard-model/package.json",
);
expect(containerfile).not.toContain("COPY packages/ui/package.json");
expect(workspaceDependencyManifests).not.toContain(undefined);
for (const manifestPath of workspaceDependencyManifests) {
expect(containerfile).toContain(`COPY ${manifestPath} ${manifestPath}`);
}
const jsonCopyIndex = containerfile.indexOf(jsonCopy);
const installIndex = containerfile.indexOf(installCommand);
const sourceCopyIndex = containerfile.indexOf(sourceCopy);
const tsconfigCopyIndex = containerfile.indexOf(tsconfigCopy);
expect(jsonCopyIndex).toBeGreaterThan(-1);
expect(installIndex).toBeGreaterThan(jsonCopyIndex);
expect(sourceCopyIndex).toBeGreaterThan(installIndex);
expect(tsconfigCopyIndex).toBeGreaterThan(sourceCopyIndex);
expect(containerfile.indexOf("RUN bun run build")).toBeGreaterThan(
tsconfigCopyIndex,
);
});
test("keeps local turbo prune output out of git and container contexts", () => {
const gitignore = readFileSync(join(root, ".gitignore"), "utf8");
const containerignore = readFileSync(join(root, ".containerignore"), "utf8");
expect(gitignore).toContain("out/");
expect(containerignore).toContain("out");
});
});