@rcpooley/concord 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +318 -0
- package/bin/concord.service +69 -0
- package/dist/age.d.ts +20 -0
- package/dist/age.d.ts.map +1 -0
- package/dist/age.js +58 -0
- package/dist/age.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +301 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/daemon.d.ts +4 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +394 -0
- package/dist/daemon.js.map +1 -0
- package/dist/eval-config.d.ts +2 -0
- package/dist/eval-config.d.ts.map +1 -0
- package/dist/eval-config.js +45 -0
- package/dist/eval-config.js.map +1 -0
- package/dist/exec.d.ts +168 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +313 -0
- package/dist/exec.js.map +1 -0
- package/dist/git.d.ts +59 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +265 -0
- package/dist/git.js.map +1 -0
- package/dist/hook.d.ts +37 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +89 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +76 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +236 -0
- package/dist/init.js.map +1 -0
- package/dist/loader.d.ts +35 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +230 -0
- package/dist/loader.js.map +1 -0
- package/dist/module.d.ts +116 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +100 -0
- package/dist/module.js.map +1 -0
- package/dist/modules/apt/index.d.ts +45 -0
- package/dist/modules/apt/index.d.ts.map +1 -0
- package/dist/modules/apt/index.js +249 -0
- package/dist/modules/apt/index.js.map +1 -0
- package/dist/modules/apt/schema.d.ts +63 -0
- package/dist/modules/apt/schema.d.ts.map +1 -0
- package/dist/modules/apt/schema.js +75 -0
- package/dist/modules/apt/schema.js.map +1 -0
- package/dist/modules/checkout/index.d.ts +88 -0
- package/dist/modules/checkout/index.d.ts.map +1 -0
- package/dist/modules/checkout/index.js +382 -0
- package/dist/modules/checkout/index.js.map +1 -0
- package/dist/modules/checkout/schema.d.ts +52 -0
- package/dist/modules/checkout/schema.d.ts.map +1 -0
- package/dist/modules/checkout/schema.js +132 -0
- package/dist/modules/checkout/schema.js.map +1 -0
- package/dist/modules/cloudflare/api.d.ts +64 -0
- package/dist/modules/cloudflare/api.d.ts.map +1 -0
- package/dist/modules/cloudflare/api.js +98 -0
- package/dist/modules/cloudflare/api.js.map +1 -0
- package/dist/modules/cloudflare/index.d.ts +74 -0
- package/dist/modules/cloudflare/index.d.ts.map +1 -0
- package/dist/modules/cloudflare/index.js +374 -0
- package/dist/modules/cloudflare/index.js.map +1 -0
- package/dist/modules/cloudflare/schema.d.ts +62 -0
- package/dist/modules/cloudflare/schema.d.ts.map +1 -0
- package/dist/modules/cloudflare/schema.js +85 -0
- package/dist/modules/cloudflare/schema.js.map +1 -0
- package/dist/modules/docker/index.d.ts +83 -0
- package/dist/modules/docker/index.d.ts.map +1 -0
- package/dist/modules/docker/index.js +470 -0
- package/dist/modules/docker/index.js.map +1 -0
- package/dist/modules/docker/registry.d.ts +35 -0
- package/dist/modules/docker/registry.d.ts.map +1 -0
- package/dist/modules/docker/registry.js +95 -0
- package/dist/modules/docker/registry.js.map +1 -0
- package/dist/modules/docker/render.d.ts +45 -0
- package/dist/modules/docker/render.d.ts.map +1 -0
- package/dist/modules/docker/render.js +162 -0
- package/dist/modules/docker/render.js.map +1 -0
- package/dist/modules/docker/schema.d.ts +231 -0
- package/dist/modules/docker/schema.d.ts.map +1 -0
- package/dist/modules/docker/schema.js +335 -0
- package/dist/modules/docker/schema.js.map +1 -0
- package/dist/modules/docker/sweeper.d.ts +64 -0
- package/dist/modules/docker/sweeper.d.ts.map +1 -0
- package/dist/modules/docker/sweeper.js +94 -0
- package/dist/modules/docker/sweeper.js.map +1 -0
- package/dist/modules/file/index.d.ts +79 -0
- package/dist/modules/file/index.d.ts.map +1 -0
- package/dist/modules/file/index.js +305 -0
- package/dist/modules/file/index.js.map +1 -0
- package/dist/modules/file/schema.d.ts +45 -0
- package/dist/modules/file/schema.d.ts.map +1 -0
- package/dist/modules/file/schema.js +114 -0
- package/dist/modules/file/schema.js.map +1 -0
- package/dist/modules/index.d.ts +20 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +11 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/porkbun/api.d.ts +36 -0
- package/dist/modules/porkbun/api.d.ts.map +1 -0
- package/dist/modules/porkbun/api.js +62 -0
- package/dist/modules/porkbun/api.js.map +1 -0
- package/dist/modules/porkbun/index.d.ts +50 -0
- package/dist/modules/porkbun/index.d.ts.map +1 -0
- package/dist/modules/porkbun/index.js +236 -0
- package/dist/modules/porkbun/index.js.map +1 -0
- package/dist/modules/porkbun/schema.d.ts +38 -0
- package/dist/modules/porkbun/schema.d.ts.map +1 -0
- package/dist/modules/porkbun/schema.js +39 -0
- package/dist/modules/porkbun/schema.js.map +1 -0
- package/dist/modules/script/index.d.ts +43 -0
- package/dist/modules/script/index.d.ts.map +1 -0
- package/dist/modules/script/index.js +116 -0
- package/dist/modules/script/index.js.map +1 -0
- package/dist/modules/script/schema.d.ts +25 -0
- package/dist/modules/script/schema.d.ts.map +1 -0
- package/dist/modules/script/schema.js +63 -0
- package/dist/modules/script/schema.js.map +1 -0
- package/dist/modules/systemd/index.d.ts +93 -0
- package/dist/modules/systemd/index.d.ts.map +1 -0
- package/dist/modules/systemd/index.js +394 -0
- package/dist/modules/systemd/index.js.map +1 -0
- package/dist/modules/systemd/render.d.ts +41 -0
- package/dist/modules/systemd/render.d.ts.map +1 -0
- package/dist/modules/systemd/render.js +252 -0
- package/dist/modules/systemd/render.js.map +1 -0
- package/dist/modules/systemd/schema.d.ts +293 -0
- package/dist/modules/systemd/schema.d.ts.map +1 -0
- package/dist/modules/systemd/schema.js +302 -0
- package/dist/modules/systemd/schema.js.map +1 -0
- package/dist/modules/systemd/sweeper.d.ts +31 -0
- package/dist/modules/systemd/sweeper.d.ts.map +1 -0
- package/dist/modules/systemd/sweeper.js +77 -0
- package/dist/modules/systemd/sweeper.js.map +1 -0
- package/dist/plans.d.ts +132 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.js +315 -0
- package/dist/plans.js.map +1 -0
- package/dist/records.d.ts +37 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +100 -0
- package/dist/records.js.map +1 -0
- package/dist/registry.d.ts +38 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +31 -0
- package/dist/registry.js.map +1 -0
- package/dist/runner.d.ts +48 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +150 -0
- package/dist/runner.js.map +1 -0
- package/dist/scheduler.d.ts +36 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +77 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/schema.d.ts +762 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +185 -0
- package/dist/schema.js.map +1 -0
- package/dist/secret.d.ts +24 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +3 -0
- package/dist/secret.js.map +1 -0
- package/dist/ui.d.ts +62 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +288 -0
- package/dist/ui.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { Module } from '../../module.js';
|
|
3
|
+
import { archiveTree, mirrorHas, resolveRefs, syncMirror } from '../../git.js';
|
|
4
|
+
import { LABEL_APP, LABEL_SPEC, LABEL_VERSION, imageRef, render, serialize } from './render.js';
|
|
5
|
+
import { resolveDigest } from './registry.js';
|
|
6
|
+
import { isImageSource } from './schema.js';
|
|
7
|
+
export { render, serialize, imageTag, imageRef } from './render.js';
|
|
8
|
+
export { resolveRefs, cloneUrl, githubSlug } from '../../git.js';
|
|
9
|
+
export { resolveDigest, parseImage } from './registry.js';
|
|
10
|
+
/** Base64 inflates by ~4/3; a context past this is a mistake, not a build. */
|
|
11
|
+
const MAX_CONTEXT_BYTES = 96 * 1024 * 1024;
|
|
12
|
+
/** A commit shortens to 7; a digest keeps its `sha256:` prefix legible. */
|
|
13
|
+
const short = (v) => (v.startsWith('sha256:') ? v.slice(7, 19) : v.slice(0, 7));
|
|
14
|
+
/** Single-quote for a POSIX shell. Scripts are built here, run over stdin. */
|
|
15
|
+
const sq = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
16
|
+
export function parseContainers(stdout) {
|
|
17
|
+
const out = [];
|
|
18
|
+
for (const line of stdout.split('\n')) {
|
|
19
|
+
if (!line.trim())
|
|
20
|
+
continue;
|
|
21
|
+
const [name, version, spec, running, health] = line.split('\t');
|
|
22
|
+
if (!name)
|
|
23
|
+
continue;
|
|
24
|
+
out.push({
|
|
25
|
+
name,
|
|
26
|
+
present: true,
|
|
27
|
+
version: version || null,
|
|
28
|
+
specHash: spec || null,
|
|
29
|
+
running: running === 'true',
|
|
30
|
+
// Docker reports starting | healthy | unhealthy, or empty for no
|
|
31
|
+
// healthcheck. `starting` is not a verdict — the container is inside its
|
|
32
|
+
// startPeriod and has not been judged yet, so it reads the same as having
|
|
33
|
+
// no healthcheck at all. Docker flips it to unhealthy once the period
|
|
34
|
+
// elapses, which is what drift detection acts on.
|
|
35
|
+
healthy: !health || health === 'starting' ? null : health === 'healthy',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
// --------------------------------------------------------------- module ----
|
|
41
|
+
export class DockerModule extends Module {
|
|
42
|
+
config;
|
|
43
|
+
kind = 'docker';
|
|
44
|
+
/** Populated by desired(); read by apply(). Never carried on an op — it holds secrets. */
|
|
45
|
+
#resolved = new Map();
|
|
46
|
+
/** Apps whose desired state could not be determined, and why. */
|
|
47
|
+
#unresolved = new Map();
|
|
48
|
+
/** Decrypted once in desired(), reused by apply(). Never leaves the primary. */
|
|
49
|
+
#token;
|
|
50
|
+
constructor(config) {
|
|
51
|
+
super(config.id, config.host);
|
|
52
|
+
this.config = config;
|
|
53
|
+
}
|
|
54
|
+
/** Declared container names — the sweep keep-set contribution. These are
|
|
55
|
+
* also the compose project names (`dev.concord.app`), which is what the
|
|
56
|
+
* sweeper matches live containers against. */
|
|
57
|
+
owned() {
|
|
58
|
+
return this.containers.map((a) => a.name);
|
|
59
|
+
}
|
|
60
|
+
get containers() {
|
|
61
|
+
return this.config.containers ?? [];
|
|
62
|
+
}
|
|
63
|
+
dir(name) {
|
|
64
|
+
return join(this.config.root, name);
|
|
65
|
+
}
|
|
66
|
+
composePath(name) {
|
|
67
|
+
return join(this.dir(name), 'docker-compose.yml');
|
|
68
|
+
}
|
|
69
|
+
// ------------------------------------------------------------ desired ----
|
|
70
|
+
async desired() {
|
|
71
|
+
const seen = new Set();
|
|
72
|
+
for (const a of this.containers) {
|
|
73
|
+
if (seen.has(a.name))
|
|
74
|
+
throw new Error(`${this.scope}: app "${a.name}" declared twice`);
|
|
75
|
+
seen.add(a.name);
|
|
76
|
+
}
|
|
77
|
+
this.#resolved.clear();
|
|
78
|
+
this.#unresolved.clear();
|
|
79
|
+
const declared = this.settings.git?.token;
|
|
80
|
+
this.#token = declared ? await this.secret(declared) : undefined;
|
|
81
|
+
const token = this.#token;
|
|
82
|
+
// One batched request for every tracked GIT app; pinned apps cost no
|
|
83
|
+
// network at all. Failures are per app so that one deleted branch cannot
|
|
84
|
+
// decide the fate of every other app in the module.
|
|
85
|
+
const tracked = this.containers
|
|
86
|
+
.filter((a) => !isImageSource(a.source) && a.source.track)
|
|
87
|
+
.map((a) => {
|
|
88
|
+
const s = a.source;
|
|
89
|
+
return {
|
|
90
|
+
app: a.name,
|
|
91
|
+
repo: s.repo,
|
|
92
|
+
branch: s.track.branch,
|
|
93
|
+
// The build context IS the watch path: a sibling app in the same repo
|
|
94
|
+
// must not trigger a rebuild here.
|
|
95
|
+
path: s.context,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
const tips = tracked.length
|
|
99
|
+
? await resolveRefs(tracked, token, (repo) => syncMirror(join(this.stateDir, 'repos'), repo, token))
|
|
100
|
+
: new Map();
|
|
101
|
+
// Image tags resolve to digests against their registry, for the same reason
|
|
102
|
+
// and with the same guarantee: a bare tag in the spec would never change.
|
|
103
|
+
const digests = new Map();
|
|
104
|
+
for (const a of this.containers) {
|
|
105
|
+
if (!isImageSource(a.source) || !a.source.track)
|
|
106
|
+
continue;
|
|
107
|
+
const got = await resolveDigest(a.source.image, a.source.track.tag);
|
|
108
|
+
if ('error' in got)
|
|
109
|
+
this.#unresolved.set(a.name, got.error);
|
|
110
|
+
else
|
|
111
|
+
digests.set(a.name, got.digest);
|
|
112
|
+
}
|
|
113
|
+
const containers = [];
|
|
114
|
+
for (const a of this.containers) {
|
|
115
|
+
if (this.#unresolved.has(a.name))
|
|
116
|
+
continue;
|
|
117
|
+
let version;
|
|
118
|
+
if (isImageSource(a.source)) {
|
|
119
|
+
if (a.source.pin) {
|
|
120
|
+
version = a.source.pin.digest;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const d = digests.get(a.name);
|
|
124
|
+
if (!d)
|
|
125
|
+
continue;
|
|
126
|
+
version = d;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (a.source.pin) {
|
|
130
|
+
version = a.source.pin.commit;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const got = tips.get(a.name);
|
|
134
|
+
if (!got || 'error' in got) {
|
|
135
|
+
this.#unresolved.set(a.name, got?.error ?? `could not resolve ${a.source.track.branch}`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
version = got.commit;
|
|
139
|
+
}
|
|
140
|
+
const env = { ...(a.env ?? {}) };
|
|
141
|
+
for (const [k, ref] of Object.entries(a.secretEnv ?? {})) {
|
|
142
|
+
env[k] = await this.secret(ref);
|
|
143
|
+
}
|
|
144
|
+
const { compose, specHash } = render(a, version, env);
|
|
145
|
+
this.#resolved.set(a.name, { version, specHash, composeText: serialize(compose) });
|
|
146
|
+
containers.push({
|
|
147
|
+
name: a.name,
|
|
148
|
+
present: true,
|
|
149
|
+
version,
|
|
150
|
+
specHash,
|
|
151
|
+
running: true,
|
|
152
|
+
healthy: null,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// An app we could not resolve is NOT converged. It is reported here rather
|
|
156
|
+
// than silently omitted, and a blocking app fails the module outright.
|
|
157
|
+
const blocking = [...this.#unresolved].filter(([name]) => !this.containers.find((a) => a.name === name)?.failureIsWarning);
|
|
158
|
+
if (blocking.length) {
|
|
159
|
+
throw new Error(`${this.scope}: could not determine desired state for ` +
|
|
160
|
+
blocking.map(([n, why]) => `"${n}" (${why})`).join(', '));
|
|
161
|
+
}
|
|
162
|
+
for (const [name, why] of this.#unresolved) {
|
|
163
|
+
this.warn(`${name}: not deployed — ${why}`);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
networks: (this.config.networks ?? []).map((n) => ({
|
|
167
|
+
name: n.name,
|
|
168
|
+
present: true,
|
|
169
|
+
driver: n.driver,
|
|
170
|
+
})),
|
|
171
|
+
containers,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// --------------------------------------------------------------- read ----
|
|
175
|
+
/**
|
|
176
|
+
* Live state comes from the CONTAINER's own labels, not from files on disk.
|
|
177
|
+
*
|
|
178
|
+
* The container is what is actually running, so it is the honest source. It
|
|
179
|
+
* also means an out-of-band `docker run`, a hand-edited compose file, or a
|
|
180
|
+
* half-finished deploy all read as drift rather than as convergence — none of
|
|
181
|
+
* them carry a matching `dev.concord.spec`.
|
|
182
|
+
*/
|
|
183
|
+
async read() {
|
|
184
|
+
// Networks first, and unconditionally: a module may declare a network and
|
|
185
|
+
// no containers at all, which is exactly how a shared network gets an owner.
|
|
186
|
+
const networks = this.readNetworks();
|
|
187
|
+
const names = new Set(this.containers.map((a) => a.name));
|
|
188
|
+
if (!names.size)
|
|
189
|
+
return { networks, containers: [] };
|
|
190
|
+
const ids = this.exec
|
|
191
|
+
.run('sudo', [
|
|
192
|
+
'-n',
|
|
193
|
+
'docker',
|
|
194
|
+
'ps',
|
|
195
|
+
'-a',
|
|
196
|
+
'--filter',
|
|
197
|
+
`label=${LABEL_APP}`,
|
|
198
|
+
'--format',
|
|
199
|
+
'{{.ID}}',
|
|
200
|
+
])
|
|
201
|
+
.stdout.split('\n')
|
|
202
|
+
.map((s) => s.trim())
|
|
203
|
+
.filter(Boolean);
|
|
204
|
+
const live = ids.length
|
|
205
|
+
? parseContainers(this.exec.run('sudo', [
|
|
206
|
+
'-n',
|
|
207
|
+
'docker',
|
|
208
|
+
'inspect',
|
|
209
|
+
...ids,
|
|
210
|
+
'--format',
|
|
211
|
+
`{{index .Config.Labels "${LABEL_APP}"}}\t` +
|
|
212
|
+
`{{index .Config.Labels "${LABEL_VERSION}"}}\t` +
|
|
213
|
+
`{{index .Config.Labels "${LABEL_SPEC}"}}\t` +
|
|
214
|
+
'{{.State.Running}}\t' +
|
|
215
|
+
'{{if .State.Health}}{{.State.Health.Status}}{{end}}',
|
|
216
|
+
]).stdout)
|
|
217
|
+
: [];
|
|
218
|
+
const byName = new Map(live.map((s) => [s.name, s]));
|
|
219
|
+
return {
|
|
220
|
+
networks,
|
|
221
|
+
containers: this.containers
|
|
222
|
+
.filter((a) => this.#resolved.has(a.name) || !this.#unresolved.has(a.name))
|
|
223
|
+
.map((a) => byName.get(a.name) ?? {
|
|
224
|
+
name: a.name,
|
|
225
|
+
present: false,
|
|
226
|
+
version: null,
|
|
227
|
+
specHash: null,
|
|
228
|
+
running: false,
|
|
229
|
+
healthy: null,
|
|
230
|
+
}),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// --------------------------------------------------------------- diff ----
|
|
234
|
+
/**
|
|
235
|
+
* `docker network ls`, filtered to what is declared.
|
|
236
|
+
*
|
|
237
|
+
* Additive: a network nobody declared is never read and never touched. This
|
|
238
|
+
* host has networks docker itself made (`bridge`, `host`, `none`) and others
|
|
239
|
+
* left behind by tools long gone — enumerating them would invite a diff that
|
|
240
|
+
* wants to delete them.
|
|
241
|
+
*/
|
|
242
|
+
readNetworks() {
|
|
243
|
+
const want = this.config.networks ?? [];
|
|
244
|
+
if (!want.length)
|
|
245
|
+
return [];
|
|
246
|
+
const out = this.exec.run('sudo', [
|
|
247
|
+
'-n', 'docker', 'network', 'ls', '--format', '{{.Name}}\t{{.Driver}}',
|
|
248
|
+
]).stdout;
|
|
249
|
+
const live = new Map(out
|
|
250
|
+
.split('\n')
|
|
251
|
+
.map((l) => l.trim().split('\t'))
|
|
252
|
+
.filter((p) => p.length === 2 && p[0])
|
|
253
|
+
.map(([name, driver]) => [name, driver]));
|
|
254
|
+
return want.map((n) => ({
|
|
255
|
+
name: n.name,
|
|
256
|
+
present: live.has(n.name),
|
|
257
|
+
driver: live.get(n.name) ?? null,
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
diff(actual, desired) {
|
|
261
|
+
const ops = [];
|
|
262
|
+
// Networks FIRST, always: a container joining one renders `external: true`,
|
|
263
|
+
// so compose refuses to start until it exists. Ordering them ahead here is
|
|
264
|
+
// what lets one run create a network and fill it.
|
|
265
|
+
const liveNet = new Map(actual.networks.map((n) => [n.name, n]));
|
|
266
|
+
for (const want of desired.networks) {
|
|
267
|
+
const have = liveNet.get(want.name);
|
|
268
|
+
if (!have?.present) {
|
|
269
|
+
ops.push({
|
|
270
|
+
kind: 'create',
|
|
271
|
+
entity: 'network',
|
|
272
|
+
id: `network/${want.name}`,
|
|
273
|
+
summary: `create network ${want.name} (${want.driver})`,
|
|
274
|
+
name: want.name,
|
|
275
|
+
action: 'create-network',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
else if (have.driver !== want.driver) {
|
|
279
|
+
// Not fixable in place: docker has no `network update`, and recreating
|
|
280
|
+
// one would detach every container on it. Say so and stop.
|
|
281
|
+
throw new Error(`${this.kind}:${this.id}: network "${want.name}" is a ${have.driver} network ` +
|
|
282
|
+
`but is declared as ${want.driver}. Docker cannot change a network's driver; ` +
|
|
283
|
+
`remove it by hand once nothing is attached, or declare the driver it has.`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const byName = new Map(actual.containers.map((a) => [a.name, a]));
|
|
287
|
+
for (const want of desired.containers) {
|
|
288
|
+
const have = byName.get(want.name);
|
|
289
|
+
const reasons = [];
|
|
290
|
+
if (!have?.present) {
|
|
291
|
+
reasons.push(`new at ${short(want.version)}`);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
const moved = have.version !== want.version;
|
|
295
|
+
if (moved) {
|
|
296
|
+
reasons.push(have.version
|
|
297
|
+
? `${short(have.version)} → ${short(want.version)}`
|
|
298
|
+
: `unlabelled → ${short(want.version)}`);
|
|
299
|
+
}
|
|
300
|
+
// "The code changed" and "the config changed" are different events and
|
|
301
|
+
// a plan should say which. Only reported when the commit did NOT move,
|
|
302
|
+
// because the commit is part of the spec — saying both every time would
|
|
303
|
+
// train the reader to ignore it.
|
|
304
|
+
if (!moved && have.specHash !== want.specHash)
|
|
305
|
+
reasons.push('config changed');
|
|
306
|
+
if (!have.running)
|
|
307
|
+
reasons.push('not running');
|
|
308
|
+
if (have.healthy === false)
|
|
309
|
+
reasons.push('unhealthy');
|
|
310
|
+
}
|
|
311
|
+
if (reasons.length) {
|
|
312
|
+
ops.push({
|
|
313
|
+
kind: have?.present ? 'update' : 'create',
|
|
314
|
+
entity: 'app',
|
|
315
|
+
id: `app/${want.name}`,
|
|
316
|
+
summary: `deploy ${want.name} (${reasons.join('; ')})`,
|
|
317
|
+
name: want.name,
|
|
318
|
+
action: 'deploy',
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return ops;
|
|
323
|
+
}
|
|
324
|
+
// -------------------------------------------------------------- apply ----
|
|
325
|
+
async apply(ops) {
|
|
326
|
+
const blocking = [];
|
|
327
|
+
// Before any container: `external: true` means compose will not make one.
|
|
328
|
+
for (const op of ops.filter((o) => o.entity === 'network')) {
|
|
329
|
+
const want = (this.config.networks ?? []).find((n) => n.name === op.name);
|
|
330
|
+
this.exec.sudo(['docker', 'network', 'create', '--driver', want.driver, want.name]);
|
|
331
|
+
this.log(` ✓ ${op.kind}: ${op.summary}`);
|
|
332
|
+
}
|
|
333
|
+
for (const op of ops.filter((o) => o.action === 'deploy')) {
|
|
334
|
+
const app = this.containers.find((a) => a.name === op.name);
|
|
335
|
+
try {
|
|
336
|
+
await this.deploy(app);
|
|
337
|
+
this.log(` ✓ ${op.kind}: ${op.summary}`);
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
const why = err instanceof Error ? err.message : String(err);
|
|
341
|
+
if (app.failureIsWarning) {
|
|
342
|
+
// Still on its previous commit — a known state, not an unknown one,
|
|
343
|
+
// which is why this is a warning rather than a skipped module.
|
|
344
|
+
this.warn(`${app.name}: ${why}`);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
// Collected, not thrown: a broken repo must not stop its siblings
|
|
348
|
+
// from deploying. The module still fails once every app is attempted.
|
|
349
|
+
blocking.push(`${app.name}: ${why}`);
|
|
350
|
+
this.log(` ✗ ${app.name} FAILED`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// Removal is the SWEEPER's job (sweeper.ts): a container no module
|
|
355
|
+
// declares is torn down at the tail of the run, never here.
|
|
356
|
+
if (blocking.length) {
|
|
357
|
+
throw new Error(`${blocking.length} app(s) failed:\n${blocking.map((b) => ` • ${b}`).join('\n')}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
async deploy(app) {
|
|
361
|
+
const r = this.#resolved.get(app.name);
|
|
362
|
+
if (!r)
|
|
363
|
+
throw new Error(`internal: no resolved state for "${app.name}"`);
|
|
364
|
+
// An image app has nothing to build: compose pulls the pinned digest.
|
|
365
|
+
if (!isImageSource(app.source)) {
|
|
366
|
+
const tag = imageRef(app, r.version);
|
|
367
|
+
const ctx = join(this.dir(app.name), 'context');
|
|
368
|
+
// Build only when the exact image is absent. This is what keeps a
|
|
369
|
+
// converged fleet from rebuilding every app every 15 minutes.
|
|
370
|
+
const built = this.exec.run('sudo', ['-n', 'docker', 'image', 'inspect', tag]);
|
|
371
|
+
if (built.status !== 0) {
|
|
372
|
+
this.uploadContext(app.source, r.version, ctx);
|
|
373
|
+
this.build(app.source, tag, ctx);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
for (const v of app.volumes ?? []) {
|
|
377
|
+
if (v.name)
|
|
378
|
+
this.exec.sudo(['docker', 'volume', 'create', v.name]);
|
|
379
|
+
}
|
|
380
|
+
// 0600: the rendered document carries any secretEnv values inline.
|
|
381
|
+
this.exec.writeFileAsRoot(this.composePath(app.name), r.composeText, '0600');
|
|
382
|
+
// Above the exec default: an image pull plus `--wait-timeout 180` can
|
|
383
|
+
// legitimately take longer than 600s.
|
|
384
|
+
const up = this.exec.sudoCombined([
|
|
385
|
+
'docker',
|
|
386
|
+
'compose',
|
|
387
|
+
'-p',
|
|
388
|
+
app.name,
|
|
389
|
+
'-f',
|
|
390
|
+
this.composePath(app.name),
|
|
391
|
+
'up',
|
|
392
|
+
'-d',
|
|
393
|
+
'--wait',
|
|
394
|
+
'--wait-timeout',
|
|
395
|
+
'180',
|
|
396
|
+
], { timeoutMs: 900_000 });
|
|
397
|
+
if (up.status !== 0) {
|
|
398
|
+
throw new Error(`compose up failed (exit ${up.status}):\n${tail(up.output)}`);
|
|
399
|
+
}
|
|
400
|
+
this.prune(app.name);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Fetch on the primary, extract on the target.
|
|
404
|
+
*
|
|
405
|
+
* The tar goes over the transport already established, base64 inside a quoted
|
|
406
|
+
* heredoc, so nothing is spliced into a remote shell and the target needs
|
|
407
|
+
* neither git nor any credential.
|
|
408
|
+
*/
|
|
409
|
+
uploadContext(src, commit, ctx) {
|
|
410
|
+
const mirror = syncMirror(join(this.stateDir, 'repos'), src.repo, this.#token);
|
|
411
|
+
if (!mirrorHas(mirror, commit)) {
|
|
412
|
+
throw new Error(`commit ${short(commit)} is not in ${src.repo} after fetching`);
|
|
413
|
+
}
|
|
414
|
+
const tar = archiveTree(mirror, commit, src.context);
|
|
415
|
+
if (tar.length > MAX_CONTEXT_BYTES) {
|
|
416
|
+
throw new Error(`build context is ${(tar.length / 1024 / 1024).toFixed(1)} MB, over the ` +
|
|
417
|
+
`${MAX_CONTEXT_BYTES / 1024 / 1024} MB limit. Narrow \`context\` or add a .dockerignore.`);
|
|
418
|
+
}
|
|
419
|
+
const script = [
|
|
420
|
+
'set -euo pipefail',
|
|
421
|
+
`rm -rf ${sq(ctx)}`,
|
|
422
|
+
`mkdir -p ${sq(ctx)}`,
|
|
423
|
+
`base64 -d <<'CONCORD_TAR_EOF' | tar -x -C ${sq(ctx)}`,
|
|
424
|
+
tar.toString('base64'),
|
|
425
|
+
'CONCORD_TAR_EOF',
|
|
426
|
+
].join('\n');
|
|
427
|
+
const r = this.exec.runScript(script, { sudo: true, timeoutMs: 300_000 });
|
|
428
|
+
if (r.status !== 0) {
|
|
429
|
+
throw new Error(`uploading build context failed (exit ${r.status}):\n${tail(r.output)}`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
build(src, tag, ctx) {
|
|
433
|
+
const args = Object.entries(src.buildArgs ?? {})
|
|
434
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
435
|
+
.flatMap(([k, v]) => ['--build-arg', `${k}=${v}`]);
|
|
436
|
+
const cmd = [
|
|
437
|
+
'docker',
|
|
438
|
+
'build',
|
|
439
|
+
'-t',
|
|
440
|
+
tag,
|
|
441
|
+
'-f',
|
|
442
|
+
join(ctx, src.dockerfile),
|
|
443
|
+
...args,
|
|
444
|
+
ctx,
|
|
445
|
+
]
|
|
446
|
+
.map(sq)
|
|
447
|
+
.join(' ');
|
|
448
|
+
const r = this.exec.runScript(`set -euo pipefail\n${cmd}`, {
|
|
449
|
+
sudo: true,
|
|
450
|
+
timeoutMs: src.buildTimeout * 1000,
|
|
451
|
+
});
|
|
452
|
+
if (r.status !== 0) {
|
|
453
|
+
throw new Error(`build failed (exit ${r.status === 124 ? 'timeout' : r.status}):\n${tail(r.output)}`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/** Keep the newest N tags for this app; docker lists newest first. */
|
|
457
|
+
prune(name) {
|
|
458
|
+
const keep = this.config.keepImages;
|
|
459
|
+
const script = [
|
|
460
|
+
'set -euo pipefail',
|
|
461
|
+
`docker images ${sq(`concord/${name}`)} --format '{{.Tag}}' | grep -v '^<none>$' | ` +
|
|
462
|
+
`tail -n +${keep + 1} | while read -r t; do ` +
|
|
463
|
+
`docker rmi ${sq(`concord/${name}`)}:"$t" >/dev/null 2>&1 || true; done`,
|
|
464
|
+
].join('\n');
|
|
465
|
+
this.exec.runScript(script, { sudo: true, timeoutMs: 120_000 });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/** Output may contain anything a build printed — keep it short. */
|
|
469
|
+
const tail = (s, n = 25) => s.trim().split('\n').slice(-n).join('\n');
|
|
470
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/docker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAe,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAA;AAC/F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D,KAAK,CAAC,IAAY;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;QACnC,MAAM,MAAM,GAAG;YACb,mBAAmB;YACnB,iBAAiB,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC,8CAA8C;gBAClF,YAAY,IAAI,GAAG,CAAC,yBAAyB;gBAC7C,cAAc,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC,qCAAqC;SAC3E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACZ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;IACjE,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve an image TAG to a DIGEST, on the primary.
|
|
3
|
+
*
|
|
4
|
+
* Same principle as a branch tip: the registry is an external authority the
|
|
5
|
+
* host has no say in, resolution happens once and centrally, and the resolved
|
|
6
|
+
* value goes into the plan and into the rendered compose file.
|
|
7
|
+
*
|
|
8
|
+
* Without this, an image app would carry a bare tag in its spec — so the spec
|
|
9
|
+
* hash would never change, and `nginx:alpine` would sit frozen on whatever the
|
|
10
|
+
* host first downloaded while appearing to track upstream. That is exactly the
|
|
11
|
+
* trap `compose`'s required `pull` field exists to make impossible.
|
|
12
|
+
*/
|
|
13
|
+
export interface ImageRef {
|
|
14
|
+
registry: string;
|
|
15
|
+
/** Path within the registry, already normalised (`nginx` → `library/nginx`). */
|
|
16
|
+
repository: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Docker's naming rules are historical, not principled: a single-segment name
|
|
20
|
+
* is a Docker Hub official image under `library/`, and a name is only treated
|
|
21
|
+
* as registry-qualified when its first segment looks like a host.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseImage(image: string): ImageRef;
|
|
24
|
+
export type DigestResult = {
|
|
25
|
+
digest: string;
|
|
26
|
+
} | {
|
|
27
|
+
error: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @param auth Optional `Basic <base64>` for a private registry. Unused today —
|
|
31
|
+
* only public images are resolved — but the challenge flow is
|
|
32
|
+
* where it would go, so the seam is here rather than bolted on.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveDigest(image: string, tag: string, auth?: string): Promise<DigestResult>;
|
|
35
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/modules/docker/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAYlD;AAkBD,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjE;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC,CAoCvB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve an image TAG to a DIGEST, on the primary.
|
|
3
|
+
*
|
|
4
|
+
* Same principle as a branch tip: the registry is an external authority the
|
|
5
|
+
* host has no say in, resolution happens once and centrally, and the resolved
|
|
6
|
+
* value goes into the plan and into the rendered compose file.
|
|
7
|
+
*
|
|
8
|
+
* Without this, an image app would carry a bare tag in its spec — so the spec
|
|
9
|
+
* hash would never change, and `nginx:alpine` would sit frozen on whatever the
|
|
10
|
+
* host first downloaded while appearing to track upstream. That is exactly the
|
|
11
|
+
* trap `compose`'s required `pull` field exists to make impossible.
|
|
12
|
+
*/
|
|
13
|
+
/** Manifest LISTS first: a multi-arch tag resolves to an index, not an image. */
|
|
14
|
+
const ACCEPT = [
|
|
15
|
+
'application/vnd.oci.image.index.v1+json',
|
|
16
|
+
'application/vnd.docker.distribution.manifest.list.v2+json',
|
|
17
|
+
'application/vnd.oci.image.manifest.v1+json',
|
|
18
|
+
'application/vnd.docker.distribution.manifest.v2+json',
|
|
19
|
+
].join(', ');
|
|
20
|
+
/**
|
|
21
|
+
* Docker's naming rules are historical, not principled: a single-segment name
|
|
22
|
+
* is a Docker Hub official image under `library/`, and a name is only treated
|
|
23
|
+
* as registry-qualified when its first segment looks like a host.
|
|
24
|
+
*/
|
|
25
|
+
export function parseImage(image) {
|
|
26
|
+
const parts = image.split('/');
|
|
27
|
+
const first = parts[0];
|
|
28
|
+
const looksLikeHost = parts.length > 1 && (first.includes('.') || first.includes(':') || first === 'localhost');
|
|
29
|
+
if (looksLikeHost) {
|
|
30
|
+
return { registry: first, repository: parts.slice(1).join('/') };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
registry: 'registry-1.docker.io',
|
|
34
|
+
repository: parts.length === 1 ? `library/${image}` : image,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Registries answer 401 with a WWW-Authenticate challenge describing where to get a token. */
|
|
38
|
+
async function tokenFor(ref, challenge) {
|
|
39
|
+
const get = (k) => new RegExp(`${k}="([^"]+)"`).exec(challenge)?.[1];
|
|
40
|
+
const realm = get('realm');
|
|
41
|
+
if (!realm)
|
|
42
|
+
return null;
|
|
43
|
+
const url = new URL(realm);
|
|
44
|
+
const service = get('service');
|
|
45
|
+
if (service)
|
|
46
|
+
url.searchParams.set('service', service);
|
|
47
|
+
url.searchParams.set('scope', get('scope') ?? `repository:${ref.repository}:pull`);
|
|
48
|
+
const res = await fetch(url, { headers: { 'user-agent': 'concord' } });
|
|
49
|
+
if (!res.ok)
|
|
50
|
+
return null;
|
|
51
|
+
const body = (await res.json());
|
|
52
|
+
return body.token ?? body.access_token ?? null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @param auth Optional `Basic <base64>` for a private registry. Unused today —
|
|
56
|
+
* only public images are resolved — but the challenge flow is
|
|
57
|
+
* where it would go, so the seam is here rather than bolted on.
|
|
58
|
+
*/
|
|
59
|
+
export async function resolveDigest(image, tag, auth) {
|
|
60
|
+
const ref = parseImage(image);
|
|
61
|
+
const url = `https://${ref.registry}/v2/${ref.repository}/manifests/${encodeURIComponent(tag)}`;
|
|
62
|
+
const head = (token) => fetch(url, {
|
|
63
|
+
method: 'HEAD',
|
|
64
|
+
headers: {
|
|
65
|
+
accept: ACCEPT,
|
|
66
|
+
'user-agent': 'concord',
|
|
67
|
+
...(token ? { authorization: `Bearer ${token}` } : auth ? { authorization: auth } : {}),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
let res = await head();
|
|
72
|
+
if (res.status === 401) {
|
|
73
|
+
const challenge = res.headers.get('www-authenticate');
|
|
74
|
+
const token = challenge ? await tokenFor(ref, challenge) : null;
|
|
75
|
+
if (!token)
|
|
76
|
+
return { error: `${image}:${tag} — registry demanded auth and no token could be obtained` };
|
|
77
|
+
res = await head(token);
|
|
78
|
+
}
|
|
79
|
+
if (res.status === 404) {
|
|
80
|
+
// Never "no change": we do not know what should be running.
|
|
81
|
+
return { error: `${image}:${tag} does not exist in the registry` };
|
|
82
|
+
}
|
|
83
|
+
if (!res.ok)
|
|
84
|
+
return { error: `${image}:${tag} — registry returned ${res.status} ${res.statusText}` };
|
|
85
|
+
const digest = res.headers.get('docker-content-digest');
|
|
86
|
+
if (!digest || !/^sha256:[0-9a-f]{64}$/.test(digest)) {
|
|
87
|
+
return { error: `${image}:${tag} — registry gave no usable Docker-Content-Digest` };
|
|
88
|
+
}
|
|
89
|
+
return { digest };
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
return { error: `${image}:${tag} — ${err instanceof Error ? err.message : String(err)}` };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/modules/docker/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iFAAiF;AACjF,MAAM,MAAM,GAAG;IACb,yCAAyC;IACzC,2DAA2D;IAC3D,4CAA4C;IAC5C,sDAAsD;CACvD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAQZ;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;IACvB,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,WAAW,CAAC,CAAA;IAE/G,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IAClE,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,sBAAsB;QAChC,UAAU,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC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