-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathdocker-compose.test.ts
More file actions
76 lines (67 loc) · 2.05 KB
/
docker-compose.test.ts
File metadata and controls
76 lines (67 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import { parse } from "yaml";
type ComposeService = {
container_name?: string;
image?: string;
build?: {
context?: string;
dockerfile?: string;
};
ports?: Array<number | string>;
volumes?: string[];
depends_on?: string[];
environment?: Record<string, string | number>;
};
type ComposeFile = {
name?: string;
services?: Record<string, ComposeService>;
volumes?: Record<string, unknown>;
};
const composePath = fileURLToPath(
new URL("./docker-compose.yml", import.meta.url),
);
async function readCompose() {
const source = await readFile(composePath, "utf8");
return parse(source) as ComposeFile;
}
describe("local Docker compose file", () => {
it("keeps the expected local development services wired", async () => {
const compose = await readCompose();
expect(compose.name).toBe("cap-so-dev");
expect(Object.keys(compose.services ?? {}).sort()).toEqual([
"cap-media-server",
"createbuckets",
"minio",
"ps-mysql",
]);
expect(compose.services?.["ps-mysql"]).toMatchObject({
image: "mysql:8.0",
container_name: "mysql-primary-db",
});
expect(compose.services?.["cap-media-server"]?.build).toEqual({
context: "../..",
dockerfile: "apps/media-server/Dockerfile",
});
expect(compose.services?.minio?.ports).toEqual(["9000:9000", "9001:9001"]);
expect(compose.services?.createbuckets?.depends_on).toEqual(["minio"]);
});
it("does not declare stale named volumes", async () => {
const compose = await readCompose();
const declaredVolumes = new Set(Object.keys(compose.volumes ?? {}));
const usedNamedVolumes = new Set(
Object.values(compose.services ?? {})
.flatMap((service) => service.volumes ?? [])
.map((volume) => volume.split(":")[0])
.filter(
(source) =>
source &&
!source.startsWith(".") &&
!source.startsWith("/") &&
!source.startsWith("~"),
),
);
expect([...declaredVolumes].sort()).toEqual([...usedNamedVolumes].sort());
});
});