Repeated builds grew the VM's disk to 63 GB, until the Mac's disk was full. Writes inside the VM then failed and its file systems broke. - The service image installed dependencies after copying every source file, so each source change rebuilt a 750 MB layer, five images at a time. It now installs from the workspace manifests first, and a test keeps every workspace listed. - The VM's disk defaults to 40 GiB instead of 80. - `up` refuses to create the VM when the Mac has less free space than that, and `build` refuses below 15 GiB free. - After building, superseded images are pruned and the build cache is capped at 10 GB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.7 KiB
TypeScript
37 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { readdir, readFile } from 'node:fs/promises';
|
|
import { existsSync } from 'node:fs';
|
|
|
|
// The service image installs dependencies from the workspace manifests alone, so the layer stays
|
|
// cached while only sources change. A workspace missing there would fail npm ci in the image.
|
|
describe('service image', () => {
|
|
it('copies every workspace manifest before installing dependencies', async () => {
|
|
const { workspaces } = JSON.parse(await readFile('package.json', 'utf8')) as { workspaces: string[] };
|
|
const directories = (
|
|
await Promise.all(
|
|
workspaces.map(async pattern =>
|
|
pattern.endsWith('/*')
|
|
? (await readdir(pattern.slice(0, -2))).map(name => `${pattern.slice(0, -2)}/${name}`)
|
|
: [pattern],
|
|
),
|
|
)
|
|
)
|
|
.flat()
|
|
.filter(directory => existsSync(`${directory}/package.json`));
|
|
const dockerfile = await readFile('infra/images/runtime.Dockerfile', 'utf8');
|
|
const install = dockerfile.indexOf('RUN npm ci');
|
|
expect(install).toBeGreaterThan(0);
|
|
for (const directory of directories) {
|
|
const manifest = dockerfile.indexOf(`COPY ${directory}/package.json ./${directory}/`);
|
|
expect(manifest, directory).toBeGreaterThan(0);
|
|
expect(manifest, directory).toBeLessThan(install);
|
|
// Its sources (the workspace, or its whole parent directory) come only after the installation.
|
|
const parent = directory.split('/')[0];
|
|
const sources = [`COPY ${directory} ./${directory}`, `COPY ${parent} ./${parent}\n`].map(line =>
|
|
dockerfile.indexOf(line, install),
|
|
);
|
|
expect(Math.max(...sources), directory).toBeGreaterThan(install);
|
|
}
|
|
});
|
|
});
|