@marinoscar/platform-cli 0.1.0-next.13 → 0.1.0-next.15
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 +32 -0
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/engine/commands/deploy.d.ts +7 -0
- package/dist/engine/commands/deploy.d.ts.map +1 -1
- package/dist/engine/commands/deploy.js +7 -2
- package/dist/engine/commands/deploy.js.map +1 -1
- package/dist/engine/deploy/checks/compose.d.ts +10 -1
- package/dist/engine/deploy/checks/compose.d.ts.map +1 -1
- package/dist/engine/deploy/checks/compose.js +4 -4
- package/dist/engine/deploy/checks/compose.js.map +1 -1
- package/dist/engine/deploy/checks/index.d.ts +1 -0
- package/dist/engine/deploy/checks/index.d.ts.map +1 -1
- package/dist/engine/deploy/checks/index.js +4 -0
- package/dist/engine/deploy/checks/index.js.map +1 -1
- package/dist/engine/deploy/checks/stack-ports.d.ts +4 -0
- package/dist/engine/deploy/checks/stack-ports.d.ts.map +1 -0
- package/dist/engine/deploy/checks/stack-ports.js +261 -0
- package/dist/engine/deploy/checks/stack-ports.js.map +1 -0
- package/dist/engine/deploy/checks/types.d.ts +16 -0
- package/dist/engine/deploy/checks/types.d.ts.map +1 -1
- package/dist/engine/deploy/checks/types.js.map +1 -1
- package/dist/engine/deploy/compose-command.d.ts +16 -0
- package/dist/engine/deploy/compose-command.d.ts.map +1 -0
- package/dist/engine/deploy/compose-command.js +40 -0
- package/dist/engine/deploy/compose-command.js.map +1 -0
- package/dist/engine/deploy/compose-containers.d.ts +30 -1
- package/dist/engine/deploy/compose-containers.d.ts.map +1 -1
- package/dist/engine/deploy/compose-containers.js +79 -13
- package/dist/engine/deploy/compose-containers.js.map +1 -1
- package/dist/engine/deploy/compose-port-variables.d.ts +58 -0
- package/dist/engine/deploy/compose-port-variables.d.ts.map +1 -0
- package/dist/engine/deploy/compose-port-variables.js +184 -0
- package/dist/engine/deploy/compose-port-variables.js.map +1 -0
- package/dist/engine/deploy/compose-ports.d.ts +98 -0
- package/dist/engine/deploy/compose-ports.d.ts.map +1 -0
- package/dist/engine/deploy/compose-ports.js +204 -0
- package/dist/engine/deploy/compose-ports.js.map +1 -0
- package/dist/engine/deploy/compose-project.d.ts +1 -1
- package/dist/engine/deploy/compose-project.d.ts.map +1 -1
- package/dist/engine/deploy/compose-project.js.map +1 -1
- package/dist/engine/deploy/free-ports.d.ts +145 -0
- package/dist/engine/deploy/free-ports.d.ts.map +1 -0
- package/dist/engine/deploy/free-ports.js +235 -0
- package/dist/engine/deploy/free-ports.js.map +1 -0
- package/dist/engine/deploy/install.d.ts +16 -10
- package/dist/engine/deploy/install.d.ts.map +1 -1
- package/dist/engine/deploy/install.js +136 -26
- package/dist/engine/deploy/install.js.map +1 -1
- package/dist/engine/deploy/stack-ports-gate.d.ts +19 -0
- package/dist/engine/deploy/stack-ports-gate.d.ts.map +1 -0
- package/dist/engine/deploy/stack-ports-gate.js +54 -0
- package/dist/engine/deploy/stack-ports-gate.js.map +1 -0
- package/dist/engine/deploy/steps/registry.d.ts +2 -2
- package/dist/engine/deploy/steps/registry.d.ts.map +1 -1
- package/dist/engine/deploy/steps/registry.js +2 -0
- package/dist/engine/deploy/steps/registry.js.map +1 -1
- package/dist/engine/deploy/testing/fake-containers.d.ts +13 -2
- package/dist/engine/deploy/testing/fake-containers.d.ts.map +1 -1
- package/dist/engine/deploy/testing/fake-containers.js +9 -2
- package/dist/engine/deploy/testing/fake-containers.js.map +1 -1
- package/dist/engine/deploy/testing/fake-vps.d.ts.map +1 -1
- package/dist/engine/deploy/testing/fake-vps.js +6 -0
- package/dist/engine/deploy/testing/fake-vps.js.map +1 -1
- package/dist/engine/deploy/update.d.ts +2 -0
- package/dist/engine/deploy/update.d.ts.map +1 -1
- package/dist/engine/deploy/update.js +79 -1
- package/dist/engine/deploy/update.js.map +1 -1
- package/dist/engine/index.d.ts +1 -1
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/tui/screens/deploy/doctor.js +1 -0
- package/dist/engine/tui/screens/deploy/doctor.js.map +1 -1
- package/dist/engine/tui/screens/deploy/install.d.ts.map +1 -1
- package/dist/engine/tui/screens/deploy/install.js +4 -0
- package/dist/engine/tui/screens/deploy/install.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { composeArgv, composeCwd } from './compose-command.js';
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// Which host ports will the composed stack publish? (#1024)
|
|
4
|
+
// =============================================================================
|
|
5
|
+
//
|
|
6
|
+
// `docker compose up -d` recreates the services that changed, in dependency
|
|
7
|
+
// order, and only THEN meets a host port something else holds. By that point the
|
|
8
|
+
// web, api and nginx containers have been replaced and the one that needed the
|
|
9
|
+
// port (`greptimedb` on 127.0.0.1:14003) cannot start: the site is down. So the
|
|
10
|
+
// question "will every port the stack publishes bind?" has to be answered before
|
|
11
|
+
// the first container is touched, and the only complete answer to "which ports
|
|
12
|
+
// does the stack publish?" is compose's own: the same files, the same project and
|
|
13
|
+
// the same `.env` `up` will read, merged and interpolated (`!override` and
|
|
14
|
+
// `${APP_BIND_PORT:-3535}` included), i.e. `docker compose config --format json`.
|
|
15
|
+
//
|
|
16
|
+
// ⚠ THAT OUTPUT CARRIES EVERY SECRET. The rendered `environment:` of each
|
|
17
|
+
// service holds POSTGRES_PASSWORD, JWT_SECRET and the rest, in clear. This module
|
|
18
|
+
// parses it in memory and hands back ports only; it never logs, journals or
|
|
19
|
+
// quotes stdout, not even to explain a parse failure. A failed command's message
|
|
20
|
+
// is stderr (the executor's tail), which compose does not fill with values.
|
|
21
|
+
//
|
|
22
|
+
// Read-only, argv only, never a shell string. `config` needs no daemon: whether
|
|
23
|
+
// Docker is reachable is the caller's question (`listComposeContainers`).
|
|
24
|
+
// =============================================================================
|
|
25
|
+
/** Hard stop on one published range, so a pathological `1-65535` cannot make a check probe 65k sockets. */
|
|
26
|
+
const MAX_RANGE_PORTS = 1024;
|
|
27
|
+
/** Compose renders the whole stack; a big project on a small VPS is slow, a hang is not. */
|
|
28
|
+
const CONFIG_TIMEOUT_MS = 60_000;
|
|
29
|
+
/** `docker compose config --format json` output that is not the stack this module can read. */
|
|
30
|
+
export class ComposeConfigError extends Error {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'ComposeConfigError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Splits a short-syntax port spec (`127.0.0.1:14003:4003/tcp`) at the colons
|
|
38
|
+
* that are not inside `${...}` or an IPv6 `[...]`, and returns the host side.
|
|
39
|
+
*
|
|
40
|
+
* Shared by the rendered-config fallback and the raw-file variable scan, so
|
|
41
|
+
* both read one grammar.
|
|
42
|
+
*
|
|
43
|
+
* @param spec - The spec, quotes and whitespace already removed.
|
|
44
|
+
* @returns the host address (`''` when none), the published token (which may
|
|
45
|
+
* still hold `${VAR:-default}`), and the protocol; `undefined` for a spec
|
|
46
|
+
* with no published side (`"80"`, a container-only port).
|
|
47
|
+
*/
|
|
48
|
+
export function splitPortSpec(spec) {
|
|
49
|
+
const parts = [];
|
|
50
|
+
let current = '';
|
|
51
|
+
let braces = 0;
|
|
52
|
+
let brackets = 0;
|
|
53
|
+
for (const char of spec) {
|
|
54
|
+
if (char === '{')
|
|
55
|
+
braces += 1;
|
|
56
|
+
else if (char === '}')
|
|
57
|
+
braces = Math.max(0, braces - 1);
|
|
58
|
+
else if (char === '[')
|
|
59
|
+
brackets += 1;
|
|
60
|
+
else if (char === ']')
|
|
61
|
+
brackets = Math.max(0, brackets - 1);
|
|
62
|
+
if (char === ':' && braces === 0 && brackets === 0) {
|
|
63
|
+
parts.push(current);
|
|
64
|
+
current = '';
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
current += char;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
parts.push(current);
|
|
71
|
+
// [hostIp:]published:target[/protocol]; fewer than two parts publishes nothing.
|
|
72
|
+
if (parts.length < 2)
|
|
73
|
+
return undefined;
|
|
74
|
+
const target = parts[parts.length - 1] ?? '';
|
|
75
|
+
const slash = target.indexOf('/');
|
|
76
|
+
const protocol = slash === -1 ? 'tcp' : target.slice(slash + 1).toLowerCase();
|
|
77
|
+
const published = parts[parts.length - 2] ?? '';
|
|
78
|
+
const hostIp = parts.length >= 3 ? parts.slice(0, parts.length - 2).join(':').replace(/^\[|\]$/g, '') : '';
|
|
79
|
+
return { hostIp, published, protocol: protocol === '' ? 'tcp' : protocol };
|
|
80
|
+
}
|
|
81
|
+
/** The ports a `published` token names: `3535`, `"3535"` or the range `"8000-8002"`. */
|
|
82
|
+
function expandPublished(published) {
|
|
83
|
+
if (published === undefined || published === null)
|
|
84
|
+
return [];
|
|
85
|
+
const text = String(published).trim();
|
|
86
|
+
// '' and 0 mean "Docker picks one": no claim to collide with.
|
|
87
|
+
if (text === '' || text === '0')
|
|
88
|
+
return [];
|
|
89
|
+
const [first = '', last = first] = text.split('-');
|
|
90
|
+
const low = Number(first);
|
|
91
|
+
const high = Number(last);
|
|
92
|
+
if (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < low || high > 65535) {
|
|
93
|
+
throw new ComposeConfigError(`unreadable published port ${JSON.stringify(text)}`);
|
|
94
|
+
}
|
|
95
|
+
const ports = [];
|
|
96
|
+
for (let port = low; port <= high && ports.length < MAX_RANGE_PORTS; port += 1)
|
|
97
|
+
ports.push(port);
|
|
98
|
+
return ports;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Every host port a rendered compose project publishes, from the JSON of
|
|
102
|
+
* `docker compose config --format json`.
|
|
103
|
+
*
|
|
104
|
+
* `published` is a string for compose v2 and a number elsewhere, and a range
|
|
105
|
+
* (`"8000-8002"`) is one entry per port; no `published` (or `0`) is a port
|
|
106
|
+
* Docker picks and is no claim; no `host_ip` is every interface; the protocol
|
|
107
|
+
* defaults to `tcp`. A service that lists a short-syntax string instead of the
|
|
108
|
+
* long form is read too. A range wider than 1024 ports is cut at 1024.
|
|
109
|
+
*
|
|
110
|
+
* @param json - The command's stdout.
|
|
111
|
+
* @returns the ports, deduplicated, in service order.
|
|
112
|
+
* @throws ComposeConfigError when the text is not a compose project. The
|
|
113
|
+
* message never quotes the text: it holds the stack's secrets.
|
|
114
|
+
* @stability experimental
|
|
115
|
+
*/
|
|
116
|
+
export function parseComposePorts(json) {
|
|
117
|
+
let document;
|
|
118
|
+
try {
|
|
119
|
+
document = JSON.parse(json);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
throw new ComposeConfigError('the output of `docker compose config --format json` is not JSON');
|
|
123
|
+
}
|
|
124
|
+
const services = document?.services;
|
|
125
|
+
if (typeof services !== 'object' || services === null || Array.isArray(services)) {
|
|
126
|
+
throw new ComposeConfigError('the output of `docker compose config --format json` has no services');
|
|
127
|
+
}
|
|
128
|
+
const found = [];
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
const add = (entry) => {
|
|
131
|
+
const key = `${entry.service}|${entry.hostIp}|${entry.port}|${entry.protocol}`;
|
|
132
|
+
if (seen.has(key))
|
|
133
|
+
return;
|
|
134
|
+
seen.add(key);
|
|
135
|
+
found.push(entry);
|
|
136
|
+
};
|
|
137
|
+
for (const [service, definition] of Object.entries(services)) {
|
|
138
|
+
const ports = definition?.ports;
|
|
139
|
+
if (!Array.isArray(ports))
|
|
140
|
+
continue;
|
|
141
|
+
for (const raw of ports) {
|
|
142
|
+
if (typeof raw === 'string') {
|
|
143
|
+
const split = splitPortSpec(raw.replace(/["'\s]/g, ''));
|
|
144
|
+
if (split === undefined)
|
|
145
|
+
continue;
|
|
146
|
+
for (const port of expandPublished(split.published)) {
|
|
147
|
+
add({ service, hostIp: split.hostIp, port, protocol: split.protocol });
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (typeof raw !== 'object' || raw === null)
|
|
152
|
+
continue;
|
|
153
|
+
const entry = raw;
|
|
154
|
+
const hostIp = typeof entry.host_ip === 'string' ? entry.host_ip.replace(/^\[|\]$/g, '') : '';
|
|
155
|
+
const protocol = typeof entry.protocol === 'string' && entry.protocol !== '' ? entry.protocol.toLowerCase() : 'tcp';
|
|
156
|
+
for (const port of expandPublished(entry.published))
|
|
157
|
+
add({ service, hostIp, port, protocol });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
/** The wordings Docker uses for "I cannot be asked", from the docker-daemon check plus the missing binary. */
|
|
163
|
+
const DOCKER_UNREACHABLE = /cannot connect to the docker daemon|failed to connect to the docker api|is the docker daemon running|docker\.sock|docker: command not found/i;
|
|
164
|
+
/** The failure's own words: the executor's message (argv and stderr tail), and stderr. Never stdout. */
|
|
165
|
+
function failureText(error) {
|
|
166
|
+
if (!(error instanceof Error))
|
|
167
|
+
return String(error);
|
|
168
|
+
const result = error.result;
|
|
169
|
+
const stderr = result?.stderr?.trim() ?? '';
|
|
170
|
+
return stderr === '' || error.message.includes(stderr) ? error.message : `${error.message}\n${stderr}`;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Renders the deployment's compose project exactly as `up -d` would and lists
|
|
174
|
+
* the host ports it publishes, with `docker compose config --format json` run
|
|
175
|
+
* under the run's project and files, in the checkout's compose directory. That
|
|
176
|
+
* directory is where compose finds the deployment's `.env`: no `--env-file` is
|
|
177
|
+
* passed by any `up`, so none is passed here, and the process environment
|
|
178
|
+
* overrides the file the same way. Never runs anything that changes a container.
|
|
179
|
+
*
|
|
180
|
+
* @param options - The command seam, the deployment and the project.
|
|
181
|
+
* @returns the ports, or why they could not be read.
|
|
182
|
+
* @stability experimental
|
|
183
|
+
*/
|
|
184
|
+
export async function readStackPorts(options) {
|
|
185
|
+
const cwd = composeCwd(options.deployRoot);
|
|
186
|
+
const argv = composeArgv(['config', '--format', 'json'], options.project, options.groups, cwd);
|
|
187
|
+
let stdout;
|
|
188
|
+
try {
|
|
189
|
+
({ stdout } = await options.run(argv, { cwd, timeoutMs: CONFIG_TIMEOUT_MS }));
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
const message = failureText(error);
|
|
193
|
+
return DOCKER_UNREACHABLE.test(message)
|
|
194
|
+
? { status: 'docker-unreachable', message }
|
|
195
|
+
: { status: 'render-failed', message };
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
return { status: 'ok', ports: parseComposePorts(stdout) };
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
return { status: 'render-failed', message: error instanceof Error ? error.message : String(error) };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=compose-ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-ports.js","sourceRoot":"","sources":["../../../src/engine/deploy/compose-ports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAG/D,gFAAgF;AAChF,6DAA6D;AAC7D,gFAAgF;AAChF,EAAE;AACF,4EAA4E;AAC5E,iFAAiF;AACjF,+EAA+E;AAC/E,gFAAgF;AAChF,iFAAiF;AACjF,+EAA+E;AAC/E,kFAAkF;AAClF,2EAA2E;AAC3E,kFAAkF;AAClF,EAAE;AACF,0EAA0E;AAC1E,kFAAkF;AAClF,4EAA4E;AAC5E,iFAAiF;AACjF,4EAA4E;AAC5E,EAAE;AACF,gFAAgF;AAChF,0EAA0E;AAC1E,gFAAgF;AAEhF,2GAA2G;AAC3G,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,4FAA4F;AAC5F,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAkBjC,+FAA+F;AAC/F,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAA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EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAChF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC;YACrC,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE;YAC3C,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3C,CAAC;IAED,IAAI,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACtG,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ComposeProjectCommandRunner } from './compose-containers.js';
|
|
2
2
|
import { type DeployState } from './state.js';
|
|
3
|
-
export { isPathUnder, type ComposeContainer, type ComposeProjectCommandRunner } from './compose-containers.js';
|
|
3
|
+
export { isPathUnder, type ComposeContainer, type ComposePortBinding, type ComposeProjectCommandRunner } from './compose-containers.js';
|
|
4
4
|
/**
|
|
5
5
|
* The evidence that decided which project a deployment folder runs under,
|
|
6
6
|
* strongest first. Lets a message say WHY a project was picked.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-project.d.ts","sourceRoot":"","sources":["../../../src/engine/deploy/compose-project.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,2BAA2B,EACjC,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"compose-project.d.ts","sourceRoot":"","sources":["../../../src/engine/deploy/compose-project.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,2BAA2B,EACjC,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAkCxI;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAC/B;IACE,mGAAmG;IACnG,IAAI,EAAE,OAAO,CAAC;IACd,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,KAAK,EAAE,mBAAmB,CAAC;CAC5B,GACD;IACE,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE,qGAAqG;IACrG,IAAI,EAAE,WAAW,CAAC;IAClB,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,GACD;IACE,mFAAmF;IACnF,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAON;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,2BAA2B,EAChC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAC9C,OAAO,CAAC,uBAAuB,CAAC,CA6BlC;AAED,4CAA4C;AAC5C,MAAM,WAAW,8BAA8B;IAC7C,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,wFAAwF;IACxF,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,wDAAwD;IACxD,UAAU,EAAE,2BAA2B,CAAC;CACzC;AAED,8CAA8C;AAC9C,MAAM,WAAW,6BAA6B;IAC5C,2GAA2G;IAC3G,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,6BAA6B,CAAC,CAkExC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-project.js","sourceRoot":"","sources":["../../../src/engine/deploy/compose-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,aAAa,GAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAoB,MAAM,YAAY,CAAC;AAE3E,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"compose-project.js","sourceRoot":"","sources":["../../../src/engine/deploy/compose-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,aAAa,GAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE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EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAEzG,IAAI,CAAC;YACH,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,UAAU,CAAC,UAAU,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,KAAK,EAAE,UAAU;gBACjB,OAAO,EACL,0BAA0B,IAAI,8BAA8B,SAAS,CAAC,OAAO,gCAAgC;oBAC7G,mCAAmC,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aACvG,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type ComposeContainer } from './compose-containers.js';
|
|
2
|
+
/** How far above the default a search walks before giving up. */
|
|
3
|
+
export declare const DEFAULT_PORT_SEARCH_LIMIT = 200;
|
|
4
|
+
/** Where a port is published: the address and protocol a clash is judged on. */
|
|
5
|
+
export interface PortClaim {
|
|
6
|
+
/** The host address; `''` (and `0.0.0.0`, `::`) is every interface. */
|
|
7
|
+
hostIp: string;
|
|
8
|
+
/** `tcp`, `udp` or `sctp`. */
|
|
9
|
+
protocol: string;
|
|
10
|
+
}
|
|
11
|
+
/** Why a candidate port was passed over. */
|
|
12
|
+
export interface SkippedPort {
|
|
13
|
+
port: number;
|
|
14
|
+
/** `listener`: a process listens on it; `container`: a container is configured to publish it; `taken`: another variable of this run has it. */
|
|
15
|
+
reason: 'listener' | 'container' | 'taken';
|
|
16
|
+
/** The container that holds it, for `container`. A running one is preferred over a stopped one. */
|
|
17
|
+
holder?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The port found, and the ones passed over on the way. */
|
|
20
|
+
export interface PortPick {
|
|
21
|
+
port: number;
|
|
22
|
+
skipped: SkippedPort[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether `value` is an integer port number (1 to 65535).
|
|
26
|
+
*
|
|
27
|
+
* @param value - Any number.
|
|
28
|
+
* @returns true for a usable port.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isPort(value: number): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The first free host port at or above `preferred`.
|
|
33
|
+
*
|
|
34
|
+
* `options` carries:
|
|
35
|
+
*
|
|
36
|
+
* - `preferred`: where the search starts (the template default).
|
|
37
|
+
* - `hostIp` and `protocol`: where the port will be published.
|
|
38
|
+
* - `also`: more places the SAME port number is published (a variable that
|
|
39
|
+
* feeds a TCP and a UDP mapping); all of them must be free.
|
|
40
|
+
* - `taken`: ports already chosen for other variables of this run. Not
|
|
41
|
+
* changed; the caller adds the result.
|
|
42
|
+
* - `containers`: every container Docker knows, in any state. A container claims
|
|
43
|
+
* a port when it is configured to publish it on an address that overlaps (a
|
|
44
|
+
* wildcard clashes with every address) and the same protocol.
|
|
45
|
+
* - `probe`: says whether nothing listens on the port (true = free).
|
|
46
|
+
* - `limit`: how many ports to try (default 200); the search never goes above
|
|
47
|
+
* 65535.
|
|
48
|
+
* - `label`: names the variable in the error.
|
|
49
|
+
*
|
|
50
|
+
* @param options - The search, as above.
|
|
51
|
+
* @returns the port and the candidates passed over.
|
|
52
|
+
* @throws PreconditionError when `preferred` is not a port, or none is free.
|
|
53
|
+
*/
|
|
54
|
+
export declare function pickFreePort(options: {
|
|
55
|
+
preferred: number;
|
|
56
|
+
hostIp: string;
|
|
57
|
+
protocol: string;
|
|
58
|
+
also?: readonly PortClaim[] | undefined;
|
|
59
|
+
taken?: ReadonlySet<number> | undefined;
|
|
60
|
+
containers: readonly ComposeContainer[];
|
|
61
|
+
probe: (port: number) => Promise<boolean>;
|
|
62
|
+
limit?: number | undefined;
|
|
63
|
+
label?: string | undefined;
|
|
64
|
+
}): Promise<PortPick>;
|
|
65
|
+
/**
|
|
66
|
+
* The sentence for a pick that did not land on the default:
|
|
67
|
+
* `GREPTIME_BIND_PG_PORT=14013 (14003 is held by evopath-greptimedb-1)`.
|
|
68
|
+
*
|
|
69
|
+
* @param variable - The variable the port is for.
|
|
70
|
+
* @param pick - What `pickFreePort` returned.
|
|
71
|
+
* @param preferred - The default the search started from.
|
|
72
|
+
* @returns the text, or `undefined` when the default was free (nothing to say).
|
|
73
|
+
*/
|
|
74
|
+
export declare function describePick(variable: string, pick: PortPick, preferred: number): string | undefined;
|
|
75
|
+
/** A port variable decided by `planPortValues`. */
|
|
76
|
+
export interface PortDecision {
|
|
77
|
+
variable: string;
|
|
78
|
+
port: number;
|
|
79
|
+
/** The default the search started from. */
|
|
80
|
+
preferred: number;
|
|
81
|
+
/** What `describePick` says, or `undefined` when the default was free. */
|
|
82
|
+
message: string | undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Decides a value for every published-port variable that needs one.
|
|
86
|
+
*
|
|
87
|
+
* The variables come from the compose files (`publishedPortVariables`), so an
|
|
88
|
+
* app overlay that publishes a new port is covered without a list to keep. A
|
|
89
|
+
* variable is decided only when it is in `eligible`, has no non-blank value in
|
|
90
|
+
* `given`, is not in `exclude`, and a starting point is known (the template
|
|
91
|
+
* default, else the compose file's). Everything else is left exactly as it is.
|
|
92
|
+
* Variables are decided in the order the files publish them; each choice is
|
|
93
|
+
* `taken` for the next, and so are the ports the `given` values already use.
|
|
94
|
+
*
|
|
95
|
+
* `options` carries:
|
|
96
|
+
*
|
|
97
|
+
* - `files`: the compose files' text, in merge order.
|
|
98
|
+
* - `eligible`: the keys this run may decide (the template's, or for an update
|
|
99
|
+
* the keys it is adding).
|
|
100
|
+
* - `given`: values that stay as they are, the `.env` on disk and the
|
|
101
|
+
* operator's answers. A key with a value here is never moved.
|
|
102
|
+
* - `defaults`: the template default of each key, where the search starts.
|
|
103
|
+
* - `exclude`: keys decided elsewhere (`APP_BIND_PORT`).
|
|
104
|
+
* - `taken`: ports already in use by this run.
|
|
105
|
+
* - `containers`: every container Docker knows, or `undefined` when Docker
|
|
106
|
+
* cannot be asked (probe-only).
|
|
107
|
+
* - `probe`: says whether nothing listens on a port (default: the loopback bind
|
|
108
|
+
* probe).
|
|
109
|
+
* - `limit`: the search bound per variable.
|
|
110
|
+
*
|
|
111
|
+
* @param options - The decision inputs, as above.
|
|
112
|
+
* @returns one decision per variable decided, in file order.
|
|
113
|
+
* @throws PreconditionError when a variable has no free port within the bound.
|
|
114
|
+
*/
|
|
115
|
+
export declare function planPortValues(options: {
|
|
116
|
+
files: readonly string[];
|
|
117
|
+
eligible: ReadonlySet<string>;
|
|
118
|
+
given: ReadonlyMap<string, string>;
|
|
119
|
+
defaults: ReadonlyMap<string, string>;
|
|
120
|
+
exclude?: ReadonlySet<string> | undefined;
|
|
121
|
+
taken?: Iterable<number> | undefined;
|
|
122
|
+
containers: readonly ComposeContainer[] | undefined;
|
|
123
|
+
probe?: ((port: number) => Promise<boolean>) | undefined;
|
|
124
|
+
limit?: number | undefined;
|
|
125
|
+
}): Promise<PortDecision[]>;
|
|
126
|
+
/**
|
|
127
|
+
* The containers a pick must avoid: every one except those of the run's own
|
|
128
|
+
* compose project, which `up -d` recreates (the rule `stack-ports-free` applies).
|
|
129
|
+
*
|
|
130
|
+
* @param containers - What `listComposeContainers` returned, or `undefined`.
|
|
131
|
+
* @param project - The deployment's compose project.
|
|
132
|
+
* @returns the other projects' containers, or `undefined` when Docker could not be asked.
|
|
133
|
+
*/
|
|
134
|
+
export declare function foreignContainers(containers: readonly ComposeContainer[] | undefined, project: string): ComposeContainer[] | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* The text of the deployment's compose files, in the order compose merges them
|
|
137
|
+
* (the same list `up -d` uses, app overlays last). A file that cannot be read
|
|
138
|
+
* is an empty string: a missing checkout is the compose call's error to report.
|
|
139
|
+
*
|
|
140
|
+
* @param deployRoot - The deployment folder.
|
|
141
|
+
* @param groups - The deployment's groups.
|
|
142
|
+
* @returns one text per compose file.
|
|
143
|
+
*/
|
|
144
|
+
export declare function readComposeFileTexts(deployRoot: string, groups?: readonly string[] | undefined): string[];
|
|
145
|
+
//# sourceMappingURL=free-ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"free-ports.d.ts","sourceRoot":"","sources":["../../../src/engine/deploy/free-ports.ts"],"names":[],"mappings":"AAMA,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AA+B/E,iEAAiE;AACjE,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAK7C,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,4CAA4C;AAC5C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,+IAA+I;IAC/I,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;IAC3C,mGAAmG;IACnG,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,2DAA2D;AAC3D,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7C;AAOD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAAC;IACxC,KAAK,CAAC,EAAE,WAAW,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C,CAAC,GAAG,SAAS,CAAC;IACzD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CA0C1B;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,SAAS,gBAAgB,EAAE,GAAG,SAAS,EACnD,OAAO,EAAE,MAAM,GACd,gBAAgB,EAAE,GAAG,SAAS,CAEhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CASzG"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { PreconditionError } from '../errors.js';
|
|
4
|
+
import { isLoopbackPortFree } from './checks/types.js';
|
|
5
|
+
import { composeCwd } from './compose-command.js';
|
|
6
|
+
import { publishesPort } from './compose-containers.js';
|
|
7
|
+
import { composeFilesFor } from './compose-files.js';
|
|
8
|
+
import { publishedPortVariables } from './compose-port-variables.js';
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Free host ports for the variables the CLI writes (#1027)
|
|
11
|
+
// =============================================================================
|
|
12
|
+
//
|
|
13
|
+
// Every app the platform deploys publishes the same default host ports
|
|
14
|
+
// (`APP_BIND_PORT=3535`, `GREPTIME_BIND_PG_PORT=14003`), so the SECOND app on a
|
|
15
|
+
// server collided with the first on its telemetry port and `stack-ports-free`
|
|
16
|
+
// (#1024) stopped it, leaving the operator to hand-edit `.env`. When the CLI is
|
|
17
|
+
// about to WRITE a value for a published-port variable it now picks one that is
|
|
18
|
+
// actually free:
|
|
19
|
+
//
|
|
20
|
+
// - FREE means no container in ANY state is configured to publish it on an
|
|
21
|
+
// address that can clash (the source `stack-ports-free` uses), nothing
|
|
22
|
+
// listens on it (the same loopback bind probe as `bind-port-free`), and it
|
|
23
|
+
// is not already chosen for another variable of the same run.
|
|
24
|
+
// - THE SEARCH STARTS AT THE DEFAULT AND WALKS UP, bounded, so a lone app
|
|
25
|
+
// keeps the familiar numbers and says nothing extra.
|
|
26
|
+
// - AN EXISTING VALUE IS NEVER MOVED. Only a variable with no value yet gets a
|
|
27
|
+
// pick: an SSH tunnel or a BI tool may depend on the number, and
|
|
28
|
+
// `stack-ports-free` still reports a clash with the fix.
|
|
29
|
+
// - DOCKER UNREACHABLE (`containers` undefined) is probe-only: still picks.
|
|
30
|
+
//
|
|
31
|
+
// `stack-ports-free` stays the final guard; this module only chooses what the
|
|
32
|
+
// guard is then asked about. It reads Docker and probes sockets and writes
|
|
33
|
+
// nothing: the callers decide where a value goes.
|
|
34
|
+
// =============================================================================
|
|
35
|
+
/** How far above the default a search walks before giving up. */
|
|
36
|
+
export const DEFAULT_PORT_SEARCH_LIMIT = 200;
|
|
37
|
+
/** The highest port number. */
|
|
38
|
+
const MAX_PORT = 65535;
|
|
39
|
+
/**
|
|
40
|
+
* Whether `value` is an integer port number (1 to 65535).
|
|
41
|
+
*
|
|
42
|
+
* @param value - Any number.
|
|
43
|
+
* @returns true for a usable port.
|
|
44
|
+
*/
|
|
45
|
+
export function isPort(value) {
|
|
46
|
+
return Number.isInteger(value) && value >= 1 && value <= MAX_PORT;
|
|
47
|
+
}
|
|
48
|
+
/** Whether the listener probe says something about this claim: it binds TCP on the loopback. */
|
|
49
|
+
function probeable(claim) {
|
|
50
|
+
return claim.protocol === 'tcp' && ['', '0.0.0.0', '::', '[::]', '127.0.0.1'].includes(claim.hostIp);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The first free host port at or above `preferred`.
|
|
54
|
+
*
|
|
55
|
+
* `options` carries:
|
|
56
|
+
*
|
|
57
|
+
* - `preferred`: where the search starts (the template default).
|
|
58
|
+
* - `hostIp` and `protocol`: where the port will be published.
|
|
59
|
+
* - `also`: more places the SAME port number is published (a variable that
|
|
60
|
+
* feeds a TCP and a UDP mapping); all of them must be free.
|
|
61
|
+
* - `taken`: ports already chosen for other variables of this run. Not
|
|
62
|
+
* changed; the caller adds the result.
|
|
63
|
+
* - `containers`: every container Docker knows, in any state. A container claims
|
|
64
|
+
* a port when it is configured to publish it on an address that overlaps (a
|
|
65
|
+
* wildcard clashes with every address) and the same protocol.
|
|
66
|
+
* - `probe`: says whether nothing listens on the port (true = free).
|
|
67
|
+
* - `limit`: how many ports to try (default 200); the search never goes above
|
|
68
|
+
* 65535.
|
|
69
|
+
* - `label`: names the variable in the error.
|
|
70
|
+
*
|
|
71
|
+
* @param options - The search, as above.
|
|
72
|
+
* @returns the port and the candidates passed over.
|
|
73
|
+
* @throws PreconditionError when `preferred` is not a port, or none is free.
|
|
74
|
+
*/
|
|
75
|
+
export async function pickFreePort(options) {
|
|
76
|
+
const { preferred, taken = new Set(), containers, probe, limit = DEFAULT_PORT_SEARCH_LIMIT } = options;
|
|
77
|
+
const label = options.label ?? 'a host port';
|
|
78
|
+
const claims = [{ hostIp: options.hostIp, protocol: options.protocol }, ...(options.also ?? [])];
|
|
79
|
+
if (!isPort(preferred)) {
|
|
80
|
+
throw new PreconditionError(`Cannot pick a free port for ${label}: ${String(preferred)} is not a port number.`);
|
|
81
|
+
}
|
|
82
|
+
const last = Math.min(MAX_PORT, preferred + Math.max(1, limit) - 1);
|
|
83
|
+
const skipped = [];
|
|
84
|
+
for (let port = preferred; port <= last; port += 1) {
|
|
85
|
+
if (taken.has(port)) {
|
|
86
|
+
skipped.push({ port, reason: 'taken' });
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const claimants = containers.filter((container) => claims.some((claim) => publishesPort(container, port, claim)));
|
|
90
|
+
if (claimants.length > 0) {
|
|
91
|
+
const holder = claimants.find((container) => container.running) ?? claimants[0];
|
|
92
|
+
skipped.push({ port, reason: 'container', holder: holder?.name });
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Probed once per port, and only where the probe is honest: it binds TCP on
|
|
96
|
+
// the loopback, which sees a listener on 127.0.0.1 or on every interface.
|
|
97
|
+
if (claims.some(probeable) && !(await probe(port))) {
|
|
98
|
+
skipped.push({ port, reason: 'listener' });
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
return { port, skipped };
|
|
102
|
+
}
|
|
103
|
+
throw new PreconditionError(`No free host port for ${label} from ${preferred} to ${last} (${skipped.length} tried). ` +
|
|
104
|
+
`Free one of them, or set ${options.label ?? 'the variable'} to a free port in the environment file by hand.`);
|
|
105
|
+
}
|
|
106
|
+
/** How many skipped candidates a message spells out. */
|
|
107
|
+
const MAX_PHRASES = 3;
|
|
108
|
+
/**
|
|
109
|
+
* The sentence for a pick that did not land on the default:
|
|
110
|
+
* `GREPTIME_BIND_PG_PORT=14013 (14003 is held by evopath-greptimedb-1)`.
|
|
111
|
+
*
|
|
112
|
+
* @param variable - The variable the port is for.
|
|
113
|
+
* @param pick - What `pickFreePort` returned.
|
|
114
|
+
* @param preferred - The default the search started from.
|
|
115
|
+
* @returns the text, or `undefined` when the default was free (nothing to say).
|
|
116
|
+
*/
|
|
117
|
+
export function describePick(variable, pick, preferred) {
|
|
118
|
+
if (pick.port === preferred && pick.skipped.length === 0)
|
|
119
|
+
return undefined;
|
|
120
|
+
const phrase = (entry) => entry.reason === 'container'
|
|
121
|
+
? `${entry.port} is held by ${entry.holder ?? 'another container'}`
|
|
122
|
+
: entry.reason === 'listener'
|
|
123
|
+
? `${entry.port} has a listener`
|
|
124
|
+
: `${entry.port} is used by another variable of this run`;
|
|
125
|
+
const shown = pick.skipped.slice(0, MAX_PHRASES).map(phrase);
|
|
126
|
+
if (pick.skipped.length > MAX_PHRASES)
|
|
127
|
+
shown.push(`${pick.skipped.length - MAX_PHRASES} more in use`);
|
|
128
|
+
return `${variable}=${pick.port} (${shown.join(', ')})`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Decides a value for every published-port variable that needs one.
|
|
132
|
+
*
|
|
133
|
+
* The variables come from the compose files (`publishedPortVariables`), so an
|
|
134
|
+
* app overlay that publishes a new port is covered without a list to keep. A
|
|
135
|
+
* variable is decided only when it is in `eligible`, has no non-blank value in
|
|
136
|
+
* `given`, is not in `exclude`, and a starting point is known (the template
|
|
137
|
+
* default, else the compose file's). Everything else is left exactly as it is.
|
|
138
|
+
* Variables are decided in the order the files publish them; each choice is
|
|
139
|
+
* `taken` for the next, and so are the ports the `given` values already use.
|
|
140
|
+
*
|
|
141
|
+
* `options` carries:
|
|
142
|
+
*
|
|
143
|
+
* - `files`: the compose files' text, in merge order.
|
|
144
|
+
* - `eligible`: the keys this run may decide (the template's, or for an update
|
|
145
|
+
* the keys it is adding).
|
|
146
|
+
* - `given`: values that stay as they are, the `.env` on disk and the
|
|
147
|
+
* operator's answers. A key with a value here is never moved.
|
|
148
|
+
* - `defaults`: the template default of each key, where the search starts.
|
|
149
|
+
* - `exclude`: keys decided elsewhere (`APP_BIND_PORT`).
|
|
150
|
+
* - `taken`: ports already in use by this run.
|
|
151
|
+
* - `containers`: every container Docker knows, or `undefined` when Docker
|
|
152
|
+
* cannot be asked (probe-only).
|
|
153
|
+
* - `probe`: says whether nothing listens on a port (default: the loopback bind
|
|
154
|
+
* probe).
|
|
155
|
+
* - `limit`: the search bound per variable.
|
|
156
|
+
*
|
|
157
|
+
* @param options - The decision inputs, as above.
|
|
158
|
+
* @returns one decision per variable decided, in file order.
|
|
159
|
+
* @throws PreconditionError when a variable has no free port within the bound.
|
|
160
|
+
*/
|
|
161
|
+
export async function planPortValues(options) {
|
|
162
|
+
const { given, defaults, eligible, exclude = new Set() } = options;
|
|
163
|
+
const probe = options.probe ?? isLoopbackPortFree;
|
|
164
|
+
const containers = options.containers ?? [];
|
|
165
|
+
const variables = publishedPortVariables({ files: options.files, env: new Map([...defaults, ...given]) });
|
|
166
|
+
// What the run already uses: the ports it was told about, and every value
|
|
167
|
+
// another published-port variable keeps.
|
|
168
|
+
const taken = new Set(options.taken ?? []);
|
|
169
|
+
for (const { variable } of variables) {
|
|
170
|
+
const value = Number(given.get(variable));
|
|
171
|
+
if (given.get(variable) !== undefined && isPort(value))
|
|
172
|
+
taken.add(value);
|
|
173
|
+
}
|
|
174
|
+
const decisions = [];
|
|
175
|
+
for (const candidate of variables) {
|
|
176
|
+
const { variable } = candidate;
|
|
177
|
+
if (!eligible.has(variable) || exclude.has(variable))
|
|
178
|
+
continue;
|
|
179
|
+
if ((given.get(variable) ?? '') !== '')
|
|
180
|
+
continue;
|
|
181
|
+
const fromTemplate = Number(defaults.get(variable));
|
|
182
|
+
const preferred = isPort(fromTemplate) ? fromTemplate : candidate.defaultPort;
|
|
183
|
+
if (preferred === undefined)
|
|
184
|
+
continue;
|
|
185
|
+
const [first, ...rest] = candidate.claims;
|
|
186
|
+
if (first === undefined)
|
|
187
|
+
continue;
|
|
188
|
+
const pick = await pickFreePort({
|
|
189
|
+
preferred,
|
|
190
|
+
hostIp: first.hostIp,
|
|
191
|
+
protocol: first.protocol,
|
|
192
|
+
also: rest,
|
|
193
|
+
taken,
|
|
194
|
+
containers,
|
|
195
|
+
probe,
|
|
196
|
+
limit: options.limit,
|
|
197
|
+
label: variable,
|
|
198
|
+
});
|
|
199
|
+
taken.add(pick.port);
|
|
200
|
+
decisions.push({ variable, port: pick.port, preferred, message: describePick(variable, pick, preferred) });
|
|
201
|
+
}
|
|
202
|
+
return decisions;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The containers a pick must avoid: every one except those of the run's own
|
|
206
|
+
* compose project, which `up -d` recreates (the rule `stack-ports-free` applies).
|
|
207
|
+
*
|
|
208
|
+
* @param containers - What `listComposeContainers` returned, or `undefined`.
|
|
209
|
+
* @param project - The deployment's compose project.
|
|
210
|
+
* @returns the other projects' containers, or `undefined` when Docker could not be asked.
|
|
211
|
+
*/
|
|
212
|
+
export function foreignContainers(containers, project) {
|
|
213
|
+
return containers?.filter((container) => container.project !== project);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The text of the deployment's compose files, in the order compose merges them
|
|
217
|
+
* (the same list `up -d` uses, app overlays last). A file that cannot be read
|
|
218
|
+
* is an empty string: a missing checkout is the compose call's error to report.
|
|
219
|
+
*
|
|
220
|
+
* @param deployRoot - The deployment folder.
|
|
221
|
+
* @param groups - The deployment's groups.
|
|
222
|
+
* @returns one text per compose file.
|
|
223
|
+
*/
|
|
224
|
+
export function readComposeFileTexts(deployRoot, groups) {
|
|
225
|
+
const composeDir = composeCwd(deployRoot);
|
|
226
|
+
return composeFilesFor(groups, composeDir).map((file) => {
|
|
227
|
+
try {
|
|
228
|
+
return readFileSync(join(composeDir, file), 'utf8');
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return '';
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=free-ports.js.map
|