@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.
Files changed (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +318 -0
  3. package/bin/concord.service +69 -0
  4. package/dist/age.d.ts +20 -0
  5. package/dist/age.d.ts.map +1 -0
  6. package/dist/age.js +58 -0
  7. package/dist/age.js.map +1 -0
  8. package/dist/cli/main.d.ts +3 -0
  9. package/dist/cli/main.d.ts.map +1 -0
  10. package/dist/cli/main.js +301 -0
  11. package/dist/cli/main.js.map +1 -0
  12. package/dist/daemon.d.ts +4 -0
  13. package/dist/daemon.d.ts.map +1 -0
  14. package/dist/daemon.js +394 -0
  15. package/dist/daemon.js.map +1 -0
  16. package/dist/eval-config.d.ts +2 -0
  17. package/dist/eval-config.d.ts.map +1 -0
  18. package/dist/eval-config.js +45 -0
  19. package/dist/eval-config.js.map +1 -0
  20. package/dist/exec.d.ts +168 -0
  21. package/dist/exec.d.ts.map +1 -0
  22. package/dist/exec.js +313 -0
  23. package/dist/exec.js.map +1 -0
  24. package/dist/git.d.ts +59 -0
  25. package/dist/git.d.ts.map +1 -0
  26. package/dist/git.js +265 -0
  27. package/dist/git.js.map +1 -0
  28. package/dist/hook.d.ts +37 -0
  29. package/dist/hook.d.ts.map +1 -0
  30. package/dist/hook.js +89 -0
  31. package/dist/hook.js.map +1 -0
  32. package/dist/index.d.ts +18 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +15 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/init.d.ts +76 -0
  37. package/dist/init.d.ts.map +1 -0
  38. package/dist/init.js +236 -0
  39. package/dist/init.js.map +1 -0
  40. package/dist/loader.d.ts +35 -0
  41. package/dist/loader.d.ts.map +1 -0
  42. package/dist/loader.js +230 -0
  43. package/dist/loader.js.map +1 -0
  44. package/dist/module.d.ts +116 -0
  45. package/dist/module.d.ts.map +1 -0
  46. package/dist/module.js +100 -0
  47. package/dist/module.js.map +1 -0
  48. package/dist/modules/apt/index.d.ts +45 -0
  49. package/dist/modules/apt/index.d.ts.map +1 -0
  50. package/dist/modules/apt/index.js +249 -0
  51. package/dist/modules/apt/index.js.map +1 -0
  52. package/dist/modules/apt/schema.d.ts +63 -0
  53. package/dist/modules/apt/schema.d.ts.map +1 -0
  54. package/dist/modules/apt/schema.js +75 -0
  55. package/dist/modules/apt/schema.js.map +1 -0
  56. package/dist/modules/checkout/index.d.ts +88 -0
  57. package/dist/modules/checkout/index.d.ts.map +1 -0
  58. package/dist/modules/checkout/index.js +382 -0
  59. package/dist/modules/checkout/index.js.map +1 -0
  60. package/dist/modules/checkout/schema.d.ts +52 -0
  61. package/dist/modules/checkout/schema.d.ts.map +1 -0
  62. package/dist/modules/checkout/schema.js +132 -0
  63. package/dist/modules/checkout/schema.js.map +1 -0
  64. package/dist/modules/cloudflare/api.d.ts +64 -0
  65. package/dist/modules/cloudflare/api.d.ts.map +1 -0
  66. package/dist/modules/cloudflare/api.js +98 -0
  67. package/dist/modules/cloudflare/api.js.map +1 -0
  68. package/dist/modules/cloudflare/index.d.ts +74 -0
  69. package/dist/modules/cloudflare/index.d.ts.map +1 -0
  70. package/dist/modules/cloudflare/index.js +374 -0
  71. package/dist/modules/cloudflare/index.js.map +1 -0
  72. package/dist/modules/cloudflare/schema.d.ts +62 -0
  73. package/dist/modules/cloudflare/schema.d.ts.map +1 -0
  74. package/dist/modules/cloudflare/schema.js +85 -0
  75. package/dist/modules/cloudflare/schema.js.map +1 -0
  76. package/dist/modules/docker/index.d.ts +83 -0
  77. package/dist/modules/docker/index.d.ts.map +1 -0
  78. package/dist/modules/docker/index.js +470 -0
  79. package/dist/modules/docker/index.js.map +1 -0
  80. package/dist/modules/docker/registry.d.ts +35 -0
  81. package/dist/modules/docker/registry.d.ts.map +1 -0
  82. package/dist/modules/docker/registry.js +95 -0
  83. package/dist/modules/docker/registry.js.map +1 -0
  84. package/dist/modules/docker/render.d.ts +45 -0
  85. package/dist/modules/docker/render.d.ts.map +1 -0
  86. package/dist/modules/docker/render.js +162 -0
  87. package/dist/modules/docker/render.js.map +1 -0
  88. package/dist/modules/docker/schema.d.ts +231 -0
  89. package/dist/modules/docker/schema.d.ts.map +1 -0
  90. package/dist/modules/docker/schema.js +335 -0
  91. package/dist/modules/docker/schema.js.map +1 -0
  92. package/dist/modules/docker/sweeper.d.ts +64 -0
  93. package/dist/modules/docker/sweeper.d.ts.map +1 -0
  94. package/dist/modules/docker/sweeper.js +94 -0
  95. package/dist/modules/docker/sweeper.js.map +1 -0
  96. package/dist/modules/file/index.d.ts +79 -0
  97. package/dist/modules/file/index.d.ts.map +1 -0
  98. package/dist/modules/file/index.js +305 -0
  99. package/dist/modules/file/index.js.map +1 -0
  100. package/dist/modules/file/schema.d.ts +45 -0
  101. package/dist/modules/file/schema.d.ts.map +1 -0
  102. package/dist/modules/file/schema.js +114 -0
  103. package/dist/modules/file/schema.js.map +1 -0
  104. package/dist/modules/index.d.ts +20 -0
  105. package/dist/modules/index.d.ts.map +1 -0
  106. package/dist/modules/index.js +11 -0
  107. package/dist/modules/index.js.map +1 -0
  108. package/dist/modules/porkbun/api.d.ts +36 -0
  109. package/dist/modules/porkbun/api.d.ts.map +1 -0
  110. package/dist/modules/porkbun/api.js +62 -0
  111. package/dist/modules/porkbun/api.js.map +1 -0
  112. package/dist/modules/porkbun/index.d.ts +50 -0
  113. package/dist/modules/porkbun/index.d.ts.map +1 -0
  114. package/dist/modules/porkbun/index.js +236 -0
  115. package/dist/modules/porkbun/index.js.map +1 -0
  116. package/dist/modules/porkbun/schema.d.ts +38 -0
  117. package/dist/modules/porkbun/schema.d.ts.map +1 -0
  118. package/dist/modules/porkbun/schema.js +39 -0
  119. package/dist/modules/porkbun/schema.js.map +1 -0
  120. package/dist/modules/script/index.d.ts +43 -0
  121. package/dist/modules/script/index.d.ts.map +1 -0
  122. package/dist/modules/script/index.js +116 -0
  123. package/dist/modules/script/index.js.map +1 -0
  124. package/dist/modules/script/schema.d.ts +25 -0
  125. package/dist/modules/script/schema.d.ts.map +1 -0
  126. package/dist/modules/script/schema.js +63 -0
  127. package/dist/modules/script/schema.js.map +1 -0
  128. package/dist/modules/systemd/index.d.ts +93 -0
  129. package/dist/modules/systemd/index.d.ts.map +1 -0
  130. package/dist/modules/systemd/index.js +394 -0
  131. package/dist/modules/systemd/index.js.map +1 -0
  132. package/dist/modules/systemd/render.d.ts +41 -0
  133. package/dist/modules/systemd/render.d.ts.map +1 -0
  134. package/dist/modules/systemd/render.js +252 -0
  135. package/dist/modules/systemd/render.js.map +1 -0
  136. package/dist/modules/systemd/schema.d.ts +293 -0
  137. package/dist/modules/systemd/schema.d.ts.map +1 -0
  138. package/dist/modules/systemd/schema.js +302 -0
  139. package/dist/modules/systemd/schema.js.map +1 -0
  140. package/dist/modules/systemd/sweeper.d.ts +31 -0
  141. package/dist/modules/systemd/sweeper.d.ts.map +1 -0
  142. package/dist/modules/systemd/sweeper.js +77 -0
  143. package/dist/modules/systemd/sweeper.js.map +1 -0
  144. package/dist/plans.d.ts +132 -0
  145. package/dist/plans.d.ts.map +1 -0
  146. package/dist/plans.js +315 -0
  147. package/dist/plans.js.map +1 -0
  148. package/dist/records.d.ts +37 -0
  149. package/dist/records.d.ts.map +1 -0
  150. package/dist/records.js +100 -0
  151. package/dist/records.js.map +1 -0
  152. package/dist/registry.d.ts +38 -0
  153. package/dist/registry.d.ts.map +1 -0
  154. package/dist/registry.js +31 -0
  155. package/dist/registry.js.map +1 -0
  156. package/dist/runner.d.ts +48 -0
  157. package/dist/runner.d.ts.map +1 -0
  158. package/dist/runner.js +150 -0
  159. package/dist/runner.js.map +1 -0
  160. package/dist/scheduler.d.ts +36 -0
  161. package/dist/scheduler.d.ts.map +1 -0
  162. package/dist/scheduler.js +77 -0
  163. package/dist/scheduler.js.map +1 -0
  164. package/dist/schema.d.ts +762 -0
  165. package/dist/schema.d.ts.map +1 -0
  166. package/dist/schema.js +185 -0
  167. package/dist/schema.js.map +1 -0
  168. package/dist/secret.d.ts +24 -0
  169. package/dist/secret.d.ts.map +1 -0
  170. package/dist/secret.js +3 -0
  171. package/dist/secret.js.map +1 -0
  172. package/dist/ui.d.ts +62 -0
  173. package/dist/ui.d.ts.map +1 -0
  174. package/dist/ui.js +288 -0
  175. package/dist/ui.js.map +1 -0
  176. package/package.json +57 -0
@@ -0,0 +1,335 @@
1
+ import { z } from 'zod';
2
+ import { SecretSchema } from '../../secret.js';
3
+ /**
4
+ * An application: a git repo, built and run on a host.
5
+ *
6
+ * This is the layer ABOVE `compose`, not a replacement for it. The declaration
7
+ * is in application terms; the module renders an ordinary compose project from
8
+ * it and lets `docker compose` do the running. Docker Compose stays the driver —
9
+ * we own the declaration and the build step around it.
10
+ */
11
+ const Name = z.string().regex(/^[a-z0-9][a-z0-9-]*$/, 'must be kebab-case, starting alphanumeric');
12
+ /** `owner/name` (implies github.com) or any git URL. */
13
+ const Repo = z
14
+ .string()
15
+ .min(1)
16
+ .refine((r) => /^[\w.-]+\/[\w.-]+$/.test(r) || /^(https?|ssh|git):\/\//.test(r) || /^[\w.-]+@/.test(r), 'must be "owner/name" or a git URL');
17
+ const Commit = z.string().regex(/^[0-9a-f]{40}$/, 'must be a full 40-character commit sha');
18
+ /** Relative to the repo root, and never escaping it. */
19
+ const RelPath = z
20
+ .string()
21
+ .min(1)
22
+ .refine((p) => !p.startsWith('/'), 'must be relative to the repo root')
23
+ .refine((p) => !p.split('/').includes('..'), 'must not contain ".."');
24
+ export const GitSourceSchema = z
25
+ .object({
26
+ repo: Repo,
27
+ /**
28
+ * Follow a branch: every reconcile resolves its tip and deploys it.
29
+ *
30
+ * This is a declaration of POLICY, not a value discovered from the host —
31
+ * the branch tip is an EXTERNAL authority the host has no say in, so drift
32
+ * against it is real and detectable. That is the line Concord draws:
33
+ * desired state may come from an external authority, never from the thing
34
+ * being managed.
35
+ */
36
+ track: z.object({ branch: z.string().min(1) }).strict().optional(),
37
+ /** Deploy exactly this commit. Nothing moves until the config changes. */
38
+ pin: z.object({ commit: Commit }).strict().optional(),
39
+ /**
40
+ * Build context within the repo — often called the base directory.
41
+ *
42
+ * It is also the WATCH PATH. A tracked branch resolves to the last commit
43
+ * that touched this subtree, not to the branch tip, so a sibling app in the
44
+ * same repo cannot trigger a rebuild here. Platforms usually need a separate
45
+ * `watch_paths` field for this; making it the context means there is no
46
+ * second thing to keep in sync.
47
+ */
48
+ context: RelPath.default('.'),
49
+ /** Relative to `context`, matching how you would invoke `docker build -f`. */
50
+ dockerfile: RelPath.default('Dockerfile'),
51
+ buildArgs: z.record(z.string().min(1), z.string()).optional(),
52
+ /** Seconds. A build that hangs must fail the run, not stall it forever. */
53
+ buildTimeout: z.number().int().positive().max(7200).default(1800),
54
+ })
55
+ .strict()
56
+ .superRefine((s, ctx) => {
57
+ const n = [s.track !== undefined, s.pin !== undefined].filter(Boolean).length;
58
+ if (n !== 1) {
59
+ ctx.addIssue({
60
+ code: 'custom',
61
+ message: n === 0
62
+ ? 'needs exactly one of `track` (follow a branch) or `pin` (an exact commit)'
63
+ : 'track and pin are mutually exclusive — pick one',
64
+ });
65
+ }
66
+ });
67
+ const Digest = z.string().regex(/^sha256:[0-9a-f]{64}$/, 'must be a sha256 digest');
68
+ /**
69
+ * A prebuilt image, rather than a repo to build.
70
+ *
71
+ * `track` resolves the tag to a DIGEST on every run, and the digest is what
72
+ * gets rendered. A bare tag would be the `latest` + `pull: missing` trap all
73
+ * over again: the spec would never change, so the app would sit frozen on
74
+ * whatever the host first downloaded while looking like it tracked upstream.
75
+ */
76
+ export const ImageSourceSchema = z
77
+ .object({
78
+ /** `nginx`, `postgres:18`, `ghcr.io/owner/name`. */
79
+ image: z.string().min(1).regex(/^[a-z0-9._\-/:]+$/i, 'must be an image reference'),
80
+ track: z.object({ tag: z.string().min(1) }).strict().optional(),
81
+ pin: z.object({ digest: Digest }).strict().optional(),
82
+ })
83
+ .strict()
84
+ .superRefine((s, ctx) => {
85
+ const n = [s.track !== undefined, s.pin !== undefined].filter(Boolean).length;
86
+ if (n !== 1) {
87
+ ctx.addIssue({
88
+ code: 'custom',
89
+ message: n === 0
90
+ ? 'needs exactly one of `track` (follow a tag) or `pin` (an exact digest)'
91
+ : 'track and pin are mutually exclusive — pick one',
92
+ });
93
+ }
94
+ if (s.image.includes('@')) {
95
+ ctx.addIssue({
96
+ code: 'custom',
97
+ message: 'put the digest in `pin: { digest }`, not in the image reference',
98
+ });
99
+ }
100
+ });
101
+ /** Exactly one kind. `repo` builds; `image` runs something already built. */
102
+ export const ContainerSourceSchema = z.union([GitSourceSchema, ImageSourceSchema], {
103
+ error: 'source needs either `repo` (build it here) or `image` (already built)',
104
+ });
105
+ export const isImageSource = (s) => 'image' in s;
106
+ const PortSchema = z
107
+ .object({
108
+ host: z.number().int().positive().max(65535),
109
+ container: z.number().int().positive().max(65535),
110
+ protocol: z.enum(['tcp', 'udp']).default('tcp'),
111
+ /** Bind address. Defaults to all interfaces, exactly as compose does. */
112
+ bind: z.string().min(1).optional(),
113
+ })
114
+ .strict();
115
+ const NetworkSchema = z
116
+ .object({
117
+ name: z.string().min(1),
118
+ /**
119
+ * DNS names other containers can reach this one by.
120
+ *
121
+ * Typically load-bearing: a reverse proxy on the same network reaches
122
+ * an app as `http://<alias>:<port>`, so the alias IS the routing contract.
123
+ */
124
+ aliases: z.array(z.string().min(1)).optional(),
125
+ /**
126
+ * ALWAYS true in the rendered compose, and not a choice.
127
+ *
128
+ * Without it compose creates whatever it does not find, namespaced to the
129
+ * project — so a typo'd network name yields a brand-new EMPTY
130
+ * `<project>_<typo>`, the container starts healthy, and it can reach
131
+ * nothing. No error anywhere; you find out when the site 502s.
132
+ *
133
+ * `external: true` turns that into "network X declared as external, but
134
+ * could not be found" at deploy. The module creates declared networks
135
+ * itself (see the module-level `networks`), so by the time any container
136
+ * starts the real one exists and only a mistake is left to fail.
137
+ */
138
+ external: z.literal(true).default(true),
139
+ })
140
+ .strict();
141
+ /**
142
+ * A docker network as a managed resource.
143
+ *
144
+ * Deliberately thin. `driver` is the only knob most fleets need, and a field nothing sets is a field nobody maintains — the subnet,
145
+ * gateway and IPAM options are all reachable later if something asks for them.
146
+ */
147
+ export const DockerNetworkSchema = z
148
+ .object({
149
+ name: z.string().min(1),
150
+ /** `bridge` is the only driver a single-host fleet needs. */
151
+ driver: z.enum(['bridge', 'overlay', 'macvlan', 'host', 'none']).default('bridge'),
152
+ })
153
+ .strict();
154
+ const VolumeSchema = z
155
+ .object({
156
+ /** A named docker volume. Mutually exclusive with `hostPath`. */
157
+ name: z.string().min(1).optional(),
158
+ /** A bind mount from the host. Mutually exclusive with `name`. */
159
+ hostPath: z.string().startsWith('/', 'must be an absolute path').optional(),
160
+ mountPath: z.string().startsWith('/', 'must be an absolute path'),
161
+ readOnly: z.boolean().optional(),
162
+ })
163
+ .strict()
164
+ .superRefine((v, ctx) => {
165
+ const n = [v.name !== undefined, v.hostPath !== undefined].filter(Boolean).length;
166
+ if (n !== 1) {
167
+ ctx.addIssue({
168
+ code: 'custom',
169
+ message: n === 0
170
+ ? 'needs exactly one of `name` (a docker volume) or `hostPath` (a bind mount)'
171
+ : 'name and hostPath are mutually exclusive — pick one',
172
+ });
173
+ }
174
+ });
175
+ const HealthcheckSchema = z
176
+ .object({
177
+ /** Run through the container's shell, exactly like compose's CMD-SHELL. */
178
+ test: z.string().min(1),
179
+ interval: z.string().min(1).default('10s'),
180
+ timeout: z.string().min(1).default('5s'),
181
+ retries: z.number().int().positive().max(100).default(3),
182
+ startPeriod: z.string().min(1).default('10s'),
183
+ })
184
+ .strict();
185
+ export const ContainerSchema = z
186
+ .object({
187
+ name: Name,
188
+ source: ContainerSourceSchema,
189
+ /**
190
+ * Turn a build or deploy failure for THIS app into a warning: the run keeps
191
+ * going, the module still succeeds, and the app stays on whatever commit it
192
+ * is already running.
193
+ *
194
+ * Named for exactly the transformation it performs. `optional` or
195
+ * `allowFailure` would both invite the reading "failures here do not
196
+ * matter" — they do, they simply do not stop the fleet. The warning is
197
+ * carried in the run result and reported at the end; it is never swallowed,
198
+ * because a run that silently drops a failure is the same mistake as
199
+ * reading an absent answer as a satisfied one.
200
+ */
201
+ failureIsWarning: z.boolean().default(false),
202
+ /**
203
+ * Plain runtime environment. Values are literal: no shell expansion, and a
204
+ * `$` is escaped for Compose at render time, so it reaches the container.
205
+ */
206
+ env: z.record(z.string().min(1), z.string()).optional(),
207
+ /**
208
+ * Environment whose values are age ciphertext, decrypted on the primary.
209
+ *
210
+ * Separate from `env` because a `Secret` is a compile-time brand over a
211
+ * plain string: zod cannot tell them apart at runtime, so a single merged
212
+ * field would silently write ciphertext into a container.
213
+ */
214
+ secretEnv: z.record(z.string().min(1), SecretSchema).optional(),
215
+ ports: z.array(PortSchema).optional(),
216
+ networks: z.array(NetworkSchema).optional(),
217
+ /**
218
+ * `host` shares the host's network namespace outright — no port mapping, no
219
+ * network alias, no isolation. Needed by things that discover peers by
220
+ * broadcast (home-assistant) or serve DLNA (jellyfin).
221
+ *
222
+ * Rejected together with `ports` or `networks`, which silently do nothing
223
+ * in host mode rather than failing.
224
+ */
225
+ networkMode: z.literal('host').optional(),
226
+ /**
227
+ * Full access to the host's devices. This is a genuine privilege grant, not
228
+ * a tuning knob — a privileged container is effectively root on the host.
229
+ * Declared per app so it is visible in review rather than buried.
230
+ */
231
+ privileged: z.boolean().optional(),
232
+ /**
233
+ * Fix the container's name instead of letting compose generate
234
+ * `<project>-app-1`. Only needed when something outside Concord refers to
235
+ * the container by name.
236
+ */
237
+ containerName: z.string().min(1).optional(),
238
+ volumes: z.array(VolumeSchema).optional(),
239
+ healthcheck: HealthcheckSchema.optional(),
240
+ restart: z.enum(['no', 'always', 'unless-stopped', 'on-failure']).default('unless-stopped'),
241
+ /** Docker's own syntax, e.g. "512m". */
242
+ memory: z.string().min(1).optional(),
243
+ cpus: z.string().min(1).optional(),
244
+ user: z.string().min(1).optional(),
245
+ command: z.union([z.string().min(1), z.array(z.string())]).optional(),
246
+ /**
247
+ * Extra container labels, verbatim.
248
+ *
249
+ * The escape hatch for anything that reads labels off running containers.
250
+ * Concord's own `dev.concord.*` labels are reserved and rejected here — they
251
+ * are how `read()` knows what is running, so a config able to forge them
252
+ * could make a stale container look converged.
253
+ */
254
+ labels: z.record(z.string().min(1), z.string()).optional(),
255
+ })
256
+ .strict()
257
+ .superRefine((a, ctx) => {
258
+ if (a.networkMode === 'host') {
259
+ // Compose accepts both and silently ignores them, which would leave a
260
+ // config claiming an alias that nothing can ever resolve.
261
+ if (a.networks?.length) {
262
+ ctx.addIssue({
263
+ code: 'custom',
264
+ path: ['networks'],
265
+ message: 'networkMode "host" shares the host namespace — networks and aliases do nothing',
266
+ });
267
+ }
268
+ if (a.ports?.length) {
269
+ ctx.addIssue({
270
+ code: 'custom',
271
+ path: ['ports'],
272
+ message: 'networkMode "host" publishes nothing — the container already has the host ports',
273
+ });
274
+ }
275
+ }
276
+ for (const k of Object.keys(a.labels ?? {})) {
277
+ if (k.startsWith('dev.concord.')) {
278
+ ctx.addIssue({
279
+ code: 'custom',
280
+ path: ['labels', k],
281
+ message: `"dev.concord.*" labels are reserved — read() uses them to identify what is running`,
282
+ });
283
+ }
284
+ }
285
+ for (const k of Object.keys(a.secretEnv ?? {})) {
286
+ if (a.env && k in a.env) {
287
+ ctx.addIssue({
288
+ code: 'custom',
289
+ path: ['secretEnv', k],
290
+ message: `"${k}" is declared in both env and secretEnv — pick one`,
291
+ });
292
+ }
293
+ }
294
+ });
295
+ /** Where rendered compose projects live unless a module overrides `root`. The
296
+ * sweeper cleans orphaned project dirs under THIS path only — a custom-root
297
+ * module's orphans would be missed, exactly as under the v6 declared sweep. */
298
+ export const DEFAULT_ROOT = '/data/concord/apps';
299
+ // There is deliberately no `sweep` field (schema 8). Sweeping is a property
300
+ // of the module KIND: the loader synthesizes one DockerSweeper per registry
301
+ // host — see sweeper.ts. Config declares what SHOULD exist, never janitors.
302
+ // `protected` died with it: unused, and an escape hatch with zero
303
+ // consumers returns as data when a real one appears.
304
+ export const DockerConfigSchema = z
305
+ .object({
306
+ type: z.literal('docker'),
307
+ id: z.string().regex(/^[a-z0-9][a-z0-9-]*$/, 'must be kebab-case, starting alphanumeric'),
308
+ /**
309
+ * Which host this runs on — a key of the config's `hosts` registry.
310
+ *
311
+ * REQUIRED, with no default. A silently-defaulting host is a way to run
312
+ * something on the wrong machine, and "wherever Concord happens to be
313
+ * running" is not a property a config should depend on.
314
+ */
315
+ host: z.string().min(1),
316
+ /** Where rendered compose projects and build contexts live ON THE TARGET. */
317
+ root: z.string().startsWith('/').default(DEFAULT_ROOT),
318
+ /** Images to retain per app, newest first. Older ones are pruned after a deploy. */
319
+ keepImages: z.number().int().positive().max(50).default(3),
320
+ /**
321
+ * Networks this module CREATES, as declared resources.
322
+ *
323
+ * Separate from a container's `networks`, which say what it joins. This is
324
+ * the thing itself: enumerable with `docker network ls`, so it clears the
325
+ * `read()` entry requirement and shows up in a plan like anything else.
326
+ *
327
+ * ADDITIVE, like `apt` and `file`: an undeclared network is never touched.
328
+ * A network can hold nothing, but removing one silently detaches every
329
+ * container on it, so removal stays explicit.
330
+ */
331
+ networks: z.array(DockerNetworkSchema).optional(),
332
+ containers: z.array(ContainerSchema).optional(),
333
+ })
334
+ .strict();
335
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/modules/docker/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C;;;;;;;GAOG;AAEH,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,sBAAsB,EAAE,2CAA2C,CAAC,CAAA;AAElG,wDAAwD;AACxD,MAAM,IAAI,GAAG,CAAC;KACX,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,MAAM,CACL,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAo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E;IAC7E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAEtD,oFAAoF;IACpF,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAE1D;;;;;;;;;;OAUG;IACH,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE;IAEjD,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE;CAChD,CAAC;KACD,MAAM,EAAE,CAAA"}
@@ -0,0 +1,64 @@
1
+ import { Module } from '../../module.js';
2
+ import type { DockerOp } from './index.js';
3
+ import type { HostConfig } from '../../schema.js';
4
+ /**
5
+ * End-of-run host-truth enforcement for containers — the porkbun rule applied
6
+ * to hosts: the declared set is the WHOLE truth, because nothing runs a
7
+ * container outside Concord (schema 8).
8
+ *
9
+ * Unlike the systemd sweeper, which can only remove what carries the tag
10
+ * Concord wrote, this removes ANY live container no docker module on the host
11
+ * declares — labelled or not. That is deliberate and approved: an unowned
12
+ * container is drift whether Concord created it or a hand-run `docker run`
13
+ * did, and it is removed within a cycle. What it will NEVER remove: volumes.
14
+ * Containers are reproducible; the data under them is not.
15
+ *
16
+ * The exception is per HOST, not per container: a host declaring
17
+ * `containerSweep: 'labelled'` (a dev machine, where hand-run containers are
18
+ * the work) gets a sweeper that only removes containers carrying Concord's
19
+ * label. Concord still cleans up its own orphans there.
20
+ *
21
+ * Never declared in config. The loader synthesizes one per registry host and
22
+ * appends it after every declared module, so removals run last: a moved app
23
+ * is deployed on its new host before the old host's copy reads as unowned.
24
+ */
25
+ /**
26
+ * A live container no module on this host declares.
27
+ *
28
+ * `project` is the compose project it was deployed under (the
29
+ * `dev.concord.app` label) when Concord made it, null for a container
30
+ * something else started — the two are torn down differently.
31
+ */
32
+ export interface UnownedContainer {
33
+ name: string;
34
+ project: string | null;
35
+ image: string;
36
+ status: string;
37
+ }
38
+ export interface DockerSweepState {
39
+ unowned: UnownedContainer[];
40
+ }
41
+ /** The host's `containerSweep` setting — see HostSchema. */
42
+ export type ContainerSweep = HostConfig['containerSweep'];
43
+ /**
44
+ * Which live containers are unowned, given the keep-set.
45
+ *
46
+ * The label is the compose project Concord deployed under — but it comes off a
47
+ * LIVE container, so it is untrusted input. A value that is not a legal project
48
+ * name is treated as no project at all: the container is still removed, just
49
+ * directly rather than via compose (and never through a path built from it).
50
+ */
51
+ export declare function parseUnowned(stdout: string, keep: ReadonlySet<string>, mode?: ContainerSweep): UnownedContainer[];
52
+ export declare class DockerSweeper extends Module<DockerSweepState, DockerOp> {
53
+ private readonly keep;
54
+ private readonly mode;
55
+ readonly kind = "docker";
56
+ constructor(host: string, keep: ReadonlySet<string>, mode?: ContainerSweep);
57
+ desired(): Promise<DockerSweepState>;
58
+ /** EVERYTHING on the host, not just what any module declares — an unowned
59
+ * container can only be found by looking at what nothing asked about. */
60
+ read(): Promise<DockerSweepState>;
61
+ diff(actual: DockerSweepState, _desired: DockerSweepState): DockerOp[];
62
+ apply(ops: DockerOp[]): Promise<void>;
63
+ }
64
+ //# sourceMappingURL=sweeper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../../src/modules/docker/sweeper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAC5B;AAED,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;AAKzD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,IAAI,GAAE,cAAsB,GAC3B,gBAAgB,EAAE,CAcpB;AAED,qBAAa,aAAc,SAAQ,MAAM,CAAC,gBAAgB,EAAE,QAAQ,CAAC;IAKjE,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,SAAkB,IAAI,YAAW;gBAG/B,IAAI,EAAE,MAAM,EACK,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,IAAI,GAAE,cAAsB;IAKzC,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAI1C;8EAC0E;IACpE,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAUvC,IAAI,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,GAAG,QAAQ,EAAE;IAkBhE,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB5C"}
@@ -0,0 +1,94 @@
1
+ import { join } from 'node:path';
2
+ import { Module } from '../../module.js';
3
+ import { LABEL_APP } from './render.js';
4
+ import { DEFAULT_ROOT } from './schema.js';
5
+ /** Single-quote for a POSIX shell. Scripts are built here, run over stdin. */
6
+ const sq = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
7
+ /**
8
+ * Which live containers are unowned, given the keep-set.
9
+ *
10
+ * The label is the compose project Concord deployed under — but it comes off a
11
+ * LIVE container, so it is untrusted input. A value that is not a legal project
12
+ * name is treated as no project at all: the container is still removed, just
13
+ * directly rather than via compose (and never through a path built from it).
14
+ */
15
+ export function parseUnowned(stdout, keep, mode = 'all') {
16
+ const strays = [];
17
+ for (const line of stdout.split('\n')) {
18
+ if (!line.trim())
19
+ continue;
20
+ const [name, label, image, status] = line.split('\t');
21
+ if (!name)
22
+ continue;
23
+ // `labelled`: a container with no Concord label is not Concord's to judge.
24
+ // Keyed on the RAW label, so a forged-but-present value is still swept.
25
+ if (mode === 'labelled' && !label)
26
+ continue;
27
+ const project = label && /^[a-z0-9][a-z0-9-]*$/.test(label) ? label : null;
28
+ if (project !== null && keep.has(project))
29
+ continue;
30
+ strays.push({ name, project, image: image ?? '', status: status ?? '' });
31
+ }
32
+ return strays;
33
+ }
34
+ export class DockerSweeper extends Module {
35
+ keep;
36
+ mode;
37
+ kind = 'docker';
38
+ constructor(host, keep, mode = 'all') {
39
+ super('sweep', host);
40
+ this.keep = keep;
41
+ this.mode = mode;
42
+ }
43
+ async desired() {
44
+ return { unowned: [] };
45
+ }
46
+ /** EVERYTHING on the host, not just what any module declares — an unowned
47
+ * container can only be found by looking at what nothing asked about. */
48
+ async read() {
49
+ const out = this.exec.run('sudo', [
50
+ '-n', 'docker', 'ps', '-a', '--format',
51
+ // `.Label` is the ps-format accessor (inspect-format would be
52
+ // `index .Config.Labels`) — it renders "" when the label is absent.
53
+ `{{.Names}}\t{{.Label "${LABEL_APP}"}}\t{{.Image}}\t{{.Status}}`,
54
+ ]).stdout;
55
+ return { unowned: parseUnowned(out, this.keep, this.mode) };
56
+ }
57
+ diff(actual, _desired) {
58
+ // desired.unowned is always [] — anything actually here is a removal. The
59
+ // summary names what is being destroyed and why it was matched, because
60
+ // this op is the destructive one and the plan line is the record of the
61
+ // decision.
62
+ return actual.unowned.map((s) => ({
63
+ kind: 'delete',
64
+ entity: 'app',
65
+ id: `app/${s.name}`,
66
+ summary: `remove ${s.name} (${s.image}; ${s.status}; ` +
67
+ (s.project ? `project ${s.project}, not declared by any module on this host)` : 'no concord label)'),
68
+ name: s.name,
69
+ action: 'remove',
70
+ project: s.project,
71
+ }));
72
+ }
73
+ async apply(ops) {
74
+ for (const op of ops) {
75
+ if (op.project) {
76
+ // Concord deployed it, so it comes down the way it went up — compose
77
+ // also cleans the project's bookkeeping (and its default network, for
78
+ // a container that joined no declared one). NEVER `-v`: containers are
79
+ // reproducible, the data under them is not.
80
+ this.exec.sudo(['docker', 'compose', '-p', op.project, 'down']);
81
+ // The rendered project dir. The compose file in it carries resolved
82
+ // secretEnv values, so an orphaned copy is a secret at rest with no
83
+ // owner. `project` is validated against the name grammar in
84
+ // parseUnowned, so it cannot traverse out of the root.
85
+ this.exec.sudo(['rm', '-rf', '--', join(DEFAULT_ROOT, op.project)]);
86
+ }
87
+ // Whatever `down` did not cover — no compose bookkeeping, or no project
88
+ // at all. Already-gone is the desired state, not a failure.
89
+ this.exec.runScript(`docker rm -f -- ${sq(op.name)} >/dev/null 2>&1 || true`, { sudo: true });
90
+ this.log(` ✓ delete: ${op.summary}`);
91
+ }
92
+ }
93
+ }
94
+ //# sourceMappingURL=sweeper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sweeper.js","sourceRoot":"","sources":["../../../src/modules/docker/sweeper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA+C1C,8EAA8E;AAC9E,MAAM,EAAE,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAA;AAEzD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,IAAyB,EACzB,OAAuB,KAAK;IAE5B,MAAM,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AC,CAAA;gBAC/D,oEAAoE;gBACpE,oEAAoE;gBACpE,4DAA4D;gBAC5D,uDAAuD;gBACvD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;YACrE,CAAC;YACD,wEAAwE;YACxE,4DAA4D;YAC5D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;YAC7F,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,79 @@
1
+ import { Module, type BaseOp } from '../../module.js';
2
+ import type { DirectoryEntry, FileEntry, FileModuleConfig } from './schema.js';
3
+ export type { FileModuleConfig } from './schema.js';
4
+ export interface PathState {
5
+ path: string;
6
+ exists: boolean;
7
+ /** sha256 of content. Files only — never the content itself. */
8
+ hash?: string;
9
+ uid?: string;
10
+ gid?: string;
11
+ mode?: string;
12
+ isDir?: boolean;
13
+ }
14
+ export interface FileState {
15
+ directories: PathState[];
16
+ files: PathState[];
17
+ absent: PathState[];
18
+ }
19
+ export interface FileOp extends BaseOp {
20
+ entity: 'directory' | 'file';
21
+ path: string;
22
+ file?: FileEntry;
23
+ directory?: DirectoryEntry;
24
+ /** Resolved content — carried to apply(). NEVER logged. */
25
+ content?: string;
26
+ attrs?: {
27
+ owner?: string;
28
+ group?: string;
29
+ mode?: string;
30
+ };
31
+ }
32
+ /** Apply `${NAME}` substitutions with already-decrypted values. */
33
+ export declare function substitute(content: string, values: Record<string, string>): string;
34
+ export declare class FileModule extends Module<FileState, FileOp> {
35
+ private readonly config;
36
+ readonly kind = "file";
37
+ constructor(config: FileModuleConfig);
38
+ /**
39
+ * Names already resolved this run. Ids do not change under a running
40
+ * reconcile, and a module is rebuilt from the config each run, so there is
41
+ * nothing to invalidate.
42
+ */
43
+ private readonly idCache;
44
+ /**
45
+ * Resolve an owner/group to its NUMERIC id.
46
+ *
47
+ * `read()` reports `stat -c %u`, which is always numeric, so a declared
48
+ * *name* has to be resolved before the two can be compared at all. Without
49
+ * this, `owner: 'root'` never equals the `"0"` read back: the path is
50
+ * reported as drifted and re-chowned on every single reconcile, forever,
51
+ * while the run still reports `converged — no changes`. The chown succeeds
52
+ * every time, so there is no symptom to notice — which is precisely what
53
+ * makes it worth fixing rather than documenting.
54
+ *
55
+ * The reverse mapping is NOT an option: a uid may have no passwd entry at all
56
+ * (a container's volume is often owned by a uid like 9999), and several names can share
57
+ * one id. Numeric is the canonical form; names resolve toward it.
58
+ *
59
+ * Resolution runs on the TARGET host, because ids are per-host — `root` is 0
60
+ * by near-universal convention, but nothing else is.
61
+ */
62
+ private resolveId;
63
+ /**
64
+ * Resolve a `source` path against the config repo.
65
+ *
66
+ * Rejects traversal outside the repo — a config repo should never be able to
67
+ * make the reconciler read `/etc/shadow` and write it somewhere.
68
+ */
69
+ private resolveSource;
70
+ /** The exact bytes that should be on disk. Undefined for url-pinned files. */
71
+ private resolveContent;
72
+ desired(): Promise<FileState>;
73
+ read(): Promise<FileState>;
74
+ diff(actual: FileState, desired: FileState): FileOp[];
75
+ private attrDrift;
76
+ private applyAttrs;
77
+ apply(ops: FileOp[]): Promise<void>;
78
+ }
79
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/file/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9E,YAAY,EAAE,gBAAgB,EAAE,MAAM,aA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