-
Notifications
You must be signed in to change notification settings - Fork 0
/
bake.ts
executable file
·99 lines (94 loc) · 3.13 KB
/
bake.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env -S deno run --allow-all
const usage_and_exit = () => {
console.error(
"Usage: bake.ts <sha> <ref_b64> [<base>] [<ignore_cache_error>]"
);
Deno.exit(1);
};
const run = (
sha: string,
ref_b64: string,
base: string,
ignore_cache_error: boolean
) => {
const zstd = "compression=zstd,force-compression=true";
const spec: {
group: Record<string, { targets: string[] }>;
target: Record<
string,
{
"cache-from": string[];
"cache-to": string[];
args: Record<string, string>;
dockerfile: string;
output: string[];
platforms: string[];
tags: string[];
target: string;
}
>;
} = { group: {}, target: {} };
for (const platform of [
{ os: "linux", arch: "amd64" },
{ os: "linux", arch: "arm64" },
]) {
const test_ks: string[] = [];
const prod_ks: string[] = [];
for (const [target, image_name] of [
["prod_api_v2", "/api_v2"],
["prod_envoy", "/envoy"],
["prod_nginx", "/nginx"],
["prod_postgres_migration", "/postgres_migration"],
["prod_postgres", "/postgres"],
["test_client", "/client/test"],
["tests_e2e", "/tests_e2e"],
] as const) {
const k = `${target}-${platform.os}-${platform.arch}`;
const v = {
"cache-from": [
`type=registry,ref=${base}${image_name}/cache:${ref_b64}-${platform.os}-${platform.arch}`,
`type=registry,ref=${base}${image_name}/cache:latest-${platform.os}-${platform.arch}`,
`type=registry,ref=${base}${image_name}:${ref_b64}-${platform.os}-${platform.arch}`,
`type=registry,ref=${base}${image_name}:latest-${platform.os}-${platform.arch}`,
],
"cache-to": [
`type=registry,ref=${base}${image_name}/cache:${ref_b64}-${platform.os}-${platform.arch},mode=max,${zstd},ignore-error=${ignore_cache_error}`,
`type=registry,ref=${base}${image_name}/cache:latest-${platform.os}-${platform.arch},mode=max,${zstd},ignore-error=${ignore_cache_error}`,
],
dockerfile: "Dockerfile",
output: [`type=docker,${zstd}`],
platforms: [`${platform.os}/${platform.arch}`],
tags: [`${base}${image_name}:h-${sha}-${platform.os}-${platform.arch}`],
target,
args: {
arch: platform.arch,
SOURCE_DATE_EPOCH: Deno.env.get("SOURCE_DATE_EPOCH") || "0",
},
};
spec.target[k] = v;
if (k.startsWith("prod_")) {
prod_ks.push(k);
} else {
test_ks.push(k);
}
}
spec.group[`${platform.os}-${platform.arch}-prod`] = { targets: prod_ks };
spec.group[`${platform.os}-${platform.arch}-test`] = { targets: test_ks };
}
console.log(JSON.stringify(spec, null, 2));
};
const main = (args: string[]) => {
if (args.length < 2 || 4 < args.length) {
usage_and_exit();
}
const sha = args[0];
const ref_b64 = args[1];
const base =
args[2] === undefined
? "ghcr.io/kshramt/evidence_based_scheduling"
: args[2];
const ignore_cache_error =
args[3] === undefined ? false : !!JSON.parse(args[3]);
run(sha, ref_b64, base, ignore_cache_error);
};
main(Deno.args);