@foliwake/cli 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -0
- package/README.md +196 -14
- package/config/docker/compose.varnish.yaml +44 -0
- package/config/docker/compose.yaml +165 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.js +58 -21
- package/dist/commands/docker/backup.d.ts +12 -0
- package/dist/commands/docker/backup.js +29 -0
- package/dist/commands/docker/configure.d.ts +23 -0
- package/dist/commands/docker/configure.js +73 -0
- package/dist/commands/docker/exec.d.ts +8 -0
- package/dist/commands/docker/exec.js +26 -0
- package/dist/commands/docker/install.d.ts +33 -0
- package/dist/commands/docker/install.js +126 -0
- package/dist/commands/docker/link.d.ts +12 -0
- package/dist/commands/docker/link.js +24 -0
- package/dist/commands/docker/list.d.ts +7 -0
- package/dist/commands/docker/list.js +16 -0
- package/dist/commands/docker/logs.d.ts +15 -0
- package/dist/commands/docker/logs.js +33 -0
- package/dist/commands/docker/remove.d.ts +13 -0
- package/dist/commands/docker/remove.js +35 -0
- package/dist/commands/docker/restart.d.ts +9 -0
- package/dist/commands/docker/restart.js +18 -0
- package/dist/commands/docker/restore.d.ts +14 -0
- package/dist/commands/docker/restore.js +34 -0
- package/dist/commands/docker/start.d.ts +9 -0
- package/dist/commands/docker/start.js +18 -0
- package/dist/commands/docker/status.d.ts +10 -0
- package/dist/commands/docker/status.js +22 -0
- package/dist/commands/docker/stop.d.ts +9 -0
- package/dist/commands/docker/stop.js +18 -0
- package/dist/commands/docker/update.d.ts +14 -0
- package/dist/commands/docker/update.js +42 -0
- package/dist/commands/project/publish.d.ts +1 -0
- package/dist/commands/project/publish.js +9 -2
- package/dist/core-command.d.ts +4 -1
- package/dist/core-command.js +6 -2
- package/dist/core-types.d.ts +1 -0
- package/dist/dev/container.d.ts +45 -0
- package/dist/dev/container.js +128 -0
- package/dist/dev/remote-html.js +2 -2
- package/dist/docker/asker.d.ts +4 -0
- package/dist/docker/asker.js +34 -0
- package/dist/docker/backup.d.ts +21 -0
- package/dist/docker/backup.js +114 -0
- package/dist/docker/cache-plan.d.ts +17 -0
- package/dist/docker/cache-plan.js +58 -0
- package/dist/docker/compose-file.d.ts +18 -0
- package/dist/docker/compose-file.js +58 -0
- package/dist/docker/context.d.ts +55 -0
- package/dist/docker/context.js +12 -0
- package/dist/docker/engine.d.ts +8 -0
- package/dist/docker/engine.js +51 -0
- package/dist/docker/env-block.d.ts +19 -0
- package/dist/docker/env-block.js +117 -0
- package/dist/docker/env-keys.d.ts +4 -0
- package/dist/docker/env-keys.js +33 -0
- package/dist/docker/env-verify.d.ts +17 -0
- package/dist/docker/env-verify.js +62 -0
- package/dist/docker/install-plan.d.ts +81 -0
- package/dist/docker/install-plan.js +332 -0
- package/dist/docker/install.d.ts +22 -0
- package/dist/docker/install.js +118 -0
- package/dist/docker/instance.d.ts +105 -0
- package/dist/docker/instance.js +184 -0
- package/dist/docker/lifecycle.d.ts +19 -0
- package/dist/docker/lifecycle.js +70 -0
- package/dist/docker/ports.d.ts +14 -0
- package/dist/docker/ports.js +50 -0
- package/dist/docker/process-context.d.ts +8 -0
- package/dist/docker/process-context.js +26 -0
- package/dist/docker/remove.d.ts +7 -0
- package/dist/docker/remove.js +82 -0
- package/dist/docker/report.d.ts +32 -0
- package/dist/docker/report.js +109 -0
- package/dist/docker/runner.d.ts +28 -0
- package/dist/docker/runner.js +55 -0
- package/dist/docker/settings-files.d.ts +40 -0
- package/dist/docker/settings-files.js +125 -0
- package/dist/docker/trace-url.d.ts +5 -0
- package/dist/docker/trace-url.js +36 -0
- package/dist/docker/update.d.ts +29 -0
- package/dist/docker/update.js +317 -0
- package/dist/docker-command.d.ts +17 -0
- package/dist/docker-command.js +37 -0
- package/dist/project-preview.d.ts +8 -0
- package/dist/project-preview.js +27 -5
- package/dist/project-publish.d.ts +8 -7
- package/dist/project-publish.js +124 -57
- package/dist/publish-code.d.ts +75 -0
- package/dist/publish-code.js +223 -0
- package/dist/remote/servers.d.ts +1 -1
- package/dist/remote/servers.js +1 -1
- package/dist/render/site-status.js +2 -2
- package/package.json +14 -9
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// After every write of an instance's files, Compose itself says what it reads: `docker compose …
|
|
2
|
+
// config --format json`, kept in memory only (it holds the secrets; it is never printed or logged).
|
|
3
|
+
// Every key of the block must come out as the CLI wrote it in the server's environment (the .env is
|
|
4
|
+
// its env_file, so each of its variables is there). Anything else (an operator's line that
|
|
5
|
+
// overrides one, a quote left open that swallows the block) puts the previous files back byte for
|
|
6
|
+
// byte and refuses, naming the keys, never their values.
|
|
7
|
+
import { DockerFailure, DockerUsageError } from './context.js';
|
|
8
|
+
import { ENV_KEYS } from './env-keys.js';
|
|
9
|
+
import { composeArgs, composeEnv, instanceDir, previousFiles, undoWrite, writeInstanceFiles, } from './settings-files.js';
|
|
10
|
+
/** The keys whose effective value differs from what the CLI wrote (empty: all as written). */
|
|
11
|
+
export async function differingKeys(ctx, name, values) {
|
|
12
|
+
const result = await ctx.docker.run(composeArgs(ctx.env, name, ['config', '--format', 'json']), {
|
|
13
|
+
env: composeEnv(ctx.env),
|
|
14
|
+
});
|
|
15
|
+
if (result.code !== 0) {
|
|
16
|
+
// Compose's message can quote a line of the file: it is not repeated here.
|
|
17
|
+
throw new DockerUsageError(`Compose cannot read the settings of ${name}. Nothing was changed. To see why: docker compose -p ` +
|
|
18
|
+
`${name} --project-directory ${instanceDir(ctx.env, name)} config --quiet`);
|
|
19
|
+
}
|
|
20
|
+
let environment;
|
|
21
|
+
try {
|
|
22
|
+
const config = JSON.parse(result.stdout);
|
|
23
|
+
environment = config.services?.foliwake?.environment ?? {};
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new DockerFailure(`docker compose config of ${name} did not answer in JSON.`);
|
|
27
|
+
}
|
|
28
|
+
const differing = [];
|
|
29
|
+
for (const key of ENV_KEYS) {
|
|
30
|
+
const raw = environment[key];
|
|
31
|
+
// Compose prints a `$` of a value as `$$` (so its output can be read again).
|
|
32
|
+
const effective = typeof raw === 'string' ? raw.replaceAll('$$', '$') : '';
|
|
33
|
+
if (effective !== (values[key] ?? ''))
|
|
34
|
+
differing.push(key);
|
|
35
|
+
}
|
|
36
|
+
return differing;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Writes the files, checks them with Compose, and on any difference puts back what was there and
|
|
40
|
+
* refuses. Returns the folder and how to undo this write (for a step that fails later, e.g. a pull).
|
|
41
|
+
*/
|
|
42
|
+
export async function writeVerified(ctx, name, files) {
|
|
43
|
+
const previous = await previousFiles(ctx.env, name);
|
|
44
|
+
const dir = await writeInstanceFiles(ctx.env, name, files);
|
|
45
|
+
let differing;
|
|
46
|
+
try {
|
|
47
|
+
differing = await differingKeys(ctx, name, files.env.values);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
await undoWrite(ctx.env, name, previous);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
if (differing.length) {
|
|
54
|
+
await undoWrite(ctx.env, name, previous);
|
|
55
|
+
const them = differing.length > 1 ? 'them' : 'it';
|
|
56
|
+
throw new DockerUsageError(`In ${dir}/.env, Compose does not read ${differing.join(', ')} as foliwake docker wrote ${them}: ` +
|
|
57
|
+
`a line outside its block sets ${them} too, or a quote left open runs into the block. Nothing was changed. ` +
|
|
58
|
+
'Compose takes the last definition in the file; remove the other definition (or close the quote) ' +
|
|
59
|
+
'and run the command again.');
|
|
60
|
+
}
|
|
61
|
+
return { dir, previous };
|
|
62
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type CachePlan } from './cache-plan.js';
|
|
2
|
+
import { type DockerContext } from './context.js';
|
|
3
|
+
import { type TracesMode } from './instance.js';
|
|
4
|
+
import type { EnvValues } from './env-keys.js';
|
|
5
|
+
export interface InstallRequest {
|
|
6
|
+
name?: string;
|
|
7
|
+
port?: string;
|
|
8
|
+
bind?: string;
|
|
9
|
+
publicOrigin?: string;
|
|
10
|
+
domain?: string;
|
|
11
|
+
ownerEmail?: string;
|
|
12
|
+
storage?: string;
|
|
13
|
+
storageEndpoint?: string;
|
|
14
|
+
storageRegion?: string;
|
|
15
|
+
storageBucket?: string;
|
|
16
|
+
storageCreateBuckets?: boolean;
|
|
17
|
+
traces?: string;
|
|
18
|
+
jaegerStore?: string;
|
|
19
|
+
jaegerPort?: string;
|
|
20
|
+
otlpEndpoint?: string;
|
|
21
|
+
traceUrlTemplate?: string;
|
|
22
|
+
image?: string;
|
|
23
|
+
/** `none` (default) or `varnish` (cache-plan.ts). */
|
|
24
|
+
cache?: string;
|
|
25
|
+
cachePort?: string;
|
|
26
|
+
}
|
|
27
|
+
export type StoragePlan = {
|
|
28
|
+
kind: 'volume';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 's3';
|
|
31
|
+
endpoint: string;
|
|
32
|
+
region: string;
|
|
33
|
+
bucket: string;
|
|
34
|
+
createBuckets: boolean;
|
|
35
|
+
accessKeyId: string;
|
|
36
|
+
secretKey: string;
|
|
37
|
+
};
|
|
38
|
+
export interface InstallPlan {
|
|
39
|
+
name: string;
|
|
40
|
+
image: string;
|
|
41
|
+
bind: string;
|
|
42
|
+
port: number;
|
|
43
|
+
publicOrigin: string;
|
|
44
|
+
domain: string | null;
|
|
45
|
+
ownerEmail: string | null;
|
|
46
|
+
/** The instance's data volume exists already (kept by `remove`): its sites and accounts are used. */
|
|
47
|
+
reuseData: boolean;
|
|
48
|
+
storage: StoragePlan;
|
|
49
|
+
traces: TracesMode;
|
|
50
|
+
jaeger: {
|
|
51
|
+
store: 'memory' | 'badger';
|
|
52
|
+
port: number;
|
|
53
|
+
} | null;
|
|
54
|
+
otlp: {
|
|
55
|
+
endpoint: string;
|
|
56
|
+
headers: string | null;
|
|
57
|
+
} | null;
|
|
58
|
+
/** With --traces external: the collector's trace page (FOLIWAKE_TRACE_URL_TEMPLATE), if given. */
|
|
59
|
+
traceUrl?: string | null;
|
|
60
|
+
/** A Varnish of the instance (cache-plan.ts); absent: none. */
|
|
61
|
+
cache?: CachePlan;
|
|
62
|
+
}
|
|
63
|
+
/** Why `value` is not an http(s) origin without a path, or null. */
|
|
64
|
+
export declare function originProblem(value: string): string | null;
|
|
65
|
+
/** All answers of an install, or a refusal; asks in a terminal only for what the flags left open. */
|
|
66
|
+
export declare function planInstall(ctx: DockerContext, request: InstallRequest): Promise<InstallPlan>;
|
|
67
|
+
/**
|
|
68
|
+
* FOLIWAKE_TRUST_PROXY: '1' (believe X-Forwarded-For) for a public address that is not this computer,
|
|
69
|
+
* so an HTTPS proxy is in front, and only on a loopback port, which nothing but a proxy on this
|
|
70
|
+
* computer reaches. On a port open to other networks a client could name any address there and
|
|
71
|
+
* dodge the per-client sign-in limits, so it stays ''. install and configure both use it.
|
|
72
|
+
*/
|
|
73
|
+
export declare function trustProxyFor(publicOrigin: string, bind: string): string;
|
|
74
|
+
/** trustProxyFor, saying so when a public address keeps the trust off because its port is open. */
|
|
75
|
+
export declare function proxyTrustOf(ctx: DockerContext, publicOrigin: string, bind: string): string;
|
|
76
|
+
/** The trace page of an operation in the instance's own Jaeger UI (FOLIWAKE_TRACE_URL_TEMPLATE). */
|
|
77
|
+
export declare const jaegerTraceUrl: (port: number) => string;
|
|
78
|
+
/** The .env values of a plan. */
|
|
79
|
+
export declare function planEnv(plan: InstallPlan): EnvValues;
|
|
80
|
+
/** One line of what will be installed (no secret). */
|
|
81
|
+
export declare function planSummary(plan: InstallPlan): string;
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// The answers of `foliwake docker install`: each from its flag, else asked in a terminal, else its
|
|
2
|
+
// default, or a refusal where there is none (exit 2, nothing written). Secrets (the S3 key, OTLP
|
|
3
|
+
// headers) are asked hidden, or without a terminal taken from this command's environment; never
|
|
4
|
+
// from a flag. Nothing here changes Docker or the disk.
|
|
5
|
+
import { applyCache, chooseCache } from './cache-plan.js';
|
|
6
|
+
import net from 'node:net';
|
|
7
|
+
import { traceUrlTemplateProblem } from './trace-url.js';
|
|
8
|
+
import { askerOf } from './asker.js';
|
|
9
|
+
import { DockerUsageError } from './context.js';
|
|
10
|
+
import { DEFAULT_IMAGE } from './compose-file.js';
|
|
11
|
+
import { DEFAULT_INSTANCE, TRACES_MODES, dataVolume, discoverInstances, foreignUse, instanceNameProblem, } from './instance.js';
|
|
12
|
+
import { DEFAULT_JAEGER_PORT, DEFAULT_PORT, firstFreePort, parsePort, portProblem, portsInUse } from './ports.js';
|
|
13
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
|
|
14
|
+
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
15
|
+
/** Why `value` is not an http(s) origin without a path, or null. */
|
|
16
|
+
export function originProblem(value) {
|
|
17
|
+
let url = null;
|
|
18
|
+
try {
|
|
19
|
+
url = new URL(value);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
url = null;
|
|
23
|
+
}
|
|
24
|
+
const bare = url !== null && !url.username && !url.password && url.pathname === '/' && !url.search && !url.hash;
|
|
25
|
+
if (url !== null && ['http:', 'https:'].includes(url.protocol) && bare && !value.endsWith('/'))
|
|
26
|
+
return null;
|
|
27
|
+
return `"${value}" is not an http(s) origin such as https://foliwake.example.com (no path, no trailing slash).`;
|
|
28
|
+
}
|
|
29
|
+
const HTTP_ADDRESS = /^https?:\/\/\S+$/;
|
|
30
|
+
const httpAddressProblem = (value) => HTTP_ADDRESS.test(value) ? undefined : 'An http(s) address';
|
|
31
|
+
const refuse = (message) => {
|
|
32
|
+
throw new DockerUsageError(message);
|
|
33
|
+
};
|
|
34
|
+
/** A flag value, else a question in a terminal, else the default (null: refused with `missing`). */
|
|
35
|
+
async function pick(ctx, given, ask, fallback, missing) {
|
|
36
|
+
if (given !== undefined)
|
|
37
|
+
return given;
|
|
38
|
+
if (ctx.interactive)
|
|
39
|
+
return ask(askerOf(ctx));
|
|
40
|
+
if (fallback !== null)
|
|
41
|
+
return fallback;
|
|
42
|
+
return refuse(missing ?? 'A value is missing.');
|
|
43
|
+
}
|
|
44
|
+
async function chooseName(ctx, request, instances) {
|
|
45
|
+
const running = instances.filter((instance) => instance.containers.length);
|
|
46
|
+
const taken = new Set(running.map((instance) => instance.name));
|
|
47
|
+
const validate = (value) => {
|
|
48
|
+
const problem = instanceNameProblem(value);
|
|
49
|
+
if (problem)
|
|
50
|
+
return problem;
|
|
51
|
+
return taken.has(value) ? `Instance ${value} exists already.` : undefined;
|
|
52
|
+
};
|
|
53
|
+
const askName = (asker) => asker.text('Instance name', { initial: DEFAULT_INSTANCE, validate });
|
|
54
|
+
const name = await pick(ctx, request.name, askName, DEFAULT_INSTANCE);
|
|
55
|
+
const problem = instanceNameProblem(name);
|
|
56
|
+
if (problem)
|
|
57
|
+
refuse(problem);
|
|
58
|
+
if (taken.has(name)) {
|
|
59
|
+
refuse(`Instance ${name} exists already on this Docker engine. Change it with \`foliwake docker configure ` +
|
|
60
|
+
`${name}\` or \`update ${name}\`, or remove it first.`);
|
|
61
|
+
}
|
|
62
|
+
const foreign = await foreignUse(ctx, name);
|
|
63
|
+
if (foreign) {
|
|
64
|
+
refuse(`The name ${name} is taken on this Docker engine by something that is not a Foliwake instance ` +
|
|
65
|
+
`(${foreign}); it is left alone. Choose another name.`);
|
|
66
|
+
}
|
|
67
|
+
const earlier = instances.find((instance) => instance.name === name);
|
|
68
|
+
const kept = earlier?.volumes.some((volume) => volume.name === dataVolume(name)) ?? false;
|
|
69
|
+
if (!kept)
|
|
70
|
+
return { name, reuseData: false };
|
|
71
|
+
ctx.err(`The data volume ${dataVolume(name)} of an earlier instance ${name} exists (kept by \`remove\`).`);
|
|
72
|
+
if (ctx.interactive) {
|
|
73
|
+
const question = 'Use its sites and accounts? (No: stop here; delete it with ' +
|
|
74
|
+
`\`foliwake docker remove ${name} --delete-data\`)`;
|
|
75
|
+
const reuse = await askerOf(ctx).confirm(question, true);
|
|
76
|
+
if (!reuse)
|
|
77
|
+
refuse('Nothing was changed.');
|
|
78
|
+
}
|
|
79
|
+
return { name, reuseData: true };
|
|
80
|
+
}
|
|
81
|
+
async function choosePort(ctx, request, used, bind) {
|
|
82
|
+
const free = await firstFreePort(ctx, used, bind, DEFAULT_PORT);
|
|
83
|
+
if (request.port !== undefined) {
|
|
84
|
+
const port = parsePort(request.port) ?? refuse(`--port must be a port number (1–65535); got ${JSON.stringify(request.port)}.`);
|
|
85
|
+
const problem = await portProblem(ctx, used, bind, port);
|
|
86
|
+
if (!problem)
|
|
87
|
+
return port;
|
|
88
|
+
if (!ctx.interactive) {
|
|
89
|
+
const hint = free ? ` ${free} is free: --port ${free}.` : '';
|
|
90
|
+
return refuse(`Port ${problem}.${hint}`);
|
|
91
|
+
}
|
|
92
|
+
if (free && (await askerOf(ctx).confirm(`Port ${problem}; use ${free}?`, true)))
|
|
93
|
+
return free;
|
|
94
|
+
return refuse('Nothing was changed.');
|
|
95
|
+
}
|
|
96
|
+
if (!ctx.interactive)
|
|
97
|
+
return free ?? refuse(`No free port from ${DEFAULT_PORT}; choose one with --port.`);
|
|
98
|
+
const message = `Port on this computer${free ? ` (${free} is free)` : ''}`;
|
|
99
|
+
const validate = (value) => (parsePort(value) ? undefined : 'A port number, 1–65535');
|
|
100
|
+
for (let initial = free ?? DEFAULT_PORT;;) {
|
|
101
|
+
const typed = await askerOf(ctx).text(message, { initial: String(initial), validate });
|
|
102
|
+
const port = parsePort(typed);
|
|
103
|
+
const problem = await portProblem(ctx, used, bind, port);
|
|
104
|
+
if (!problem)
|
|
105
|
+
return port;
|
|
106
|
+
const next = await firstFreePort(ctx, used, bind, port + 1);
|
|
107
|
+
if (next && (await askerOf(ctx).confirm(`Port ${problem}; use ${next}?`, true)))
|
|
108
|
+
return next;
|
|
109
|
+
initial = next ?? port;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const STORAGE_CHOICES = [
|
|
113
|
+
{ value: 'volume', label: 'The data volume', hint: 'single machine' },
|
|
114
|
+
{ value: 's3', label: 'S3-compatible storage', hint: 'S3, R2, MinIO' },
|
|
115
|
+
];
|
|
116
|
+
async function chooseStorage(ctx, request) {
|
|
117
|
+
const kind = await pick(ctx, request.storage, (asker) => asker.select('Where to keep the sites', STORAGE_CHOICES, 'volume'), 'volume');
|
|
118
|
+
if (kind === 'volume')
|
|
119
|
+
return { kind };
|
|
120
|
+
if (kind !== 's3')
|
|
121
|
+
refuse(`--storage must be volume or s3; got ${JSON.stringify(kind)}.`);
|
|
122
|
+
const askEndpoint = (asker) => asker.text('S3 endpoint (https://…)', { validate: httpAddressProblem });
|
|
123
|
+
const endpoint = await pick(ctx, request.storageEndpoint, askEndpoint, null, '--storage s3 needs --storage-endpoint.');
|
|
124
|
+
if (!HTTP_ADDRESS.test(endpoint))
|
|
125
|
+
refuse(`--storage-endpoint must be an http(s) address; got ${JSON.stringify(endpoint)}.`);
|
|
126
|
+
const askRegion = (asker) => asker.text('Region (`auto` on R2)', { initial: 'us-east-1' });
|
|
127
|
+
const region = await pick(ctx, request.storageRegion, askRegion, 'us-east-1');
|
|
128
|
+
const askBucket = (asker) => asker.text('Bucket name of each site', { initial: 'foliwake-{org}-{site}' });
|
|
129
|
+
const bucket = await pick(ctx, request.storageBucket, askBucket, 'foliwake-{org}-{site}');
|
|
130
|
+
const askCreate = (asker) => asker.confirm('May the key create buckets?', true);
|
|
131
|
+
const createBuckets = await pick(ctx, request.storageCreateBuckets, askCreate, true);
|
|
132
|
+
const fromEnv = (key) => (ctx.env[key] ? ctx.env[key] : undefined);
|
|
133
|
+
const keyMissing = 'The S3 key is read from FOLIWAKE_STORAGE_ACCESS_KEY_ID and FOLIWAKE_STORAGE_SECRET_ACCESS_KEY in ' +
|
|
134
|
+
'the environment of this command (never from a flag); set both.';
|
|
135
|
+
const accessKeyId = await pick(ctx, fromEnv('FOLIWAKE_STORAGE_ACCESS_KEY_ID'), (asker) => asker.secret('Access key id'), null, keyMissing);
|
|
136
|
+
const secretMissing = 'The S3 secret is read from FOLIWAKE_STORAGE_SECRET_ACCESS_KEY in the environment of this command ' +
|
|
137
|
+
'(never from a flag).';
|
|
138
|
+
const secretKey = await pick(ctx, fromEnv('FOLIWAKE_STORAGE_SECRET_ACCESS_KEY'), (asker) => asker.secret('Secret access key'), null, secretMissing);
|
|
139
|
+
return { kind: 's3', endpoint, region, bucket, createBuckets, accessKeyId, secretKey };
|
|
140
|
+
}
|
|
141
|
+
const TRACES_CHOICES = [
|
|
142
|
+
{ value: 'none', label: 'Off' },
|
|
143
|
+
{ value: 'jaeger', label: 'Jaeger beside the server', hint: 'UI on this computer only' },
|
|
144
|
+
{ value: 'external', label: 'My own OTLP collector' },
|
|
145
|
+
];
|
|
146
|
+
const JAEGER_STORE_CHOICES = [
|
|
147
|
+
{ value: 'memory', label: 'In memory', hint: 'until a restart' },
|
|
148
|
+
{ value: 'badger', label: 'On disk, a week' },
|
|
149
|
+
];
|
|
150
|
+
/** Traces to your own collector: its endpoint, headers (secret) and trace page. */
|
|
151
|
+
async function chooseExternal(ctx, request) {
|
|
152
|
+
const askEndpoint = (asker) => asker.text('OTLP/HTTP endpoint (https://…)', { validate: httpAddressProblem });
|
|
153
|
+
const endpoint = await pick(ctx, request.otlpEndpoint, askEndpoint, null, '--traces external needs --otlp-endpoint.');
|
|
154
|
+
if (!HTTP_ADDRESS.test(endpoint))
|
|
155
|
+
refuse(`--otlp-endpoint must be an http(s) address; got ${JSON.stringify(endpoint)}.`);
|
|
156
|
+
let headers = ctx.env.OTEL_EXPORTER_OTLP_HEADERS ?? '';
|
|
157
|
+
if (!headers && ctx.interactive) {
|
|
158
|
+
headers = await askerOf(ctx).secret('OTLP headers (key=value,…; Enter for none)', { optional: true });
|
|
159
|
+
}
|
|
160
|
+
const traceUrl = request.traceUrlTemplate || null;
|
|
161
|
+
const problem = traceUrl === null ? null : traceUrlTemplateProblem(traceUrl);
|
|
162
|
+
if (problem)
|
|
163
|
+
refuse(`--trace-url-template: ${problem}`);
|
|
164
|
+
return { traces: 'external', jaeger: null, otlp: { endpoint, headers: headers || null }, traceUrl };
|
|
165
|
+
}
|
|
166
|
+
async function chooseTraces(ctx, request, used) {
|
|
167
|
+
const askTraces = (asker) => asker.select('Traces', TRACES_CHOICES, 'none');
|
|
168
|
+
const traces = await pick(ctx, request.traces, askTraces, 'none');
|
|
169
|
+
if (!TRACES_MODES.includes(traces))
|
|
170
|
+
refuse(`--traces must be none, jaeger or external; got ${JSON.stringify(traces)}.`);
|
|
171
|
+
if (request.traceUrlTemplate !== undefined && traces !== 'external') {
|
|
172
|
+
refuse('--trace-url-template goes with --traces external (with Jaeger the CLI sets it).');
|
|
173
|
+
}
|
|
174
|
+
if (traces === 'none')
|
|
175
|
+
return { traces, jaeger: null, otlp: null };
|
|
176
|
+
if (traces === 'external')
|
|
177
|
+
return chooseExternal(ctx, request);
|
|
178
|
+
const askStore = (asker) => asker.select('Keep traces', JAEGER_STORE_CHOICES, 'memory');
|
|
179
|
+
const store = await pick(ctx, request.jaegerStore, askStore, 'memory');
|
|
180
|
+
if (store !== 'memory' && store !== 'badger')
|
|
181
|
+
refuse(`--jaeger-store must be memory or badger; got ${JSON.stringify(store)}.`);
|
|
182
|
+
let port;
|
|
183
|
+
if (request.jaegerPort !== undefined) {
|
|
184
|
+
port =
|
|
185
|
+
parsePort(request.jaegerPort) ??
|
|
186
|
+
refuse(`--jaeger-port must be a port number; got ${JSON.stringify(request.jaegerPort)}.`);
|
|
187
|
+
const problem = await portProblem(ctx, used, '127.0.0.1', port);
|
|
188
|
+
if (problem)
|
|
189
|
+
refuse(`Jaeger UI port ${problem}; choose another with --jaeger-port.`);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
port = await firstFreePort(ctx, used, '127.0.0.1', DEFAULT_JAEGER_PORT);
|
|
193
|
+
}
|
|
194
|
+
if (port === null)
|
|
195
|
+
refuse(`No free port from ${DEFAULT_JAEGER_PORT} for the Jaeger UI; choose one with --jaeger-port.`);
|
|
196
|
+
const jaeger = { store: store, port: port };
|
|
197
|
+
return { traces, jaeger, otlp: { endpoint: 'http://jaeger:4318', headers: null } };
|
|
198
|
+
}
|
|
199
|
+
const BIND_CHOICES = [
|
|
200
|
+
{ value: '127.0.0.1', label: 'This computer only', hint: '127.0.0.1' },
|
|
201
|
+
{ value: '0.0.0.0', label: 'Everywhere', hint: '0.0.0.0; put HTTPS in front' },
|
|
202
|
+
];
|
|
203
|
+
/** The public address, and the domain of the sites when that address is not this computer. */
|
|
204
|
+
async function chooseAddress(ctx, request, port) {
|
|
205
|
+
const defaultOrigin = `http://localhost:${port}`;
|
|
206
|
+
const askOrigin = (asker) => asker.text('Public address (browsers and `foliwake login`)', {
|
|
207
|
+
initial: defaultOrigin,
|
|
208
|
+
validate: (value) => originProblem(value) ?? undefined,
|
|
209
|
+
});
|
|
210
|
+
const publicOrigin = await pick(ctx, request.publicOrigin, askOrigin, defaultOrigin);
|
|
211
|
+
const originError = originProblem(publicOrigin);
|
|
212
|
+
if (originError)
|
|
213
|
+
refuse(originError);
|
|
214
|
+
const host = new URL(publicOrigin).hostname;
|
|
215
|
+
if (LOCAL_HOSTS.has(host))
|
|
216
|
+
return { publicOrigin, domain: request.domain ?? null };
|
|
217
|
+
const askDomain = (asker) => asker.text('Domain of the sites (<site>.live.<domain>)', { initial: host });
|
|
218
|
+
const domain = await pick(ctx, request.domain, askDomain, host);
|
|
219
|
+
return { publicOrigin, domain: domain || null };
|
|
220
|
+
}
|
|
221
|
+
/** The owner's e-mail; not needed when the data volume (with its owner) is reused. */
|
|
222
|
+
async function chooseOwner(ctx, request, reuseData) {
|
|
223
|
+
if (reuseData && request.ownerEmail === undefined)
|
|
224
|
+
return null;
|
|
225
|
+
const askOwner = (asker) => asker.text('Owner e-mail (the first account; no mail is sent)', {
|
|
226
|
+
validate: (value) => (EMAIL.test(value) ? undefined : 'An e-mail address'),
|
|
227
|
+
});
|
|
228
|
+
const ownerEmail = await pick(ctx, request.ownerEmail, askOwner, null, 'The first start needs the owner account: pass --owner-email.');
|
|
229
|
+
if (!EMAIL.test(ownerEmail))
|
|
230
|
+
refuse(`--owner-email must be an e-mail address; got ${JSON.stringify(ownerEmail)}.`);
|
|
231
|
+
return ownerEmail;
|
|
232
|
+
}
|
|
233
|
+
/** All answers of an install, or a refusal; asks in a terminal only for what the flags left open. */
|
|
234
|
+
export async function planInstall(ctx, request) {
|
|
235
|
+
const instances = await discoverInstances(ctx);
|
|
236
|
+
const used = portsInUse(instances);
|
|
237
|
+
const { name, reuseData } = await chooseName(ctx, request, instances);
|
|
238
|
+
const askBind = (asker) => asker.select('Reachable from', BIND_CHOICES, '127.0.0.1');
|
|
239
|
+
const bind = await pick(ctx, request.bind, askBind, '127.0.0.1');
|
|
240
|
+
if (!net.isIP(bind))
|
|
241
|
+
refuse(`--bind must be an IP address such as 127.0.0.1 or 0.0.0.0; got ${JSON.stringify(bind)}.`);
|
|
242
|
+
const port = await choosePort(ctx, request, used, bind);
|
|
243
|
+
// Reserved for the server, so the Jaeger UI below never gets the same port.
|
|
244
|
+
used.set(port, `${name} (its server)`);
|
|
245
|
+
const { publicOrigin, domain } = await chooseAddress(ctx, request, port);
|
|
246
|
+
proxyTrustOf(ctx, publicOrigin, bind); // only its warning: planEnv writes the value
|
|
247
|
+
const ownerEmail = await chooseOwner(ctx, request, reuseData);
|
|
248
|
+
const storage = await chooseStorage(ctx, request);
|
|
249
|
+
const traces = await chooseTraces(ctx, request, used);
|
|
250
|
+
const cache = await chooseCache(ctx, request, used, bind);
|
|
251
|
+
// Never asked: a newcomer has no reason to change it; --image pins a version or a local build.
|
|
252
|
+
const image = request.image ?? DEFAULT_IMAGE;
|
|
253
|
+
return { name, image, bind, port, publicOrigin, domain, ownerEmail, reuseData, storage, ...traces, cache };
|
|
254
|
+
}
|
|
255
|
+
const LOOPBACK_BINDS = new Set(['127.0.0.1', '::1']);
|
|
256
|
+
/**
|
|
257
|
+
* FOLIWAKE_TRUST_PROXY: '1' (believe X-Forwarded-For) for a public address that is not this computer,
|
|
258
|
+
* so an HTTPS proxy is in front, and only on a loopback port, which nothing but a proxy on this
|
|
259
|
+
* computer reaches. On a port open to other networks a client could name any address there and
|
|
260
|
+
* dodge the per-client sign-in limits, so it stays ''. install and configure both use it.
|
|
261
|
+
*/
|
|
262
|
+
export function trustProxyFor(publicOrigin, bind) {
|
|
263
|
+
return LOCAL_HOSTS.has(new URL(publicOrigin).hostname) || !LOOPBACK_BINDS.has(bind) ? '' : '1';
|
|
264
|
+
}
|
|
265
|
+
/** trustProxyFor, saying so when a public address keeps the trust off because its port is open. */
|
|
266
|
+
export function proxyTrustOf(ctx, publicOrigin, bind) {
|
|
267
|
+
const trust = trustProxyFor(publicOrigin, bind);
|
|
268
|
+
if (!trust && !LOCAL_HOSTS.has(new URL(publicOrigin).hostname)) {
|
|
269
|
+
ctx.err(`The port is open on ${bind}, so FOLIWAKE_TRUST_PROXY is not set: a client reaching it directly could ` +
|
|
270
|
+
'name any address in X-Forwarded-For. Sign-in limits then count the proxy as one client for every ' +
|
|
271
|
+
'browser. Bind to 127.0.0.1 (--bind) with the HTTPS proxy on this computer to have it set.');
|
|
272
|
+
}
|
|
273
|
+
return trust;
|
|
274
|
+
}
|
|
275
|
+
/** The trace page of an operation in the instance's own Jaeger UI (FOLIWAKE_TRACE_URL_TEMPLATE). */
|
|
276
|
+
export const jaegerTraceUrl = (port) => `http://127.0.0.1:${port}/trace/{traceId}`;
|
|
277
|
+
/** The .env values of a plan. */
|
|
278
|
+
export function planEnv(plan) {
|
|
279
|
+
const values = {
|
|
280
|
+
FOLIWAKE_INSTANCE: plan.name,
|
|
281
|
+
FOLIWAKE_TRACES: plan.traces,
|
|
282
|
+
FOLIWAKE_IMAGE: plan.image,
|
|
283
|
+
FOLIWAKE_BIND: plan.bind,
|
|
284
|
+
FOLIWAKE_HOST_PORT: String(plan.port),
|
|
285
|
+
FOLIWAKE_PUBLIC_ORIGIN: plan.publicOrigin,
|
|
286
|
+
FOLIWAKE_DOMAIN: plan.domain ?? '',
|
|
287
|
+
FOLIWAKE_TRUST_PROXY: trustProxyFor(plan.publicOrigin, plan.bind),
|
|
288
|
+
FOLIWAKE_OWNER_EMAIL: plan.ownerEmail ?? '',
|
|
289
|
+
};
|
|
290
|
+
if (plan.storage.kind === 's3') {
|
|
291
|
+
Object.assign(values, {
|
|
292
|
+
FOLIWAKE_STORAGE_ENDPOINT: plan.storage.endpoint,
|
|
293
|
+
FOLIWAKE_STORAGE_REGION: plan.storage.region,
|
|
294
|
+
FOLIWAKE_STORAGE_BUCKET: plan.storage.bucket,
|
|
295
|
+
FOLIWAKE_STORAGE_CREATE_BUCKETS: plan.storage.createBuckets ? '1' : '0',
|
|
296
|
+
FOLIWAKE_STORAGE_ACCESS_KEY_ID: plan.storage.accessKeyId,
|
|
297
|
+
FOLIWAKE_STORAGE_SECRET_ACCESS_KEY: plan.storage.secretKey,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (plan.otlp) {
|
|
301
|
+
values.OTEL_EXPORTER_OTLP_ENDPOINT = plan.otlp.endpoint;
|
|
302
|
+
if (plan.otlp.headers)
|
|
303
|
+
values.OTEL_EXPORTER_OTLP_HEADERS = plan.otlp.headers;
|
|
304
|
+
values.FOLIWAKE_ENVIRONMENT = plan.name;
|
|
305
|
+
}
|
|
306
|
+
if (plan.traceUrl)
|
|
307
|
+
values.FOLIWAKE_TRACE_URL_TEMPLATE = plan.traceUrl;
|
|
308
|
+
if (plan.cache)
|
|
309
|
+
applyCache(values, plan.cache);
|
|
310
|
+
if (plan.jaeger) {
|
|
311
|
+
values.JAEGER_CONFIG = plan.jaeger.store;
|
|
312
|
+
values.JAEGER_UI_PORT = String(plan.jaeger.port);
|
|
313
|
+
values.FOLIWAKE_TRACE_URL_TEMPLATE = jaegerTraceUrl(plan.jaeger.port);
|
|
314
|
+
}
|
|
315
|
+
return values;
|
|
316
|
+
}
|
|
317
|
+
/** One line of what will be installed (no secret). */
|
|
318
|
+
export function planSummary(plan) {
|
|
319
|
+
let data = `data volume ${dataVolume(plan.name)}`;
|
|
320
|
+
if (plan.reuseData)
|
|
321
|
+
data = `existing ${data}`;
|
|
322
|
+
else if (plan.storage.kind === 's3')
|
|
323
|
+
data = `S3 ${plan.storage.endpoint}`;
|
|
324
|
+
const traces = plan.jaeger
|
|
325
|
+
? `Jaeger http://127.0.0.1:${plan.jaeger.port}`
|
|
326
|
+
: plan.otlp
|
|
327
|
+
? `OTLP ${plan.otlp.endpoint}`
|
|
328
|
+
: 'no traces';
|
|
329
|
+
const cache = plan.cache?.cachePort ? ` · Varnish ${plan.bind}:${plan.cache.cachePort}` : '';
|
|
330
|
+
const address = `${plan.publicOrigin} (${plan.bind}:${plan.port})`;
|
|
331
|
+
return `instance ${plan.name} · ${address} · ${data} · ${traces}${cache} · ${plan.image}`;
|
|
332
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type DockerContext } from './context.js';
|
|
2
|
+
import { type InstallRequest } from './install-plan.js';
|
|
3
|
+
export interface InstallOptions {
|
|
4
|
+
/** Skip the final «Install?» question. */
|
|
5
|
+
yes?: boolean;
|
|
6
|
+
/** Open the sign-in link in the browser: true/false, or undefined = ask in a terminal. */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** When to pull the image (default always). */
|
|
9
|
+
pull?: PullPolicy;
|
|
10
|
+
/** How long to wait for the ready line in the log (ms). */
|
|
11
|
+
readyTimeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** When to pull: `always` (the default; a failed pull fails) or `missing` (only when the engine lacks the image). */
|
|
14
|
+
export type PullPolicy = 'always' | 'missing';
|
|
15
|
+
/**
|
|
16
|
+
* `docker compose pull` of the server image. A failed pull always fails the command (an expired
|
|
17
|
+
* registry sign-in must not pass for "up to date"); an image already on the engine is used
|
|
18
|
+
* without pulling only with the `missing` policy, chosen explicitly (`install --pull missing`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function pullImage(ctx: DockerContext, name: string, image: string, policy?: PullPolicy): Promise<void>;
|
|
21
|
+
/** Runs `install`; resolves to the exit status. Throws DockerUsageError (2) or DockerFailure (1). */
|
|
22
|
+
export declare function runInstall(ctx: DockerContext, request: InstallRequest, options?: InstallOptions): Promise<number>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// `foliwake docker install [name]`: the answers (install-plan.ts) → the files in
|
|
2
|
+
// ~/.config/foliwake/docker/<name>/ → pull → `up -d --wait` → the address, the owner's one-time
|
|
3
|
+
// sign-in link and the next commands. Until the containers exist a failure removes the files again,
|
|
4
|
+
// so a second try starts clean.
|
|
5
|
+
import { askerOf } from './asker.js';
|
|
6
|
+
import { composeFile } from './compose-file.js';
|
|
7
|
+
import { DockerFailure } from './context.js';
|
|
8
|
+
import { planEnv, planInstall, planSummary } from './install-plan.js';
|
|
9
|
+
import { writeVerified } from './env-verify.js';
|
|
10
|
+
import { composeArgs, composeEnv, undoWrite } from './settings-files.js';
|
|
11
|
+
import { failureText } from './runner.js';
|
|
12
|
+
import { translatePortError } from './lifecycle.js';
|
|
13
|
+
const READY = 'Foliwake is ready at ';
|
|
14
|
+
const LINK = /one-time sign-in link \([^)]*\): (\S+)/;
|
|
15
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
|
+
/**
|
|
17
|
+
* `docker compose pull` of the server image. A failed pull always fails the command (an expired
|
|
18
|
+
* registry sign-in must not pass for "up to date"); an image already on the engine is used
|
|
19
|
+
* without pulling only with the `missing` policy, chosen explicitly (`install --pull missing`).
|
|
20
|
+
*/
|
|
21
|
+
export async function pullImage(ctx, name, image, policy = 'always') {
|
|
22
|
+
if (policy === 'missing') {
|
|
23
|
+
const local = await ctx.docker.run(['image', 'inspect', '--format', '{{.Id}}', image]);
|
|
24
|
+
if (local.code === 0) {
|
|
25
|
+
ctx.err(`Using ${image} as it is on this engine (--pull missing).`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const pulled = await ctx.docker.run(composeArgs(ctx.env, name, ['pull', '--quiet', 'foliwake']), {
|
|
30
|
+
env: composeEnv(ctx.env),
|
|
31
|
+
});
|
|
32
|
+
if (pulled.code === 0)
|
|
33
|
+
return;
|
|
34
|
+
const denied = /denied|unauthorized|authentication required/i.test(pulled.stderr);
|
|
35
|
+
let hint = '';
|
|
36
|
+
if (denied && image.startsWith('ghcr.io/')) {
|
|
37
|
+
hint =
|
|
38
|
+
' The image is private: sign in to the registry once with `docker login ghcr.io -u <GitHub user>` ' +
|
|
39
|
+
'(a token with read:packages), then try again.';
|
|
40
|
+
}
|
|
41
|
+
const local = policy === 'always' ? ' An image built on this engine is used with `install --pull missing`.' : '';
|
|
42
|
+
throw new DockerFailure(`Could not pull ${image}: ${failureText(pulled)}${hint}${local}`);
|
|
43
|
+
}
|
|
44
|
+
/** The ready block of the log once it is printed (or null after the timeout). */
|
|
45
|
+
async function readyLog(ctx, name, timeoutMs) {
|
|
46
|
+
const deadline = Date.now() + timeoutMs;
|
|
47
|
+
for (;;) {
|
|
48
|
+
const logs = await ctx.docker.run(['compose', '-p', name, 'logs', '--no-log-prefix', 'foliwake'], {
|
|
49
|
+
env: composeEnv(ctx.env),
|
|
50
|
+
});
|
|
51
|
+
const at = logs.stdout.lastIndexOf(READY);
|
|
52
|
+
if (at !== -1)
|
|
53
|
+
return logs.stdout.slice(at);
|
|
54
|
+
if (Date.now() > deadline)
|
|
55
|
+
return null;
|
|
56
|
+
await sleep(500);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function confirmPlan(ctx, plan, options) {
|
|
60
|
+
const summary = planSummary(plan);
|
|
61
|
+
if (!ctx.interactive || options.yes) {
|
|
62
|
+
ctx.err(`Installing ${summary}`);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return askerOf(ctx).confirm(`Ready: ${summary}. Install?`, true);
|
|
66
|
+
}
|
|
67
|
+
/** Runs `install`; resolves to the exit status. Throws DockerUsageError (2) or DockerFailure (1). */
|
|
68
|
+
export async function runInstall(ctx, request, options = {}) {
|
|
69
|
+
if (ctx.interactive)
|
|
70
|
+
askerOf(ctx).intro('Install Foliwake in Docker');
|
|
71
|
+
const plan = await planInstall(ctx, request);
|
|
72
|
+
if (!(await confirmPlan(ctx, plan, options))) {
|
|
73
|
+
ctx.err('Nothing was changed.');
|
|
74
|
+
return 130;
|
|
75
|
+
}
|
|
76
|
+
const cache = plan.cache?.cache ?? 'none';
|
|
77
|
+
const compose = await composeFile({ name: plan.name, traces: plan.traces, cliVersion: ctx.cliVersion, cache });
|
|
78
|
+
const { dir, previous } = await writeVerified(ctx, plan.name, { compose, env: { values: planEnv(plan) } });
|
|
79
|
+
try {
|
|
80
|
+
await pullImage(ctx, plan.name, plan.image, options.pull ?? 'always');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
// Only a folder this install created is removed; files that were there come back as they were.
|
|
84
|
+
await undoWrite(ctx.env, plan.name, previous);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
ctx.err(`Starting ${plan.name} (settings in ${dir}) …`);
|
|
88
|
+
const started = Date.now();
|
|
89
|
+
const up = await ctx.docker.run(composeArgs(ctx.env, plan.name, ['up', '-d', '--wait', '--wait-timeout', '180']), {
|
|
90
|
+
env: composeEnv(ctx.env),
|
|
91
|
+
});
|
|
92
|
+
if (up.code !== 0) {
|
|
93
|
+
throw new DockerFailure(`${plan.name} did not start: ${translatePortError(failureText(up), plan.name)}\nSee \`foliwake docker ` +
|
|
94
|
+
`logs ${plan.name}\`; \`foliwake docker remove ${plan.name}\` takes it away again.`);
|
|
95
|
+
}
|
|
96
|
+
ctx.err(`Started; healthy after ${Math.round((Date.now() - started) / 1000)} s.`);
|
|
97
|
+
const log = await readyLog(ctx, plan.name, options.readyTimeoutMs ?? 30_000);
|
|
98
|
+
const link = log ? LINK.exec(log)?.[1] : undefined;
|
|
99
|
+
ctx.out(`Foliwake is ready at ${plan.publicOrigin}/`);
|
|
100
|
+
if (link) {
|
|
101
|
+
ctx.out(`Owner ${plan.ownerEmail ?? ''}: one-time sign-in link (15 minutes): ${link}`);
|
|
102
|
+
ctx.err('Keep this link and the log private: until the owner has signed in once, ' +
|
|
103
|
+
'anyone with it can sign in as the owner.');
|
|
104
|
+
const open = options.open ?? (ctx.interactive ? await askerOf(ctx).confirm('Open it in your browser now?', true) : false);
|
|
105
|
+
if (open)
|
|
106
|
+
(ctx.openBrowser ?? defaultOpenBrowser)(link);
|
|
107
|
+
}
|
|
108
|
+
else
|
|
109
|
+
ctx.out(`A sign-in link for an account: foliwake docker link ${plan.name}${plan.ownerEmail ? '' : ' --email <address>'}`);
|
|
110
|
+
if (plan.jaeger)
|
|
111
|
+
ctx.out(`Traces: Jaeger at http://127.0.0.1:${plan.jaeger.port}/ (service foliwake)`);
|
|
112
|
+
ctx.out(`Next: foliwake login ${plan.publicOrigin} · foliwake create mysite`);
|
|
113
|
+
ctx.out(`Later: foliwake docker status ${plan.name} · logs · link · update · remove`);
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
function defaultOpenBrowser(url) {
|
|
117
|
+
void import('../settings.js').then(({ openBrowser }) => openBrowser(url));
|
|
118
|
+
}
|