@basaltkit/deploy 0.5.4 → 0.6.1
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/README.md +45 -8
- package/dist/compose.js +1 -1
- package/dist/config.d.ts +43 -19
- package/dist/config.js +25 -26
- package/dist/events.js +1 -1
- package/dist/host.d.ts +12 -0
- package/dist/host.js +20 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/infra.d.ts +11 -5
- package/dist/infra.js +82 -35
- package/dist/init.js +9 -9
- package/dist/pipeline.js +1 -1
- package/dist/s3.d.ts +39 -0
- package/dist/s3.js +148 -0
- package/dist/services.d.ts +3 -12
- package/dist/services.js +6 -54
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# @basaltkit/deploy
|
|
2
2
|
|
|
3
3
|
One deploy pipeline for a Basalt app on a single Linux server: the `.env`,
|
|
4
|
-
dedicated Docker infra (Postgres, Redis,
|
|
4
|
+
dedicated Docker infra (Postgres, Redis, SeaweedFS for S3), PM2, Apache, a database dump
|
|
5
5
|
before migrating, a health check, and a rollback when the new release does not
|
|
6
6
|
answer. Design and decisions: [RFC 0006](https://github.com/basaltkit/basalt/blob/main/docs/rfcs/0006-basalt-deploy.md)
|
|
7
|
-
|
|
7
|
+
[RFC 0007](https://github.com/basaltkit/basalt/blob/main/docs/rfcs/0007-deploy-zero-scripts.md)
|
|
8
|
+
and [RFC 0010](https://github.com/basaltkit/basalt/blob/main/docs/rfcs/0010-deploy-seaweedfs.md) (object storage).
|
|
8
9
|
|
|
9
10
|
```sh
|
|
10
11
|
pnpm add -D @basaltkit/deploy
|
|
@@ -54,7 +55,7 @@ export default defineDeploy({
|
|
|
54
55
|
},
|
|
55
56
|
infra: dockerInfra('acme', {
|
|
56
57
|
postgres: { urlParams: { schema: 'public' } },
|
|
57
|
-
|
|
58
|
+
seaweedfs: { buckets: ['acme-documents', 'acme-backups'] }, // S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY
|
|
58
59
|
}),
|
|
59
60
|
build: { prisma: ['prisma.config.ts', 'prisma/tenants/prisma.config.ts'], web: 'web' },
|
|
60
61
|
migrate: { central: true, tenants: true },
|
|
@@ -407,11 +408,11 @@ infra: dockerInfra('myapp', {
|
|
|
407
408
|
access: 'containers', // URLs name the containers (myapp-pg:5432); migrations get 127.0.0.1:<port>
|
|
408
409
|
postgres: { user: 'myapp_owner', urlKey: 'OWNER_DATABASE_URL', appRole: { name: 'myapp_app', urlKey: 'DATABASE_URL' } },
|
|
409
410
|
redis: { urlKey: 'REDIS_URL' },
|
|
410
|
-
|
|
411
|
+
seaweedfs: { buckets: [{ name: 'myapp-documents', versioned: true }] },
|
|
411
412
|
}),
|
|
412
413
|
runtime: compose({
|
|
413
414
|
// …
|
|
414
|
-
attach: { 'myapp-pg': ['data'], 'myapp-redis': ['data'], 'myapp-
|
|
415
|
+
attach: { 'myapp-pg': ['data'], 'myapp-redis': ['data'], 'myapp-seaweedfs': ['data'] },
|
|
415
416
|
passEnv: ['REDIS_URL'], // a service without env_file gets it through ${REDIS_URL}: from memory only
|
|
416
417
|
}),
|
|
417
418
|
```
|
|
@@ -431,7 +432,10 @@ infra: external({
|
|
|
431
432
|
appRole: { name: 'myapp_app', urlKey: 'DATABASE_URL' }, // what the app connects as: no DDL
|
|
432
433
|
},
|
|
433
434
|
redis: { container: 'myapp-redis' },
|
|
434
|
-
|
|
435
|
+
s3: { // any S3-compatible store; credentials from the .env
|
|
436
|
+
hostEndpoint: 'http://127.0.0.1:8333', // where the deploy reaches it, if the .env names a container
|
|
437
|
+
buckets: [{ name: 'myapp-documents', versioned: true }, { name: 'myapp-quarantine', expireDays: 1 }],
|
|
438
|
+
},
|
|
435
439
|
}),
|
|
436
440
|
runtime: compose({
|
|
437
441
|
// …
|
|
@@ -451,8 +455,9 @@ verify: {
|
|
|
451
455
|
changed, granted DML through the owner's default privileges — never on
|
|
452
456
|
existing tables, which an app may keep append-only. With `migrate.tenants`,
|
|
453
457
|
every `tenant_*` schema too, after the migration.
|
|
454
|
-
- **Buckets:**
|
|
455
|
-
|
|
458
|
+
- **Buckets:** over the S3 API itself (signed in the deploy, no vendor CLI):
|
|
459
|
+
created; versioning on; the expiry rule added once, next to any rule already
|
|
460
|
+
there. The store and its credentials are checked before the build.
|
|
456
461
|
- **Attach:** on a fresh server the project is created first (`up --no-start`)
|
|
457
462
|
so its networks exist and the first release is healthy, not the second.
|
|
458
463
|
- **Jobs:** `docker compose run --rm --no-deps` with this commit's images,
|
|
@@ -460,6 +465,38 @@ verify: {
|
|
|
460
465
|
- **The dump** runs inside `infra.postgres.container` as the owner.
|
|
461
466
|
- `dockerInfra` services take `container` (adopt another name) and `appRole` too.
|
|
462
467
|
|
|
468
|
+
**Object storage: SeaweedFS** (RFC 0010) — `dockerInfra(app, { seaweedfs })`
|
|
469
|
+
runs one `chrislusf/seaweedfs` container (master, volume, filer and S3 in one
|
|
470
|
+
process) and writes `S3_ENDPOINT`, `S3_ACCESS_KEY` and `S3_SECRET_KEY` (rename
|
|
471
|
+
them with `keys`):
|
|
472
|
+
|
|
473
|
+
- Only the S3 API is published, on 127.0.0.1. The master, the volume server and
|
|
474
|
+
the filer listen on the container's loopback only — they have no
|
|
475
|
+
authentication, and `runtime.attach` puts the container on the app's
|
|
476
|
+
networks. The Iceberg and Lance listeners are off.
|
|
477
|
+
- The admin gRPC (identities, policies) requires a signed token: the deploy
|
|
478
|
+
generates the signing key and keeps it. SeaweedFS 4.48 otherwise accepts an
|
|
479
|
+
identity from any neighbour on the network — verified, RFC 0010 §3.
|
|
480
|
+
- Healthy means a volume server has joined, not only that `/healthz` answers:
|
|
481
|
+
reads fail for a few seconds after `/healthz` turns green.
|
|
482
|
+
- The credentials are not stored in the data: a new pair on an old volume is a
|
|
483
|
+
rotation (the objects stay readable), not the lock-out it is for Postgres.
|
|
484
|
+
|
|
485
|
+
**Moving off MinIO.** MinIO's community edition is archived (no images, no
|
|
486
|
+
fixes), and `minio` is gone from this package: a config that still names it is
|
|
487
|
+
refused with this pointer. Per app:
|
|
488
|
+
|
|
489
|
+
1. Replace `minio: { … }` with `seaweedfs: { … }` (same `buckets` and `keys`),
|
|
490
|
+
or `external({ s3: { … } })` for a store you run yourself.
|
|
491
|
+
2. `basalt-deploy plan`, then `run`: the new store is created next to the old
|
|
492
|
+
one, on its own port, with the buckets.
|
|
493
|
+
3. Copy the objects, old store to new, with any S3 tool — e.g. `rclone sync`
|
|
494
|
+
from a container on the host network, both remotes set by environment
|
|
495
|
+
variables, so no key lands in a file or a command line. Versioned buckets:
|
|
496
|
+
only the current versions come across.
|
|
497
|
+
4. Check the app, then remove the old container and, once you are sure,
|
|
498
|
+
its volume.
|
|
499
|
+
|
|
463
500
|
**Hooks** — what only your app does, as commands that also run by hand:
|
|
464
501
|
|
|
465
502
|
```ts
|
package/dist/compose.js
CHANGED
|
@@ -113,7 +113,7 @@ async function nameFindings(ctx, sha) {
|
|
|
113
113
|
? [
|
|
114
114
|
infra.postgres && (infra.postgres.container ?? `${ctx.config.app}-pg`),
|
|
115
115
|
infra.redis && (infra.redis.container ?? `${ctx.config.app}-redis`),
|
|
116
|
-
infra.
|
|
116
|
+
infra.seaweedfs && (infra.seaweedfs.container ?? `${ctx.config.app}-seaweedfs`),
|
|
117
117
|
].filter((c) => Boolean(c))
|
|
118
118
|
: []);
|
|
119
119
|
for (const container of Object.keys(rt.attach ?? {})) {
|
package/dist/config.d.ts
CHANGED
|
@@ -189,10 +189,25 @@ export interface ExternalInfra<E extends object = EnvShape> {
|
|
|
189
189
|
redis?: {
|
|
190
190
|
container: string;
|
|
191
191
|
};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
/** Any S3-compatible store the app reaches with the `.env`'s credentials: its buckets kept. */
|
|
193
|
+
s3?: ExternalS3<E>;
|
|
194
|
+
}
|
|
195
|
+
/** The `.env` keys that hold an S3 store's endpoint and credentials. */
|
|
196
|
+
export interface S3Keys<E extends object = EnvShape> {
|
|
197
|
+
endpoint: EnvKey<E>;
|
|
198
|
+
accessKey: EnvKey<E>;
|
|
199
|
+
secretKey: EnvKey<E>;
|
|
200
|
+
}
|
|
201
|
+
export interface ExternalS3<E extends object = EnvShape> {
|
|
202
|
+
/** @default { endpoint: 'S3_ENDPOINT', accessKey: 'S3_ACCESS_KEY', secretKey: 'S3_SECRET_KEY' } */
|
|
203
|
+
keys?: S3Keys<E>;
|
|
204
|
+
/**
|
|
205
|
+
* Where THIS deploy reaches the store, when the `.env`'s endpoint is an
|
|
206
|
+
* address only the app's containers resolve (`http://storage:8333`).
|
|
207
|
+
* @example 'http://127.0.0.1:8333'
|
|
208
|
+
*/
|
|
209
|
+
hostEndpoint?: string;
|
|
210
|
+
buckets?: Bucket[];
|
|
196
211
|
}
|
|
197
212
|
export interface ExternalPostgres<E extends object = EnvShape> {
|
|
198
213
|
container: string;
|
|
@@ -228,7 +243,7 @@ export interface DockerInfra<E extends object = EnvShape> {
|
|
|
228
243
|
kind: 'docker';
|
|
229
244
|
postgres?: PostgresService<E>;
|
|
230
245
|
redis?: RedisService<E>;
|
|
231
|
-
|
|
246
|
+
seaweedfs?: SeaweedfsService<E>;
|
|
232
247
|
/**
|
|
233
248
|
* The compose project the containers belong to. Default: the app — what an
|
|
234
249
|
* older compose file of the app's infra already used. An app whose own
|
|
@@ -271,19 +286,21 @@ export interface RedisService<E extends object = EnvShape> {
|
|
|
271
286
|
/** Adopt a container under another name. Default `<app>-redis`. */
|
|
272
287
|
container?: string;
|
|
273
288
|
}
|
|
274
|
-
|
|
289
|
+
/**
|
|
290
|
+
* S3-compatible object storage in one SeaweedFS container (RFC 0010). Only
|
|
291
|
+
* the S3 API is published (127.0.0.1); the master, volume and filer listen
|
|
292
|
+
* inside the container only — they have no authentication of their own.
|
|
293
|
+
*/
|
|
294
|
+
export interface SeaweedfsService<E extends object = EnvShape> {
|
|
275
295
|
image: string;
|
|
296
|
+
/** Host port on 127.0.0.1 for the S3 API; `auto` keeps the running container's, else the `.env` endpoint's, else the first free from 8333. */
|
|
276
297
|
port: number | 'auto';
|
|
277
|
-
|
|
278
|
-
|
|
298
|
+
/** The access key a new store gets. @default the app */
|
|
299
|
+
accessKey: string;
|
|
279
300
|
buckets: Bucket[];
|
|
280
301
|
/** The `.env` keys that receive the endpoint and the credentials. */
|
|
281
|
-
keys:
|
|
282
|
-
|
|
283
|
-
accessKey: string;
|
|
284
|
-
secretKey: string;
|
|
285
|
-
};
|
|
286
|
-
/** Adopt a container under another name. Default `<app>-minio`. */
|
|
302
|
+
keys: S3Keys<E>;
|
|
303
|
+
/** Adopt a container under another name. Default `<app>-seaweedfs`. */
|
|
287
304
|
container?: string;
|
|
288
305
|
}
|
|
289
306
|
export interface BuildConfig {
|
|
@@ -553,17 +570,25 @@ export declare const none: () => NoProxy;
|
|
|
553
570
|
export declare const external: <E extends object = EnvShape>(services?: NoInfer<Omit<ExternalInfra<E>, 'kind'>>) => ExternalInfra<E>;
|
|
554
571
|
/** A bucket's name, whichever form it was given in. */
|
|
555
572
|
export declare const bucketName: (bucket: Bucket) => string;
|
|
556
|
-
|
|
573
|
+
/** Pinned: a SeaweedFS upgrade is a decision, not a side effect of a deploy. */
|
|
574
|
+
export declare const SEAWEEDFS_IMAGE = "chrislusf/seaweedfs:4.48";
|
|
575
|
+
/** What a config that still names MinIO is told (RFC 0010 §1). */
|
|
576
|
+
export declare const MINIO_REMOVED: string;
|
|
577
|
+
export declare const DEFAULT_S3_KEYS: {
|
|
578
|
+
readonly endpoint: 'S3_ENDPOINT';
|
|
579
|
+
readonly accessKey: 'S3_ACCESS_KEY';
|
|
580
|
+
readonly secretKey: 'S3_SECRET_KEY';
|
|
581
|
+
};
|
|
557
582
|
export interface DockerInfraOptions<E extends object = EnvShape> {
|
|
558
583
|
project?: string;
|
|
559
584
|
access?: 'host' | 'containers';
|
|
560
585
|
postgres?: Partial<PostgresService<E>> | false;
|
|
561
586
|
redis?: Partial<RedisService<E>> | false;
|
|
562
|
-
|
|
587
|
+
seaweedfs?: Partial<SeaweedfsService<E>> | false;
|
|
563
588
|
}
|
|
564
589
|
/**
|
|
565
590
|
* Dedicated containers on 127.0.0.1 for this app only. Names are fixed by the
|
|
566
|
-
* app label — `<app>-pg`, `<app>-redis`, `<app>-
|
|
591
|
+
* app label — `<app>-pg`, `<app>-redis`, `<app>-seaweedfs` — so a server that
|
|
567
592
|
* already runs them (created by hand or by an older script) is adopted, not
|
|
568
593
|
* duplicated.
|
|
569
594
|
*/
|
|
@@ -606,9 +631,8 @@ export interface ServerOverrides {
|
|
|
606
631
|
redis?: {
|
|
607
632
|
port?: number;
|
|
608
633
|
};
|
|
609
|
-
|
|
634
|
+
seaweedfs?: {
|
|
610
635
|
port?: number;
|
|
611
|
-
consolePort?: number;
|
|
612
636
|
};
|
|
613
637
|
};
|
|
614
638
|
}
|
package/dist/config.js
CHANGED
|
@@ -74,14 +74,21 @@ export const none = () => ({ kind: 'none' });
|
|
|
74
74
|
export const external = (services = {}) => ({ kind: 'external', ...services });
|
|
75
75
|
/** A bucket's name, whichever form it was given in. */
|
|
76
76
|
export const bucketName = (bucket) => (typeof bucket === 'string' ? bucket : bucket.name);
|
|
77
|
-
|
|
77
|
+
/** Pinned: a SeaweedFS upgrade is a decision, not a side effect of a deploy. */
|
|
78
|
+
export const SEAWEEDFS_IMAGE = 'chrislusf/seaweedfs:4.48';
|
|
79
|
+
/** What a config that still names MinIO is told (RFC 0010 §1). */
|
|
80
|
+
export const MINIO_REMOVED = 'minio was removed in @basaltkit/deploy 0.6: MinIO\'s community edition is archived (no images, no fixes). '
|
|
81
|
+
+ 'Use seaweedfs: { … } in dockerInfra(), or s3: { … } in external() for a store you run yourself — moving the data: the README, "Moving off MinIO"';
|
|
82
|
+
export const DEFAULT_S3_KEYS = { endpoint: 'S3_ENDPOINT', accessKey: 'S3_ACCESS_KEY', secretKey: 'S3_SECRET_KEY' };
|
|
78
83
|
/**
|
|
79
84
|
* Dedicated containers on 127.0.0.1 for this app only. Names are fixed by the
|
|
80
|
-
* app label — `<app>-pg`, `<app>-redis`, `<app>-
|
|
85
|
+
* app label — `<app>-pg`, `<app>-redis`, `<app>-seaweedfs` — so a server that
|
|
81
86
|
* already runs them (created by hand or by an older script) is adopted, not
|
|
82
87
|
* duplicated.
|
|
83
88
|
*/
|
|
84
89
|
export function dockerInfra(app, options = {}) {
|
|
90
|
+
if ('minio' in options)
|
|
91
|
+
throw new DeployConfigError([MINIO_REMOVED]);
|
|
85
92
|
const infra = { kind: 'docker', ...(options.project ? { project: options.project } : {}), ...(options.access ? { access: options.access } : {}) };
|
|
86
93
|
if (options.postgres !== false) {
|
|
87
94
|
infra.postgres = {
|
|
@@ -92,11 +99,11 @@ export function dockerInfra(app, options = {}) {
|
|
|
92
99
|
if (options.redis !== false) {
|
|
93
100
|
infra.redis = { image: 'redis:7-alpine', port: 'auto', urlKey: 'REDIS_URL', ...options.redis };
|
|
94
101
|
}
|
|
95
|
-
if (options.
|
|
96
|
-
infra.
|
|
97
|
-
image:
|
|
98
|
-
keys: {
|
|
99
|
-
...options.
|
|
102
|
+
if (options.seaweedfs !== false && options.seaweedfs !== undefined) {
|
|
103
|
+
infra.seaweedfs = {
|
|
104
|
+
image: SEAWEEDFS_IMAGE, port: 'auto', accessKey: app, buckets: [],
|
|
105
|
+
keys: { ...DEFAULT_S3_KEYS },
|
|
106
|
+
...options.seaweedfs,
|
|
100
107
|
};
|
|
101
108
|
}
|
|
102
109
|
return infra;
|
|
@@ -219,26 +226,23 @@ export function validateConfig(typed) {
|
|
|
219
226
|
if (keys.includes(key))
|
|
220
227
|
problems.push(`env key "${key}" is both forbidden and set`);
|
|
221
228
|
}
|
|
222
|
-
if (config.infra
|
|
223
|
-
|
|
224
|
-
for (const bucket of minio?.buckets ?? []) {
|
|
225
|
-
if (!/^[a-z0-9][a-z0-9.-]{2,62}$/.test(bucketName(bucket)))
|
|
226
|
-
problems.push(`bucket "${bucketName(bucket)}" is not a valid S3 bucket name`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
+
if (config.infra && 'minio' in config.infra)
|
|
230
|
+
problems.push(MINIO_REMOVED);
|
|
229
231
|
const services = config.infra?.kind === 'external' ? config.infra : undefined;
|
|
230
|
-
|
|
232
|
+
const buckets = [...(services?.s3?.buckets ?? []), ...(config.infra?.kind === 'docker' ? config.infra.seaweedfs?.buckets ?? [] : [])];
|
|
233
|
+
for (const bucket of buckets) {
|
|
231
234
|
if (!/^[a-z0-9][a-z0-9.-]{2,62}$/.test(bucketName(bucket)))
|
|
232
235
|
problems.push(`bucket "${bucketName(bucket)}" is not a valid S3 bucket name`);
|
|
233
|
-
}
|
|
234
|
-
for (const bucket of [...(services?.minio?.buckets ?? []), ...(config.infra?.kind === 'docker' ? config.infra.minio?.buckets ?? [] : [])]) {
|
|
235
236
|
if (typeof bucket === 'object' && bucket.expireDays !== undefined && (!Number.isInteger(bucket.expireDays) || bucket.expireDays < 1)) {
|
|
236
237
|
problems.push(`bucket "${bucket.name}": expireDays must be a whole number ≥ 1`);
|
|
237
238
|
}
|
|
238
239
|
}
|
|
240
|
+
const hostEndpoint = services?.s3?.hostEndpoint;
|
|
241
|
+
if (hostEndpoint !== undefined && !/^https?:\/\/[^/\s]+\/?$/.test(hostEndpoint))
|
|
242
|
+
problems.push(`s3.hostEndpoint "${hostEndpoint}" must be http(s)://host[:port]`);
|
|
239
243
|
const containers = [
|
|
240
|
-
services?.postgres?.container, services?.redis?.container,
|
|
241
|
-
...(config.infra?.kind === 'docker' ? [config.infra.postgres?.container, config.infra.redis?.container, config.infra.
|
|
244
|
+
services?.postgres?.container, services?.redis?.container,
|
|
245
|
+
...(config.infra?.kind === 'docker' ? [config.infra.postgres?.container, config.infra.redis?.container, config.infra.seaweedfs?.container] : []),
|
|
242
246
|
];
|
|
243
247
|
for (const container of containers) {
|
|
244
248
|
if (container !== undefined && !/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(container))
|
|
@@ -312,13 +316,8 @@ export function applyOverrides(config, overrides) {
|
|
|
312
316
|
infra.postgres = { ...infra.postgres, port: o.postgres.port };
|
|
313
317
|
if (infra.redis && o.redis?.port !== undefined)
|
|
314
318
|
infra.redis = { ...infra.redis, port: o.redis.port };
|
|
315
|
-
if (infra.
|
|
316
|
-
infra.
|
|
317
|
-
...infra.minio,
|
|
318
|
-
...(o.minio.port === undefined ? {} : { port: o.minio.port }),
|
|
319
|
-
...(o.minio.consolePort === undefined ? {} : { consolePort: o.minio.consolePort }),
|
|
320
|
-
};
|
|
321
|
-
}
|
|
319
|
+
if (infra.seaweedfs && o.seaweedfs?.port !== undefined)
|
|
320
|
+
infra.seaweedfs = { ...infra.seaweedfs, port: o.seaweedfs.port };
|
|
322
321
|
next.infra = infra;
|
|
323
322
|
}
|
|
324
323
|
return next;
|
package/dist/events.js
CHANGED
|
@@ -188,7 +188,7 @@ export class Redactor {
|
|
|
188
188
|
return { text: out, hit };
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
|
-
const INFRA_SECRETS = /^BASALT_(PG|REDIS|
|
|
191
|
+
const INFRA_SECRETS = /^BASALT_(PG|REDIS|S3)_/;
|
|
192
192
|
/** Whether the value of `key` is a secret for this config: generated, asked as a secret, or named like one. */
|
|
193
193
|
export function isSecretKey(key, config) {
|
|
194
194
|
if (SENSITIVE.test(key) || INFRA_SECRETS.test(key))
|
package/dist/host.d.ts
CHANGED
|
@@ -72,6 +72,18 @@ export interface Host {
|
|
|
72
72
|
} | {
|
|
73
73
|
error: string;
|
|
74
74
|
}>;
|
|
75
|
+
/** Any method, with headers and a body; the response body as text. Never throws. */
|
|
76
|
+
httpRequest(url: string, options: {
|
|
77
|
+
method: string;
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
body?: string;
|
|
80
|
+
timeoutMs?: number;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
status: number;
|
|
83
|
+
body: string;
|
|
84
|
+
} | {
|
|
85
|
+
error: string;
|
|
86
|
+
}>;
|
|
75
87
|
/** The environment the deploy itself was started with (answers for non-interactive runs). */
|
|
76
88
|
env: Readonly<Record<string, string | undefined>>;
|
|
77
89
|
/** Whether a person can answer a prompt (a terminal, not CI). */
|
package/dist/host.js
CHANGED
|
@@ -406,6 +406,26 @@ export function nodeHost(output = consoleOutput()) {
|
|
|
406
406
|
request.end();
|
|
407
407
|
});
|
|
408
408
|
},
|
|
409
|
+
httpRequest(url, options) {
|
|
410
|
+
return new Promise((resolve) => {
|
|
411
|
+
const target = new URL(url);
|
|
412
|
+
const client = target.protocol === 'https:' ? https : http;
|
|
413
|
+
const body = options.body ?? '';
|
|
414
|
+
const request = client.request(target, {
|
|
415
|
+
method: options.method,
|
|
416
|
+
headers: { ...options.headers, ...(body ? { 'content-length': String(Buffer.byteLength(body)) } : {}) },
|
|
417
|
+
timeout: options.timeoutMs ?? 15_000,
|
|
418
|
+
}, (response) => {
|
|
419
|
+
const chunks = [];
|
|
420
|
+
response.on('data', (chunk) => chunks.push(chunk));
|
|
421
|
+
response.on('end', () => resolve({ status: response.statusCode ?? 0, body: Buffer.concat(chunks).toString('utf8') }));
|
|
422
|
+
response.on('error', (error) => resolve({ error: error.message }));
|
|
423
|
+
});
|
|
424
|
+
request.on('timeout', () => request.destroy(new Error('timed out')));
|
|
425
|
+
request.on('error', (error) => resolve({ error: error.message }));
|
|
426
|
+
request.end(body);
|
|
427
|
+
});
|
|
428
|
+
},
|
|
409
429
|
};
|
|
410
430
|
}
|
|
411
431
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defineDeploy, secret, ask, pm2, compose, apache, caddy, none, external, bucketName, dockerInfra, validateConfig, applyOverrides, parseOverrides, processName, DeployConfigError,
|
|
1
|
+
export { defineDeploy, secret, ask, pm2, compose, apache, caddy, none, external, bucketName, dockerInfra, validateConfig, applyOverrides, parseOverrides, processName, DeployConfigError, SEAWEEDFS_IMAGE, type DeployConfig, type EnvShape, type EnvKey, type EnvValue, type EnvConfig, type DeriveContext, type SecretSpec, type Question, type InfraConfig, type DockerInfra, type DockerInfraOptions, type ExternalInfra, type ExternalPostgres, type AppRole, type Bucket, type VerifyConfig, type ComposeJob, type PostgresService, type RedisService, type SeaweedfsService, type ExternalS3, type S3Keys, type BuildConfig, type MigrateConfig, type BackupConfig, type RuntimeConfig, type Pm2Runtime, type ComposeRuntime, type ComposeImage, type HooksConfig, type ProxyConfig, type ApacheProxy, type CaddyProxy, type NoProxy, type HealthConfig, type ServerOverrides, } from './config.js';
|
|
2
2
|
export { main, loadConfig, createContext, processIO, USAGE, type CliIO } from './cli.js';
|
|
3
3
|
export { nodeHost, consoleOutput, type Host, type ExecOptions, type ExecResult, type FileStat, type Output, type TlsCertificate, type PromptMeta, type LogHandle, type FileRange } from './host.js';
|
|
4
4
|
export { DeployAbortedError, DeployError, INSTALL_COMMAND, RUN_COMMAND, rootInstallCommand, type DeployContext, type Finding } from './context.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defineDeploy, secret, ask, pm2, compose, apache, caddy, none, external, bucketName, dockerInfra, validateConfig, applyOverrides, parseOverrides, processName, DeployConfigError,
|
|
1
|
+
export { defineDeploy, secret, ask, pm2, compose, apache, caddy, none, external, bucketName, dockerInfra, validateConfig, applyOverrides, parseOverrides, processName, DeployConfigError, SEAWEEDFS_IMAGE, } from './config.js';
|
|
2
2
|
export { main, loadConfig, createContext, processIO, USAGE } from './cli.js';
|
|
3
3
|
export { nodeHost, consoleOutput } from './host.js';
|
|
4
4
|
export { DeployAbortedError, DeployError, INSTALL_COMMAND, RUN_COMMAND, rootInstallCommand } from './context.js';
|
package/dist/infra.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DockerInfra } from './config.js';
|
|
2
2
|
import { type DeployContext, type Finding } from './context.js';
|
|
3
3
|
import type { EnvChange } from './dotenv.js';
|
|
4
|
+
import { type S3Target } from './s3.js';
|
|
4
5
|
import { type PostgresHandle } from './services.js';
|
|
5
6
|
/**
|
|
6
7
|
* Dedicated containers, adopted or created (RFC 0006 §6.3).
|
|
@@ -8,20 +9,21 @@ import { type PostgresHandle } from './services.js';
|
|
|
8
9
|
* The running container is the truth: its credentials are read back and the
|
|
9
10
|
* `.env` follows them, never the other way round. A fresh password written over
|
|
10
11
|
* an initialised volume is exactly the `P1000` that cost a production deploy
|
|
11
|
-
* (incident 7) — Postgres
|
|
12
|
+
* (incident 7) — Postgres keeps the first credentials in the data. (SeaweedFS
|
|
13
|
+
* does not: its S3 credentials come from the container's environment, so a
|
|
14
|
+
* new pair on an old volume is a rotation, not a lock-out — RFC 0010 §2.)
|
|
12
15
|
*
|
|
13
16
|
* Passwords never reach a command line (visible in `ps`) or the generated
|
|
14
17
|
* compose file: compose reads them from its own environment, and `docker exec
|
|
15
18
|
* -e NAME` (no value) copies them from the CLI's environment.
|
|
16
19
|
*/
|
|
17
|
-
export type ServiceName = 'postgres' | 'redis' | '
|
|
20
|
+
export type ServiceName = 'postgres' | 'redis' | 'seaweedfs';
|
|
18
21
|
export interface ServicePlan {
|
|
19
22
|
service: ServiceName;
|
|
20
23
|
container: string;
|
|
21
24
|
volume: string;
|
|
22
25
|
action: 'adopt' | 'create';
|
|
23
26
|
port: number;
|
|
24
|
-
consolePort?: number;
|
|
25
27
|
user?: string;
|
|
26
28
|
database?: string;
|
|
27
29
|
/** Where the password came from — printed; the password itself never is. */
|
|
@@ -31,7 +33,7 @@ export interface InfraPlan {
|
|
|
31
33
|
services: ServicePlan[];
|
|
32
34
|
env: EnvChange[];
|
|
33
35
|
findings: Finding[];
|
|
34
|
-
/** Values compose interpolates (`${BASALT_PG_PASSWORD}`); passed in its environment only. */
|
|
36
|
+
/** Values compose interpolates (`${BASALT_PG_PASSWORD}`); passed in its environment only. Never printed. */
|
|
35
37
|
secrets: Record<string, string>;
|
|
36
38
|
/** The dedicated Postgres's owner URL, as the `.env` will hold it (the app role's is derived from it). */
|
|
37
39
|
ownerUrl?: string;
|
|
@@ -50,6 +52,10 @@ export declare function renderCompose(app: string, infra: DockerInfra, plan: Inf
|
|
|
50
52
|
export declare const composeFile: (ctx: DeployContext) => string;
|
|
51
53
|
/** Starts (or reconciles) the containers, waits for health, proves the credentials, creates the buckets. */
|
|
52
54
|
export declare function applyInfra(ctx: DeployContext, plan: InfraPlan): Promise<Finding[]>;
|
|
55
|
+
/** An external store, from the `.env` (and `hostEndpoint` when the `.env` names a container). */
|
|
56
|
+
export declare function externalS3Target(ctx: DeployContext, values: Map<string, string>): S3Target | {
|
|
57
|
+
error: string;
|
|
58
|
+
};
|
|
53
59
|
/** The dedicated Postgres as its owner, over TCP — the credentials the `.env` holds. */
|
|
54
60
|
export declare function dockerPostgres(plan: InfraPlan): PostgresHandle | undefined;
|
|
55
61
|
/**
|
package/dist/infra.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
import { DEFAULT_S3_KEYS } from './config.js';
|
|
2
3
|
import { DeployError } from './context.js';
|
|
3
4
|
import { freePort } from './ports.js';
|
|
4
|
-
import {
|
|
5
|
+
import { ensureBuckets, s3Findings } from './s3.js';
|
|
6
|
+
import { appRoleEnv, appRoleOf, ensureAppRole, externalFindings, externalOf, externalPostgres } from './services.js';
|
|
5
7
|
async function inspect(ctx, container) {
|
|
6
8
|
const result = await ctx.host.exec('docker', ['inspect', container, '--format', '{{json .Config.Env}}\t{{json .HostConfig.PortBindings}}']);
|
|
7
9
|
if (result.code !== 0)
|
|
@@ -58,6 +60,10 @@ export async function planInfra(ctx, values) {
|
|
|
58
60
|
const plan = { services: [], env: [], findings: [], secrets: {}, hostUrls: [] };
|
|
59
61
|
if (infra?.kind === 'external') {
|
|
60
62
|
plan.findings.push(...await externalFindings(ctx));
|
|
63
|
+
if (infra.s3) {
|
|
64
|
+
const target = externalS3Target(ctx, values);
|
|
65
|
+
plan.findings.push(...('error' in target ? [{ id: 'infra', level: 'error', message: target.error }] : await s3Findings(ctx, target)));
|
|
66
|
+
}
|
|
61
67
|
const pg = infra.postgres;
|
|
62
68
|
if (pg)
|
|
63
69
|
plan.env.push(...appRoleEnv(ctx, values, values.get(pg.urlKey ?? 'DATABASE_URL')));
|
|
@@ -139,42 +145,45 @@ export async function planInfra(ctx, values) {
|
|
|
139
145
|
plan.secrets['BASALT_REDIS_PASSWORD'] = password;
|
|
140
146
|
plan.services.push({ service: 'redis', container, volume, action: running ? 'adopt' : 'create', port, source });
|
|
141
147
|
}
|
|
142
|
-
if (infra.
|
|
143
|
-
const
|
|
144
|
-
const { container, volume } = names(app, project, '
|
|
148
|
+
if (infra.seaweedfs) {
|
|
149
|
+
const sw = infra.seaweedfs;
|
|
150
|
+
const { container, volume } = names(app, project, 'seaweedfs', sw.container);
|
|
145
151
|
const running = await inspect(ctx, container);
|
|
146
|
-
let
|
|
147
|
-
let
|
|
152
|
+
let accessKey = running?.env.get('AWS_ACCESS_KEY_ID');
|
|
153
|
+
let secretKey = running?.env.get('AWS_SECRET_ACCESS_KEY');
|
|
148
154
|
let source = 'container';
|
|
149
|
-
if ((
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
if ((!accessKey || !secretKey) && values.get(sw.keys.secretKey)) {
|
|
156
|
+
accessKey = values.get(sw.keys.accessKey) || sw.accessKey;
|
|
157
|
+
secretKey = values.get(sw.keys.secretKey);
|
|
152
158
|
source = 'env';
|
|
153
159
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
// Not kept in the data (unlike Postgres): an old volume opens with new
|
|
161
|
+
// credentials, and the objects stay readable — verified, RFC 0010 §2.
|
|
162
|
+
if (!accessKey || !secretKey) {
|
|
163
|
+
accessKey = sw.accessKey;
|
|
164
|
+
secretKey = ctx.host.randomHex(24);
|
|
159
165
|
source = 'generated';
|
|
160
166
|
}
|
|
161
167
|
let endpointPort;
|
|
162
168
|
try {
|
|
163
|
-
const endpoint = values.get(
|
|
169
|
+
const endpoint = values.get(sw.keys.endpoint);
|
|
164
170
|
endpointPort = endpoint && !inContainers ? Number(new URL(endpoint).port) || undefined : undefined;
|
|
165
171
|
}
|
|
166
172
|
catch {
|
|
167
173
|
endpointPort = undefined;
|
|
168
174
|
}
|
|
169
|
-
const port = await pick(
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
setEnv(
|
|
173
|
-
setEnv(
|
|
174
|
-
|
|
175
|
-
plan.secrets['
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
const port = await pick(sw.port, running?.ports.get('8333/tcp') ?? endpointPort, 8333);
|
|
176
|
+
const reason = source === 'container' ? `from the running ${container}` : source === 'generated' ? 'new storage' : 'port';
|
|
177
|
+
setEnv(sw.keys.endpoint, `http://${address(container, 8333, port)}`, reason);
|
|
178
|
+
setEnv(sw.keys.accessKey, accessKey, reason);
|
|
179
|
+
setEnv(sw.keys.secretKey, secretKey, reason);
|
|
180
|
+
plan.secrets['BASALT_S3_ACCESS_KEY'] = accessKey;
|
|
181
|
+
plan.secrets['BASALT_S3_SECRET_KEY'] = secretKey;
|
|
182
|
+
// Closes SeaweedFS's admin gRPC (identities, policies) to anything but a
|
|
183
|
+
// signed caller: 4.48 accepted them unauthenticated from any neighbour on
|
|
184
|
+
// the network — an `attach`ed sandbox could have made itself an admin.
|
|
185
|
+
plan.secrets['BASALT_S3_SIGNING_KEY'] = running?.env.get('WEED_JWT_FILER_SIGNING_KEY') || ctx.host.randomHex(32);
|
|
186
|
+
plan.services.push({ service: 'seaweedfs', container, volume, action: running ? 'adopt' : 'create', port, source });
|
|
178
187
|
}
|
|
179
188
|
return plan;
|
|
180
189
|
}
|
|
@@ -207,8 +216,21 @@ export function renderCompose(app, infra, plan) {
|
|
|
207
216
|
if (service.service === 'redis' && infra.redis) {
|
|
208
217
|
lines.push(' redis:', ` image: ${infra.redis.image}`, ` container_name: ${service.container}`, ' restart: unless-stopped', ` labels: { basalt.app: ${app} }`, " command: ['sh', '-c', 'exec redis-server --requirepass \"$$REDIS_PASSWORD\" --appendonly yes']", ` ports: ['127.0.0.1:${service.port}:6379']`, ' environment:', ' REDIS_PASSWORD: ${BASALT_REDIS_PASSWORD:?missing}', ` volumes: ['${key}:/data']`, ' healthcheck:', ` test: ['CMD-SHELL', 'REDISCLI_AUTH="$$REDIS_PASSWORD" redis-cli ping | grep -q PONG']`, ' interval: 10s', ' timeout: 5s', ' retries: 10');
|
|
209
218
|
}
|
|
210
|
-
if (service.service === '
|
|
211
|
-
lines.push('
|
|
219
|
+
if (service.service === 'seaweedfs' && infra.seaweedfs) {
|
|
220
|
+
lines.push(' seaweedfs:', ` image: ${infra.seaweedfs.image}`, ` container_name: ${service.container}`, ' restart: unless-stopped', ` labels: { basalt.app: ${app} }`,
|
|
221
|
+
// One process runs master, volume, filer and S3. Only the S3 API listens
|
|
222
|
+
// beyond the container's loopback: the others have no authentication,
|
|
223
|
+
// and `runtime.attach` puts this container on the app's networks.
|
|
224
|
+
// Iceberg and Lance are extra listeners nothing here uses.
|
|
225
|
+
// Volumes: each bucket gets its own, seven at a time, and by default
|
|
226
|
+
// SeaweedFS allows (free disk / 30 GB) of them — on a server with less
|
|
227
|
+
// than ~60 GB free the second bucket had none and every write was a
|
|
228
|
+
// 500 (`No writable volumes and no free volumes left`). 1 GB volumes
|
|
229
|
+
// and an explicit count; a volume takes no disk until it holds data.
|
|
230
|
+
" command: ['server', '-dir=/data', '-s3', '-s3.port=8333', '-ip=127.0.0.1', '-ip.bind=127.0.0.1', '-s3.ip.bind=0.0.0.0', '-s3.port.iceberg=0', '-s3.port.lance=0', '-master.volumeSizeLimitMB=1024', '-volume.max=1000']", ` ports: ['127.0.0.1:${service.port}:8333']`, ' environment:', ' AWS_ACCESS_KEY_ID: ${BASALT_S3_ACCESS_KEY:?missing}', ' AWS_SECRET_ACCESS_KEY: ${BASALT_S3_SECRET_KEY:?missing}', ' WEED_JWT_FILER_SIGNING_KEY: ${BASALT_S3_SIGNING_KEY:?missing}', ` volumes: ['${key}:/data']`, ' healthcheck:',
|
|
231
|
+
// `/healthz` answers before the volume server has joined: reads fail
|
|
232
|
+
// for a few seconds more. Healthy = a data node registered too.
|
|
233
|
+
` test: ['CMD-SHELL', 'wget -q -O /dev/null http://127.0.0.1:8333/healthz && wget -q -O- http://127.0.0.1:9333/dir/status | grep -q Url']`, ' interval: 10s', ' timeout: 5s', ' retries: 12', ' start_period: 30s');
|
|
212
234
|
}
|
|
213
235
|
}
|
|
214
236
|
lines.push('', 'volumes:', ...volumes.map((v) => ` ${v}:`));
|
|
@@ -249,9 +271,33 @@ export async function applyInfra(ctx, plan) {
|
|
|
249
271
|
if (!check.stdout.includes('PONG'))
|
|
250
272
|
findings.push({ id: 'C7', level: 'error', message: `redis refuses the password in ${ctx.config.env.file ?? '.env'}` });
|
|
251
273
|
}
|
|
274
|
+
if (service.service === 'seaweedfs') {
|
|
275
|
+
const target = seaweedfsTarget(plan);
|
|
276
|
+
if (target)
|
|
277
|
+
findings.push(...(await s3Findings(ctx, target)).map((f) => ({ ...f, id: 'C7' })));
|
|
278
|
+
}
|
|
252
279
|
}
|
|
253
280
|
return findings;
|
|
254
281
|
}
|
|
282
|
+
/** The dedicated store, from the host: its published port, the credentials the `.env` holds. */
|
|
283
|
+
function seaweedfsTarget(plan) {
|
|
284
|
+
const sw = plan.services.find((s) => s.service === 'seaweedfs');
|
|
285
|
+
if (!sw)
|
|
286
|
+
return undefined;
|
|
287
|
+
return { label: 'seaweedfs', endpoint: `http://127.0.0.1:${sw.port}`, accessKey: plan.secrets['BASALT_S3_ACCESS_KEY'] ?? '', secretKey: plan.secrets['BASALT_S3_SECRET_KEY'] ?? '' };
|
|
288
|
+
}
|
|
289
|
+
/** An external store, from the `.env` (and `hostEndpoint` when the `.env` names a container). */
|
|
290
|
+
export function externalS3Target(ctx, values) {
|
|
291
|
+
const s3 = externalOf(ctx.config)?.s3;
|
|
292
|
+
const keys = s3?.keys ?? DEFAULT_S3_KEYS;
|
|
293
|
+
const endpoint = s3?.hostEndpoint ?? values.get(keys.endpoint);
|
|
294
|
+
const accessKey = values.get(keys.accessKey);
|
|
295
|
+
const secretKey = values.get(keys.secretKey);
|
|
296
|
+
const missing = [[keys.endpoint, endpoint], [keys.accessKey, accessKey], [keys.secretKey, secretKey]].filter(([, v]) => !v).map(([k]) => k);
|
|
297
|
+
if (missing.length || !endpoint || !accessKey || !secretKey)
|
|
298
|
+
return { error: `s3: ${missing.join(', ')} missing in ${ctx.config.env.file ?? '.env'}` };
|
|
299
|
+
return { label: 's3', endpoint, accessKey, secretKey };
|
|
300
|
+
}
|
|
255
301
|
/** The dedicated Postgres as its owner, over TCP — the credentials the `.env` holds. */
|
|
256
302
|
export function dockerPostgres(plan) {
|
|
257
303
|
const pg = plan.services.find((s) => s.service === 'postgres');
|
|
@@ -274,20 +320,21 @@ export async function maintainServices(ctx, plan, values) {
|
|
|
274
320
|
lines.push(await ensureAppRole(ctx, pg, role, values));
|
|
275
321
|
}
|
|
276
322
|
const infra = ctx.config.infra;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
323
|
+
const dedicated = seaweedfsTarget(plan);
|
|
324
|
+
if (infra?.kind === 'docker' && dedicated && infra.seaweedfs?.buckets.length)
|
|
325
|
+
lines.push(await ensureBuckets(ctx, dedicated, infra.seaweedfs.buckets));
|
|
326
|
+
const external = externalOf(ctx.config)?.s3;
|
|
327
|
+
if (external?.buckets?.length) {
|
|
328
|
+
const target = externalS3Target(ctx, values);
|
|
329
|
+
if ('error' in target)
|
|
330
|
+
throw new DeployError(target.error);
|
|
331
|
+
lines.push(await ensureBuckets(ctx, target, external.buckets));
|
|
282
332
|
}
|
|
283
|
-
const external = externalOf(ctx.config)?.minio;
|
|
284
|
-
if (external?.buckets?.length)
|
|
285
|
-
lines.push(await ensureBuckets(ctx, await minioHandle(ctx, external.container), external.buckets));
|
|
286
333
|
return lines;
|
|
287
334
|
}
|
|
288
335
|
export function describeInfra(plan) {
|
|
289
336
|
return plan.services.map((s) => {
|
|
290
|
-
const ports =
|
|
337
|
+
const ports = `127.0.0.1:${s.port}`;
|
|
291
338
|
const credentials = s.source === 'container' ? 'credentials from the container' : s.source === 'env' ? 'credentials from .env' : 'new credentials';
|
|
292
339
|
return `${s.service}: ${s.action} ${s.container} on ${ports}, ${credentials}`;
|
|
293
340
|
});
|
package/dist/init.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { relative } from 'node:path';
|
|
2
|
-
import { APP_NAME } from './config.js';
|
|
2
|
+
import { APP_NAME, DEFAULT_S3_KEYS } from './config.js';
|
|
3
3
|
const COMPOSE_FILES = ['docker/compose.prod.yml', 'docker/compose.prod.yaml', 'compose.prod.yml', 'compose.prod.yaml', 'docker-compose.prod.yml'];
|
|
4
4
|
const PRISMA_CENTRAL = 'prisma.config.ts';
|
|
5
5
|
const PRISMA_TENANTS = 'prisma/tenants/prisma.config.ts';
|
|
@@ -290,15 +290,15 @@ function managedKeys(facts) {
|
|
|
290
290
|
if (!facts.compose) {
|
|
291
291
|
for (const key of ['PORT', 'HOST', 'DATABASE_URL', 'REDIS_URL'])
|
|
292
292
|
keys.add(key);
|
|
293
|
-
if (
|
|
294
|
-
for (const key of
|
|
293
|
+
if (hasS3(facts))
|
|
294
|
+
for (const key of S3_KEYS)
|
|
295
295
|
keys.add(key);
|
|
296
296
|
}
|
|
297
297
|
return keys;
|
|
298
298
|
}
|
|
299
|
-
/** What `dockerInfra`'s
|
|
300
|
-
const
|
|
301
|
-
const
|
|
299
|
+
/** What `dockerInfra`'s SeaweedFS writes (`seaweedfs.keys`); all three in the schema → a dedicated store. */
|
|
300
|
+
const S3_KEYS = Object.values(DEFAULT_S3_KEYS);
|
|
301
|
+
const hasS3 = (facts) => S3_KEYS.every((k) => facts.env?.keys.some((e) => e.name === k));
|
|
302
302
|
export function renderConfig(facts, answers) {
|
|
303
303
|
const helpers = new Set(['defineDeploy']);
|
|
304
304
|
const lines = [];
|
|
@@ -335,15 +335,15 @@ export function renderConfig(facts, answers) {
|
|
|
335
335
|
if (ask.length)
|
|
336
336
|
lines.push(...block('ask', ask));
|
|
337
337
|
lines.push(' },');
|
|
338
|
-
if (!facts.compose && (has('DATABASE_URL') || has('REDIS_URL') ||
|
|
338
|
+
if (!facts.compose && (has('DATABASE_URL') || has('REDIS_URL') || hasS3(facts) || !typed)) {
|
|
339
339
|
helpers.add('dockerInfra');
|
|
340
340
|
const options = [];
|
|
341
341
|
if (typed && !has('DATABASE_URL'))
|
|
342
342
|
options.push('postgres: false');
|
|
343
343
|
if (typed && !has('REDIS_URL'))
|
|
344
344
|
options.push('redis: false');
|
|
345
|
-
if (
|
|
346
|
-
options.push('
|
|
345
|
+
if (hasS3(facts))
|
|
346
|
+
options.push('seaweedfs: {}');
|
|
347
347
|
lines.push(` infra: dockerInfra(${quote(facts.app)}${options.length ? `, { ${options.join(', ')} }` : ''}),`);
|
|
348
348
|
}
|
|
349
349
|
const build = [];
|
package/dist/pipeline.js
CHANGED
|
@@ -485,7 +485,7 @@ async function writeEnvSecure(ctx, plan) {
|
|
|
485
485
|
async function infraStep(ctx, infra, values) {
|
|
486
486
|
stopOnErrors(ctx, await applyInfra(ctx, infra), 'infra');
|
|
487
487
|
const external = externalOf(ctx.config);
|
|
488
|
-
const adopted = [external?.postgres?.container, external?.redis?.container
|
|
488
|
+
const adopted = [external?.postgres?.container, external?.redis?.container].filter(Boolean);
|
|
489
489
|
if (infra.services.length > 0)
|
|
490
490
|
ctx.host.out.ok(`${infra.services.map((s) => s.container).join(', ')} healthy; credentials accepted`);
|
|
491
491
|
else if (adopted.length > 0)
|
package/dist/s3.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Bucket } from './config.js';
|
|
2
|
+
import { type DeployContext, type Finding } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* The buckets, over the S3 API itself (RFC 0010 §3). No vendor CLI inside a
|
|
5
|
+
* container (MinIO's `mc` was the only way before): the same requests work on
|
|
6
|
+
* SeaweedFS, Garage, R2 or AWS — whatever the `.env` points at.
|
|
7
|
+
*
|
|
8
|
+
* Requests are signed (SigV4, path style) in this process; the secret never
|
|
9
|
+
* reaches a command line, a file or the screen.
|
|
10
|
+
*/
|
|
11
|
+
export interface S3Target {
|
|
12
|
+
/** What the messages call it: `seaweedfs`, `s3`. */
|
|
13
|
+
label: string;
|
|
14
|
+
/** Reachable from the host running the deploy, e.g. `http://127.0.0.1:8333`. */
|
|
15
|
+
endpoint: string;
|
|
16
|
+
accessKey: string;
|
|
17
|
+
secretKey: string;
|
|
18
|
+
/** @default 'us-east-1' — what SeaweedFS answers to, and AWS's default. */
|
|
19
|
+
region?: string;
|
|
20
|
+
}
|
|
21
|
+
/** The SigV4 `Authorization` header and the headers it signs. Exported for the tests. */
|
|
22
|
+
export declare function signedHeaders(target: S3Target, request: {
|
|
23
|
+
method: string;
|
|
24
|
+
url: URL;
|
|
25
|
+
body: string;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
}, now: Date): Record<string, string>;
|
|
28
|
+
/** Reachable, and the credentials accepted — before anything is built. */
|
|
29
|
+
export declare function s3Findings(ctx: DeployContext, target: S3Target): Promise<Finding[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a lifecycle document already expires EVERYTHING after `days`: an
|
|
32
|
+
* enabled rule with that expiry and no prefix or tag narrowing it. A 1-day
|
|
33
|
+
* rule on `tmp/` does not count.
|
|
34
|
+
*/
|
|
35
|
+
export declare function hasExpiry(xml: string, days: number): boolean;
|
|
36
|
+
/** The document with one more rule — the ones already there kept (a PUT replaces them all). */
|
|
37
|
+
export declare function withExpiryRule(existing: string, days: number): string;
|
|
38
|
+
/** Each bucket exists; versioning on where asked; the expiry rule added once. Says what it did. */
|
|
39
|
+
export declare function ensureBuckets(ctx: DeployContext, target: S3Target, buckets: Bucket[]): Promise<string>;
|
package/dist/s3.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createHash, createHmac } from 'node:crypto';
|
|
2
|
+
import { bucketName } from './config.js';
|
|
3
|
+
import { DeployError } from './context.js';
|
|
4
|
+
const hex = (data) => createHash('sha256').update(data).digest('hex');
|
|
5
|
+
const hmac = (key, data) => createHmac('sha256', key).update(data).digest();
|
|
6
|
+
/** `20261016T113642Z` and `20261016`. */
|
|
7
|
+
function stamps(now) {
|
|
8
|
+
const amz = now.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
|
9
|
+
return { amz, day: amz.slice(0, 8) };
|
|
10
|
+
}
|
|
11
|
+
/** The SigV4 `Authorization` header and the headers it signs. Exported for the tests. */
|
|
12
|
+
export function signedHeaders(target, request, now) {
|
|
13
|
+
const region = target.region ?? 'us-east-1';
|
|
14
|
+
const { amz, day } = stamps(now);
|
|
15
|
+
const payload = hex(request.body);
|
|
16
|
+
const headers = {
|
|
17
|
+
host: request.url.host,
|
|
18
|
+
'x-amz-content-sha256': payload,
|
|
19
|
+
'x-amz-date': amz,
|
|
20
|
+
...Object.fromEntries(Object.entries(request.headers ?? {}).map(([k, v]) => [k.toLowerCase(), v])),
|
|
21
|
+
};
|
|
22
|
+
const names = Object.keys(headers).sort();
|
|
23
|
+
// A subresource (`?versioning`) is `versioning=` in the canonical query.
|
|
24
|
+
const query = [...request.url.searchParams.entries()]
|
|
25
|
+
.map(([k, v]) => [encodeURIComponent(k), encodeURIComponent(v)])
|
|
26
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
27
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
28
|
+
.join('&');
|
|
29
|
+
const canonical = [request.method, request.url.pathname || '/', query, ...names.map((n) => `${n}:${headers[n]?.trim()}`), '', names.join(';'), payload].join('\n');
|
|
30
|
+
const scope = `${day}/${region}/s3/aws4_request`;
|
|
31
|
+
const toSign = ['AWS4-HMAC-SHA256', amz, scope, hex(canonical)].join('\n');
|
|
32
|
+
const key = hmac(hmac(hmac(hmac(`AWS4${target.secretKey}`, day), region), 's3'), 'aws4_request');
|
|
33
|
+
const signature = createHmac('sha256', key).update(toSign).digest('hex');
|
|
34
|
+
return { ...headers, authorization: `AWS4-HMAC-SHA256 Credential=${target.accessKey}/${scope}, SignedHeaders=${names.join(';')}, Signature=${signature}` };
|
|
35
|
+
}
|
|
36
|
+
async function send(ctx, target, method, bucket, subresource = '', body = '', headers = {}) {
|
|
37
|
+
let base = target.endpoint;
|
|
38
|
+
while (base.endsWith('/'))
|
|
39
|
+
base = base.slice(0, -1);
|
|
40
|
+
const url = new URL(`${base}/${bucket}`);
|
|
41
|
+
if (subresource)
|
|
42
|
+
url.search = `?${subresource}=`;
|
|
43
|
+
const result = await ctx.host.httpRequest(url.toString(), { method, headers: signedHeaders(target, { method, url, body, headers }, ctx.host.now()), body });
|
|
44
|
+
if ('error' in result)
|
|
45
|
+
throw new DeployError(`${target.label}: cannot reach ${url.origin} (${result.error})`);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/** The `<Code>` of an S3 error body, for the message. */
|
|
49
|
+
const code = (body) => body.split('<Code>')[1]?.split('</Code>')[0] ?? '';
|
|
50
|
+
function refused(target, what, response) {
|
|
51
|
+
if (response.status === 403)
|
|
52
|
+
return new DeployError(`${target.label}: the credentials were refused ${what} (${code(response.body) || 'HTTP 403'})`);
|
|
53
|
+
return new DeployError(`${target.label}: ${what}: HTTP ${response.status}${code(response.body) ? ` ${code(response.body)}` : ''}`);
|
|
54
|
+
}
|
|
55
|
+
/** Reachable, and the credentials accepted — before anything is built. */
|
|
56
|
+
export async function s3Findings(ctx, target) {
|
|
57
|
+
try {
|
|
58
|
+
const listed = await send(ctx, target, 'GET', '');
|
|
59
|
+
if (listed.status === 200)
|
|
60
|
+
return [];
|
|
61
|
+
return [{ id: 'infra', level: 'error', message: refused(target, `by ${target.endpoint}`, listed).message, fix: 'the access and secret keys in the .env must be the store\'s' }];
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return [{ id: 'infra', level: 'error', message: error.message, fix: 'is the store running, and is the endpoint reachable from this host? (hostEndpoint, when the .env names a container)' }];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const XMLNS = 'xmlns="http://s3.amazonaws.com/doc/2006-03-01/"';
|
|
68
|
+
/**
|
|
69
|
+
* Whether a lifecycle document already expires EVERYTHING after `days`: an
|
|
70
|
+
* enabled rule with that expiry and no prefix or tag narrowing it. A 1-day
|
|
71
|
+
* rule on `tmp/` does not count.
|
|
72
|
+
*/
|
|
73
|
+
export function hasExpiry(xml, days) {
|
|
74
|
+
const compact = xml.replace(/\s+/g, '');
|
|
75
|
+
return compact.split('<Rule>').slice(1).some((after) => {
|
|
76
|
+
const rule = after.split('</Rule>')[0] ?? '';
|
|
77
|
+
if (!rule.includes('<Status>Enabled</Status>') || !rule.includes(`<Expiration><Days>${days}</Days>`))
|
|
78
|
+
return false;
|
|
79
|
+
if (rule.includes('<Tag>') || rule.includes('<And>'))
|
|
80
|
+
return false;
|
|
81
|
+
return rule.split('<Prefix>').slice(1).every((p) => p.startsWith('</Prefix>'));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** The document with one more rule — the ones already there kept (a PUT replaces them all). */
|
|
85
|
+
export function withExpiryRule(existing, days) {
|
|
86
|
+
const rule = `<Rule><ID>basalt-expire-${days}d</ID><Status>Enabled</Status><Filter><Prefix></Prefix></Filter><Expiration><Days>${days}</Days></Expiration></Rule>`;
|
|
87
|
+
const end = existing.lastIndexOf('</LifecycleConfiguration>');
|
|
88
|
+
if (end === -1)
|
|
89
|
+
return `<?xml version="1.0" encoding="UTF-8"?><LifecycleConfiguration ${XMLNS}>${rule}</LifecycleConfiguration>`;
|
|
90
|
+
return `${existing.slice(0, end)}${rule}${existing.slice(end)}`;
|
|
91
|
+
}
|
|
92
|
+
/** Each bucket exists; versioning on where asked; the expiry rule added once. Says what it did. */
|
|
93
|
+
export async function ensureBuckets(ctx, target, buckets) {
|
|
94
|
+
if (buckets.length === 0)
|
|
95
|
+
return '';
|
|
96
|
+
const said = [];
|
|
97
|
+
for (const bucket of buckets) {
|
|
98
|
+
const name = bucketName(bucket);
|
|
99
|
+
const head = await send(ctx, target, 'HEAD', name);
|
|
100
|
+
if (head.status === 404) {
|
|
101
|
+
const made = await send(ctx, target, 'PUT', name);
|
|
102
|
+
// Owned by these credentials already: a race with another deploy, not an error.
|
|
103
|
+
if (made.status !== 200 && code(made.body) !== 'BucketAlreadyOwnedByYou')
|
|
104
|
+
throw refused(target, `creating ${name}`, made);
|
|
105
|
+
}
|
|
106
|
+
else if (head.status !== 200) {
|
|
107
|
+
throw refused(target, `checking ${name}`, head);
|
|
108
|
+
}
|
|
109
|
+
if (typeof bucket === 'string') {
|
|
110
|
+
said.push(name);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const notes = [];
|
|
114
|
+
if (bucket.versioned) {
|
|
115
|
+
const state = await send(ctx, target, 'GET', name, 'versioning');
|
|
116
|
+
if (state.status !== 200)
|
|
117
|
+
throw refused(target, `reading the versioning of ${name}`, state);
|
|
118
|
+
if (!state.body.replace(/\s+/g, '').includes('<Status>Enabled</Status>')) {
|
|
119
|
+
const body = `<VersioningConfiguration ${XMLNS}><Status>Enabled</Status></VersioningConfiguration>`;
|
|
120
|
+
const set = await send(ctx, target, 'PUT', name, 'versioning', body, { 'content-type': 'application/xml' });
|
|
121
|
+
if (set.status !== 200)
|
|
122
|
+
throw refused(target, `turning versioning on for ${name}`, set);
|
|
123
|
+
}
|
|
124
|
+
notes.push('versioned');
|
|
125
|
+
}
|
|
126
|
+
if (bucket.expireDays !== undefined) {
|
|
127
|
+
const current = await send(ctx, target, 'GET', name, 'lifecycle');
|
|
128
|
+
// 404 NoSuchLifecycleConfiguration: no rule yet.
|
|
129
|
+
if (current.status !== 200 && current.status !== 404)
|
|
130
|
+
throw refused(target, `reading the lifecycle of ${name}`, current);
|
|
131
|
+
const present = current.status === 200 && hasExpiry(current.body, bucket.expireDays);
|
|
132
|
+
if (!present) {
|
|
133
|
+
const body = withExpiryRule(current.status === 200 ? current.body : '', bucket.expireDays);
|
|
134
|
+
// S3 requires the body's MD5 on a lifecycle PUT.
|
|
135
|
+
const md5 = createHash('md5').update(body).digest('base64');
|
|
136
|
+
const set = await send(ctx, target, 'PUT', name, 'lifecycle', body, { 'content-type': 'application/xml', 'content-md5': md5 });
|
|
137
|
+
if (set.status !== 200)
|
|
138
|
+
throw refused(target, `adding the expiry rule to ${name}`, set);
|
|
139
|
+
const check = await send(ctx, target, 'GET', name, 'lifecycle');
|
|
140
|
+
if (check.status !== 200 || !hasExpiry(check.body, bucket.expireDays))
|
|
141
|
+
throw new DeployError(`${target.label}: ${name} accepted the expiry rule but does not report it — the store may not support lifecycle rules`);
|
|
142
|
+
}
|
|
143
|
+
notes.push(`${bucket.expireDays}-day expiry${present ? '' : ' (added)'}`);
|
|
144
|
+
}
|
|
145
|
+
said.push(notes.length ? `${name} (${notes.join(', ')})` : name);
|
|
146
|
+
}
|
|
147
|
+
return `buckets: ${said.join(', ')}`;
|
|
148
|
+
}
|
package/dist/services.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type AppRole, type
|
|
1
|
+
import { type AppRole, type DeployConfig } from './config.js';
|
|
2
2
|
import { type DeployContext, type Finding } from './context.js';
|
|
3
3
|
import type { EnvChange } from './dotenv.js';
|
|
4
4
|
/**
|
|
5
5
|
* What every deploy keeps true of the app's services, dedicated or not
|
|
6
6
|
* (RFC 0007 §4): the external containers are running, the app's database role
|
|
7
|
-
* exists with the `.env`'s password and its grants
|
|
8
|
-
*
|
|
7
|
+
* exists with the `.env`'s password and its grants. Each is idempotent and
|
|
8
|
+
* says what it did. (The buckets: `s3.ts`.)
|
|
9
9
|
*
|
|
10
10
|
* Credentials never reach a command line: `docker exec -e NAME` (no value)
|
|
11
11
|
* copies them from this process's environment, SQL with a password goes on
|
|
@@ -22,11 +22,6 @@ export interface PostgresHandle {
|
|
|
22
22
|
/** The owner's URL, from which the app role's URL is derived. */
|
|
23
23
|
url: string | undefined;
|
|
24
24
|
}
|
|
25
|
-
export interface MinioHandle {
|
|
26
|
-
container: string;
|
|
27
|
-
user: string;
|
|
28
|
-
password: string;
|
|
29
|
-
}
|
|
30
25
|
export declare const externalOf: (config: DeployConfig) => import("./config.js").ExternalInfra<import("./config.js").EnvShape> | undefined;
|
|
31
26
|
/** The container the pre-migration dump runs in, with external infra: `backup.container`, else `infra.postgres.container`. */
|
|
32
27
|
export declare const dumpContainer: (config: DeployConfig) => string | undefined;
|
|
@@ -56,9 +51,5 @@ export declare function ensureAppRole(ctx: DeployContext, pg: PostgresHandle, ro
|
|
|
56
51
|
* company without them is an outage the role only finds at runtime.
|
|
57
52
|
*/
|
|
58
53
|
export declare function grantTenantSchemas(ctx: DeployContext, pg: PostgresHandle, role: AppRole): Promise<string>;
|
|
59
|
-
/** Credentials of a running MinIO: its own, never the config's. */
|
|
60
|
-
export declare function minioHandle(ctx: DeployContext, container: string): Promise<MinioHandle>;
|
|
61
|
-
/** Each bucket exists; versioning on where asked; the expiry rule added once. */
|
|
62
|
-
export declare function ensureBuckets(ctx: DeployContext, minio: MinioHandle, buckets: Bucket[]): Promise<string>;
|
|
63
54
|
/** What `plan` says about the services: the external containers, the role, the buckets. */
|
|
64
55
|
export declare function describeServices(config: DeployConfig): string[];
|
package/dist/services.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_S3_KEYS } from './config.js';
|
|
2
2
|
import { DeployError } from './context.js';
|
|
3
3
|
export const externalOf = (config) => (config.infra?.kind === 'external' ? config.infra : undefined);
|
|
4
4
|
/** The container the pre-migration dump runs in, with external infra: `backup.container`, else `infra.postgres.container`. */
|
|
@@ -17,7 +17,7 @@ export async function externalFindings(ctx) {
|
|
|
17
17
|
if (!services)
|
|
18
18
|
return [];
|
|
19
19
|
const findings = [];
|
|
20
|
-
for (const [service, container] of [['postgres', services.postgres?.container], ['redis', services.redis?.container]
|
|
20
|
+
for (const [service, container] of [['postgres', services.postgres?.container], ['redis', services.redis?.container]]) {
|
|
21
21
|
if (!container)
|
|
22
22
|
continue;
|
|
23
23
|
const state = await ctx.host.exec('docker', ['inspect', '--format', '{{.State.Running}}', container]);
|
|
@@ -140,68 +140,20 @@ SELECT count(*) FROM pg_namespace WHERE nspname LIKE 'tenant\\_%';
|
|
|
140
140
|
throw new DeployError(`appRole ${role.name} on the company schemas: ${result.stderr.trim().split('\n').pop() ?? 'psql failed'}`);
|
|
141
141
|
return `role ${role.name}: granted on ${result.stdout.trim().split('\n').pop() ?? '0'} company schema(s)`;
|
|
142
142
|
}
|
|
143
|
-
/** Credentials of a running MinIO: its own, never the config's. */
|
|
144
|
-
export async function minioHandle(ctx, container) {
|
|
145
|
-
const result = await ctx.host.exec('docker', ['inspect', container, '--format', '{{json .Config.Env}}']);
|
|
146
|
-
if (result.code !== 0)
|
|
147
|
-
throw new DeployError(`minio: cannot inspect ${container}`);
|
|
148
|
-
const env = new Map(JSON.parse(result.stdout.trim() || '[]').map((e) => [e.slice(0, e.indexOf('=')), e.slice(e.indexOf('=') + 1)]));
|
|
149
|
-
const user = env.get('MINIO_ROOT_USER');
|
|
150
|
-
const password = env.get('MINIO_ROOT_PASSWORD');
|
|
151
|
-
if (!user || !password)
|
|
152
|
-
throw new DeployError(`minio: ${container} has no MINIO_ROOT_USER/MINIO_ROOT_PASSWORD`);
|
|
153
|
-
return { container, user, password };
|
|
154
|
-
}
|
|
155
|
-
/** Each bucket exists; versioning on where asked; the expiry rule added once. */
|
|
156
|
-
export async function ensureBuckets(ctx, minio, buckets) {
|
|
157
|
-
if (buckets.length === 0)
|
|
158
|
-
return '';
|
|
159
|
-
const alias = `http://${encodeURIComponent(minio.user)}:${encodeURIComponent(minio.password)}@127.0.0.1:9000`;
|
|
160
|
-
const mc = (args) => ctx.host.exec('docker', ['exec', '-e', 'MC_HOST_local', minio.container, 'mc', ...args], { env: { MC_HOST_local: alias } });
|
|
161
|
-
const fail = (what, result) => new DeployError(`minio: ${what}: ${result.stderr.trim().split('\n')[0] ?? 'mc failed'}`);
|
|
162
|
-
const made = await mc(['mb', '-p', ...buckets.map((b) => `local/${bucketName(b)}`)]);
|
|
163
|
-
if (made.code !== 0)
|
|
164
|
-
throw fail('creating the buckets', made);
|
|
165
|
-
const said = [];
|
|
166
|
-
for (const bucket of buckets) {
|
|
167
|
-
if (typeof bucket === 'string') {
|
|
168
|
-
said.push(bucket);
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
const notes = [];
|
|
172
|
-
if (bucket.versioned) {
|
|
173
|
-
const versioned = await mc(['version', 'enable', `local/${bucket.name}`]);
|
|
174
|
-
if (versioned.code !== 0)
|
|
175
|
-
throw fail(`versioning ${bucket.name}`, versioned);
|
|
176
|
-
notes.push('versioned');
|
|
177
|
-
}
|
|
178
|
-
if (bucket.expireDays !== undefined) {
|
|
179
|
-
// `mc ilm rule add` adds ANOTHER rule every time: read the rules first.
|
|
180
|
-
const rules = await mc(['ilm', 'rule', 'ls', '--json', `local/${bucket.name}`]);
|
|
181
|
-
const present = new RegExp(`"Expiration":\\s*\\{[^}]*"Days":\\s*${bucket.expireDays}\\b`).test(rules.stdout);
|
|
182
|
-
if (!present) {
|
|
183
|
-
const added = await mc(['ilm', 'rule', 'add', '--expire-days', String(bucket.expireDays), `local/${bucket.name}`]);
|
|
184
|
-
if (added.code !== 0)
|
|
185
|
-
throw fail(`expiry on ${bucket.name}`, added);
|
|
186
|
-
}
|
|
187
|
-
notes.push(`${bucket.expireDays}-day expiry${present ? '' : ' (added)'}`);
|
|
188
|
-
}
|
|
189
|
-
said.push(notes.length ? `${bucket.name} (${notes.join(', ')})` : bucket.name);
|
|
190
|
-
}
|
|
191
|
-
return `buckets: ${said.join(', ')}`;
|
|
192
|
-
}
|
|
193
143
|
/** What `plan` says about the services: the external containers, the role, the buckets. */
|
|
194
144
|
export function describeServices(config) {
|
|
195
145
|
const lines = [];
|
|
196
146
|
const external = externalOf(config);
|
|
197
|
-
for (const [service, container] of [['postgres', external?.postgres?.container], ['redis', external?.redis?.container]
|
|
147
|
+
for (const [service, container] of [['postgres', external?.postgres?.container], ['redis', external?.redis?.container]]) {
|
|
198
148
|
if (container)
|
|
199
149
|
lines.push(`${service}: ${container} (external, kept running by its owner)`);
|
|
200
150
|
}
|
|
151
|
+
if (external?.s3)
|
|
152
|
+
lines.push(`s3: ${external.s3.hostEndpoint ?? (external.s3.keys ?? DEFAULT_S3_KEYS).endpoint} (external; credentials from the .env, checked before the build)`);
|
|
201
153
|
const role = appRoleOf(config);
|
|
202
154
|
if (role)
|
|
203
155
|
lines.push(`role ${role.name}: created if missing, password from ${role.urlKey}, DML grants${config.migrate?.tenants ? ' (company schemas too, after the migration)' : ''}`);
|
|
204
|
-
const buckets = [...(external?.
|
|
156
|
+
const buckets = [...(external?.s3?.buckets ?? []), ...(config.infra?.kind === 'docker' ? config.infra.seaweedfs?.buckets ?? [] : [])];
|
|
205
157
|
const policies = buckets.filter((b) => typeof b === 'object' && (b.versioned || b.expireDays));
|
|
206
158
|
if (policies.length)
|
|
207
159
|
lines.push(`buckets: ${policies.map((b) => typeof b === 'object' ? `${b.name} (${[b.versioned ? 'versioned' : '', b.expireDays ? `${b.expireDays}-day expiry` : ''].filter(Boolean).join(', ')})` : b).join(', ')}`);
|