@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
|
@@ -15,19 +15,28 @@ const COMPOSE_WORKING_DIR_LABEL = 'com.docker.compose.project.working_dir';
|
|
|
15
15
|
/** Short by design: a wedged Docker socket must cost seconds, not the command. */
|
|
16
16
|
const DOCKER_QUERY_TIMEOUT_MS = 10_000;
|
|
17
17
|
/**
|
|
18
|
-
* One line per container: name, running state,
|
|
18
|
+
* One line per container: name, running state, host port bindings, compose
|
|
19
19
|
* project, then compose working directory.
|
|
20
20
|
*
|
|
21
|
+
* The bindings are `{{json .HostConfig.PortBindings}}`, one compact JSON object
|
|
22
|
+
* (`{"4003/tcp":[{"HostIp":"127.0.0.1","HostPort":"14003"}]}`, `null` for none).
|
|
23
|
+
* `json` is the template function the Docker CLI ships, so the field NAMES are
|
|
24
|
+
* the API's JSON ones whichever way the CLI renders (typed, or the raw-JSON
|
|
25
|
+
* fallback it takes when a typed field is missing): a bare `.HostIp` would
|
|
26
|
+
* fail on a CLI whose typed struct calls it `HostIP`, and a failed inspect is a
|
|
27
|
+
* skipped check. The JSON holds no `|` and no newline. A wildcard publish has an
|
|
28
|
+
* empty `HostIp`.
|
|
29
|
+
*
|
|
21
30
|
* `{{if .Config.Labels}}` guards a container created without any labels, whose
|
|
22
31
|
* `Labels` is null rather than an empty map (`index` on nil renders
|
|
23
32
|
* `<no value>` into the line otherwise); the separators sit outside the guards
|
|
24
33
|
* so every line has all five fields. `PortBindings` is the CONFIGURED publish,
|
|
25
|
-
* present on a stopped or merely created container too
|
|
26
|
-
*
|
|
27
|
-
*
|
|
34
|
+
* present on a stopped or merely created container too. The working directory
|
|
35
|
+
* comes last so a path containing the separator survives; none of the fields
|
|
36
|
+
* before it can contain one.
|
|
28
37
|
*/
|
|
29
38
|
const INSPECT_FORMAT = '{{.Name}}|{{.State.Running}}|' +
|
|
30
|
-
'{{
|
|
39
|
+
'{{json .HostConfig.PortBindings}}|' +
|
|
31
40
|
`{{if .Config.Labels}}{{index .Config.Labels "${COMPOSE_PROJECT_LABEL}"}}{{end}}|` +
|
|
32
41
|
`{{if .Config.Labels}}{{index .Config.Labels "${COMPOSE_WORKING_DIR_LABEL}"}}{{end}}`;
|
|
33
42
|
/**
|
|
@@ -56,21 +65,76 @@ export function isPathUnder(path, root) {
|
|
|
56
65
|
export function freshComposeProject(deployRoot) {
|
|
57
66
|
return basename(deployRoot);
|
|
58
67
|
}
|
|
68
|
+
/** Whether two host addresses can be bound at once: a wildcard (`''`, `0.0.0.0`, `::`) overlaps every address. */
|
|
69
|
+
export function hostIpsOverlap(left, right) {
|
|
70
|
+
const wildcard = (ip) => ip === '' || ip === '0.0.0.0' || ip === '::' || ip === '[::]';
|
|
71
|
+
return wildcard(left) || wildcard(right) || left === right;
|
|
72
|
+
}
|
|
73
|
+
/** Whether `port` is `entry` (`3535`) or inside it (`8000-8010`). */
|
|
74
|
+
function entryCovers(entry, port) {
|
|
75
|
+
const [first = '', last = first] = entry.split('-');
|
|
76
|
+
const low = Number(first);
|
|
77
|
+
const high = Number(last);
|
|
78
|
+
return Number.isInteger(low) && Number.isInteger(high) && low <= port && port <= high;
|
|
79
|
+
}
|
|
59
80
|
/**
|
|
60
81
|
* Whether `container` is configured to publish host port `port`. An empty
|
|
61
82
|
* `HostPort` (Docker picks one) is no claim; a range claims every port in it.
|
|
62
83
|
*
|
|
84
|
+
* Without `match` any address and protocol counts, which is what the bind-port
|
|
85
|
+
* checks want (a promise of port 3535 on ANY address is a promise of 3535). With
|
|
86
|
+
* `match.hostIp` only a binding whose address can be bound at the same time
|
|
87
|
+
* counts (`127.0.0.1` against `0.0.0.0` overlaps, against `127.0.0.2` does not);
|
|
88
|
+
* with `match.protocol` only that protocol counts (a binding that recorded none
|
|
89
|
+
* counts for every protocol).
|
|
90
|
+
*
|
|
63
91
|
* @param container - The container.
|
|
64
92
|
* @param port - The host port.
|
|
93
|
+
* @param match - Narrow the claim to an address and/or protocol.
|
|
65
94
|
* @returns true when the container publishes it.
|
|
66
95
|
*/
|
|
67
|
-
export function publishesPort(container, port) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
export function publishesPort(container, port, match) {
|
|
97
|
+
if (match === undefined || container.bindings === undefined) {
|
|
98
|
+
return container.hostPorts.some((entry) => entryCovers(entry, port));
|
|
99
|
+
}
|
|
100
|
+
return container.bindings.some((binding) => entryCovers(binding.hostPort, port) &&
|
|
101
|
+
(match.hostIp === undefined || hostIpsOverlap(binding.hostIp, match.hostIp)) &&
|
|
102
|
+
(match.protocol === undefined || binding.protocol === '' || binding.protocol === match.protocol));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Reads the third field of an inspect line: the JSON of `PortBindings`, keyed
|
|
106
|
+
* by `<containerPort>/<protocol>`. An empty `HostPort` is Docker picking one: no
|
|
107
|
+
* claim. Anything unreadable claims nothing (an unreadable line is not a reason
|
|
108
|
+
* to fail an update).
|
|
109
|
+
*/
|
|
110
|
+
function parseBindings(field) {
|
|
111
|
+
const text = field.trim();
|
|
112
|
+
if (text === '' || text === 'null')
|
|
113
|
+
return [];
|
|
114
|
+
let parsed;
|
|
115
|
+
try {
|
|
116
|
+
parsed = JSON.parse(text);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
122
|
+
return [];
|
|
123
|
+
const bindings = [];
|
|
124
|
+
for (const [containerPort, list] of Object.entries(parsed)) {
|
|
125
|
+
if (!Array.isArray(list))
|
|
126
|
+
continue;
|
|
127
|
+
const slash = containerPort.indexOf('/');
|
|
128
|
+
const protocol = slash === -1 ? '' : containerPort.slice(slash + 1).trim().toLowerCase();
|
|
129
|
+
for (const entry of list) {
|
|
130
|
+
const binding = entry;
|
|
131
|
+
const hostPort = typeof binding?.HostPort === 'string' ? binding.HostPort.trim() : '';
|
|
132
|
+
if (hostPort === '')
|
|
133
|
+
continue;
|
|
134
|
+
bindings.push({ hostIp: typeof binding?.HostIp === 'string' ? binding.HostIp.trim() : '', hostPort, protocol });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return bindings;
|
|
74
138
|
}
|
|
75
139
|
/**
|
|
76
140
|
* Every container Docker knows, in any state, with its compose labels and the
|
|
@@ -108,10 +172,12 @@ export async function listComposeContainers(run) {
|
|
|
108
172
|
if (fields.length < 4)
|
|
109
173
|
continue;
|
|
110
174
|
const [name = '', running = '', ports = '', project = ''] = fields;
|
|
175
|
+
const bindings = parseBindings(ports);
|
|
111
176
|
containers.push({
|
|
112
177
|
name: name.replace(/^\//, '').trim(),
|
|
113
178
|
running: running.trim() === 'true',
|
|
114
|
-
hostPorts:
|
|
179
|
+
hostPorts: bindings.map((binding) => binding.hostPort),
|
|
180
|
+
bindings,
|
|
115
181
|
project: project.trim(),
|
|
116
182
|
workingDir: rest.trim(),
|
|
117
183
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-containers.js","sourceRoot":"","sources":["../../../src/engine/deploy/compose-containers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEzE,gFAAgF;AAChF,2EAA2E;AAC3E,gFAAgF;AAChF,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,2EAA2E;AAC3E,kEAAkE;AAClE,gFAAgF;AAEhF,gEAAgE;AAChE,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAE3D,2DAA2D;AAC3D,MAAM,yBAAyB,GAAG,wCAAwC,CA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AC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type PublishedPort } from './compose-ports.js';
|
|
2
|
+
/**
|
|
3
|
+
* The environment variable that sets the host port compose reported, or
|
|
4
|
+
* `undefined` when the port is a literal in the files (or cannot be traced).
|
|
5
|
+
*
|
|
6
|
+
* @param options - The port, the compose files' text in the order compose
|
|
7
|
+
* merges them, and the environment compose interpolates with (the
|
|
8
|
+
* deployment's `.env`, then the process environment).
|
|
9
|
+
* @returns the variable name, such as `GREPTIME_BIND_PG_PORT`.
|
|
10
|
+
* @stability experimental
|
|
11
|
+
*/
|
|
12
|
+
export declare function portVariableFor(options: {
|
|
13
|
+
port: PublishedPort;
|
|
14
|
+
/** The text of each compose file, in merge order. */
|
|
15
|
+
files: readonly string[];
|
|
16
|
+
env: ReadonlyMap<string, string>;
|
|
17
|
+
}): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* One environment variable that sets a published host port, with every place
|
|
20
|
+
* the stack publishes it.
|
|
21
|
+
*
|
|
22
|
+
* @stability experimental
|
|
23
|
+
*/
|
|
24
|
+
export interface PortVariable {
|
|
25
|
+
/** The variable name, such as `GREPTIME_BIND_PG_PORT`. */
|
|
26
|
+
variable: string;
|
|
27
|
+
/** Each short-syntax entry that publishes the variable's port, in file order. */
|
|
28
|
+
claims: Array<{
|
|
29
|
+
service: string;
|
|
30
|
+
hostIp: string;
|
|
31
|
+
protocol: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** The compose file's own default (`${VAR:-14003}`), when it names one. */
|
|
34
|
+
defaultPort: number | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Every environment variable that sets ONE published host port, derived from
|
|
38
|
+
* the compose files the run uses (the same raw scan as `portVariableFor`, in the
|
|
39
|
+
* other direction: from the files to the variables, with no compose render
|
|
40
|
+
* needed, so it works before the `.env` is complete).
|
|
41
|
+
*
|
|
42
|
+
* Only a published side that is exactly one variable counts. A literal port, a
|
|
43
|
+
* range, or a token that mixes text and a variable (`${A}0`) has no single
|
|
44
|
+
* variable an installer could pick a value for, and is left to the
|
|
45
|
+
* `stack-ports-free` check. A variable that publishes the same port twice (TCP
|
|
46
|
+
* and UDP) is one entry with two claims.
|
|
47
|
+
*
|
|
48
|
+
* @param options - The compose files' text in merge order, and the environment
|
|
49
|
+
* used to interpolate the host address (`${BIND_ADDRESS:-127.0.0.1}`).
|
|
50
|
+
* @returns the variables, by the order in which the files first list their services.
|
|
51
|
+
* @stability experimental
|
|
52
|
+
*/
|
|
53
|
+
export declare function publishedPortVariables(options: {
|
|
54
|
+
/** The text of each compose file, in merge order. */
|
|
55
|
+
files: readonly string[];
|
|
56
|
+
env: ReadonlyMap<string, string>;
|
|
57
|
+
}): PortVariable[];
|
|
58
|
+
//# sourceMappingURL=compose-port-variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-port-variables.d.ts","sourceRoot":"","sources":["../../../src/engine/deploy/compose-port-variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkJvE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,IAAI,EAAE,aAAa,CAAC;IACpB,qDAAqD;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,GAAG,MAAM,GAAG,SAAS,CAerB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,2EAA2E;IAC3E,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAKD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,qDAAqD;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,GAAG,YAAY,EAAE,CAuBjB"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { splitPortSpec } from './compose-ports.js';
|
|
2
|
+
/** The `${NAME}` / `${NAME:-default}` / `$NAME` forms compose interpolates. */
|
|
3
|
+
const INTERPOLATION = /\$\$|\$\{([A-Za-z_][A-Za-z0-9_]*)(?:(:?)([-?+])([^}]*))?\}|\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
4
|
+
/**
|
|
5
|
+
* Compose's interpolation of one token against an environment. `${V:-d}` takes
|
|
6
|
+
* `d` when V is unset OR empty, `${V-d}` only when unset, `${V:?m}` and
|
|
7
|
+
* `${V?m}` keep the value (the failure is compose's to report), `${V:+a}`
|
|
8
|
+
* yields `a` when V is set and non-empty.
|
|
9
|
+
*/
|
|
10
|
+
function interpolate(token, env) {
|
|
11
|
+
return token.replace(INTERPOLATION, (match, braced, colon, operator, argument, bare) => {
|
|
12
|
+
if (match === '$$')
|
|
13
|
+
return '$';
|
|
14
|
+
const name = braced ?? bare ?? '';
|
|
15
|
+
const value = env.get(name);
|
|
16
|
+
const unset = value === undefined || (colon === ':' && value === '');
|
|
17
|
+
if (operator === '-')
|
|
18
|
+
return unset ? (argument ?? '') : (value ?? '');
|
|
19
|
+
if (operator === '+')
|
|
20
|
+
return unset ? '' : (argument ?? '');
|
|
21
|
+
return value ?? '';
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** The first variable a token reads, if any. */
|
|
25
|
+
function variableOf(token) {
|
|
26
|
+
for (const match of token.matchAll(INTERPOLATION)) {
|
|
27
|
+
const name = match[1] ?? match[5];
|
|
28
|
+
if (name !== undefined)
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
/** The leading whitespace width of a line. */
|
|
34
|
+
function indentOf(line) {
|
|
35
|
+
return line.length - line.trimStart().length;
|
|
36
|
+
}
|
|
37
|
+
/** A list item's value: the quoted string, else the text up to a trailing comment. */
|
|
38
|
+
function itemValue(line) {
|
|
39
|
+
const body = line.trimStart();
|
|
40
|
+
if (!body.startsWith('-'))
|
|
41
|
+
return undefined;
|
|
42
|
+
const rest = body.slice(1).trim();
|
|
43
|
+
const quoted = /^(["'])(.*?)\1/.exec(rest);
|
|
44
|
+
if (quoted !== null)
|
|
45
|
+
return quoted[2] ?? '';
|
|
46
|
+
return rest.replace(/\s+#.*$/, '').trim();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The raw `ports:` entries of every service after applying every file in order:
|
|
50
|
+
* `ports: !override` / `!reset` drops what the earlier files listed (as compose
|
|
51
|
+
* does), a plain `ports:` adds to it. Services appear in the order they are
|
|
52
|
+
* first seen with a `ports:` key.
|
|
53
|
+
*/
|
|
54
|
+
function rawPortsByService(texts) {
|
|
55
|
+
const byService = new Map();
|
|
56
|
+
for (const text of texts) {
|
|
57
|
+
let inServices = false;
|
|
58
|
+
let serviceIndent = -1;
|
|
59
|
+
let current;
|
|
60
|
+
let entries; // the list being filled while inside a `ports:` list
|
|
61
|
+
let portsIndent = -1; // >= 0 while inside a service's `ports:` list
|
|
62
|
+
for (const line of text.split(/\r?\n/)) {
|
|
63
|
+
const trimmed = line.trim();
|
|
64
|
+
if (trimmed === '' || trimmed.startsWith('#'))
|
|
65
|
+
continue;
|
|
66
|
+
const indent = indentOf(line);
|
|
67
|
+
if (indent === 0) {
|
|
68
|
+
inServices = /^services:\s*(#.*)?$/.test(trimmed);
|
|
69
|
+
current = undefined;
|
|
70
|
+
portsIndent = -1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!inServices)
|
|
74
|
+
continue;
|
|
75
|
+
// Leaving a `ports:` list: the first line that is not deeper than its key
|
|
76
|
+
// (an item may sit at the key's own indent, which YAML allows).
|
|
77
|
+
if (portsIndent >= 0 && (indent < portsIndent || (indent === portsIndent && !trimmed.startsWith('-')))) {
|
|
78
|
+
portsIndent = -1;
|
|
79
|
+
}
|
|
80
|
+
if (portsIndent >= 0) {
|
|
81
|
+
const value = itemValue(line);
|
|
82
|
+
const split = value === undefined ? undefined : splitPortSpec(value);
|
|
83
|
+
if (split !== undefined)
|
|
84
|
+
entries?.push(split);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// The first key under `services:` fixes the indent of the service names.
|
|
88
|
+
if (serviceIndent === -1)
|
|
89
|
+
serviceIndent = indent;
|
|
90
|
+
if (indent === serviceIndent) {
|
|
91
|
+
current = /^([A-Za-z0-9_.-]+):/.exec(trimmed)?.[1];
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (current === undefined)
|
|
95
|
+
continue;
|
|
96
|
+
const ports = /^ports:\s*(!override|!reset)?\s*(\[\s*\])?\s*(#.*)?$/.exec(trimmed);
|
|
97
|
+
if (ports === null)
|
|
98
|
+
continue;
|
|
99
|
+
if (ports[1] !== undefined || !byService.has(current))
|
|
100
|
+
byService.set(current, []);
|
|
101
|
+
entries = byService.get(current);
|
|
102
|
+
if (ports[2] === undefined)
|
|
103
|
+
portsIndent = indent;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return byService;
|
|
107
|
+
}
|
|
108
|
+
/** The raw `ports:` entries of one service after applying every file in order. */
|
|
109
|
+
function rawPortsOf(service, texts) {
|
|
110
|
+
return rawPortsByService(texts).get(service) ?? [];
|
|
111
|
+
}
|
|
112
|
+
/** Whether an interpolated published token (`14003`, `8000-8010`) covers `port`. */
|
|
113
|
+
function covers(published, port) {
|
|
114
|
+
const [first = '', last = first] = published.trim().split('-');
|
|
115
|
+
const low = Number(first);
|
|
116
|
+
const high = Number(last);
|
|
117
|
+
return Number.isInteger(low) && Number.isInteger(high) && low <= port && port <= high;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The environment variable that sets the host port compose reported, or
|
|
121
|
+
* `undefined` when the port is a literal in the files (or cannot be traced).
|
|
122
|
+
*
|
|
123
|
+
* @param options - The port, the compose files' text in the order compose
|
|
124
|
+
* merges them, and the environment compose interpolates with (the
|
|
125
|
+
* deployment's `.env`, then the process environment).
|
|
126
|
+
* @returns the variable name, such as `GREPTIME_BIND_PG_PORT`.
|
|
127
|
+
* @stability experimental
|
|
128
|
+
*/
|
|
129
|
+
export function portVariableFor(options) {
|
|
130
|
+
const { port, files, env } = options;
|
|
131
|
+
const wildcard = (ip) => ip === '' || ip === '0.0.0.0' || ip === '::';
|
|
132
|
+
const matching = rawPortsOf(port.service, files).filter((entry) => {
|
|
133
|
+
const hostIp = interpolate(entry.hostIp, env).replace(/^\[|\]$/g, '');
|
|
134
|
+
return (covers(interpolate(entry.published, env), port.port) &&
|
|
135
|
+
entry.protocol === port.protocol &&
|
|
136
|
+
(hostIp === port.hostIp || (wildcard(hostIp) && wildcard(port.hostIp))));
|
|
137
|
+
});
|
|
138
|
+
// The last file wins, so the last matching entry names the variable.
|
|
139
|
+
const last = matching[matching.length - 1];
|
|
140
|
+
return last === undefined ? undefined : variableOf(last.published);
|
|
141
|
+
}
|
|
142
|
+
// A published token that is exactly one variable: ${NAME}, ${NAME:-14003}, ${NAME-14003}, ${NAME:?message} or $NAME.
|
|
143
|
+
const WHOLE_VARIABLE = /^(?:\$\{([A-Za-z_][A-Za-z0-9_]*)(?:(:?)([-?])([^}]*))?\}|\$([A-Za-z_][A-Za-z0-9_]*))$/;
|
|
144
|
+
/**
|
|
145
|
+
* Every environment variable that sets ONE published host port, derived from
|
|
146
|
+
* the compose files the run uses (the same raw scan as `portVariableFor`, in the
|
|
147
|
+
* other direction: from the files to the variables, with no compose render
|
|
148
|
+
* needed, so it works before the `.env` is complete).
|
|
149
|
+
*
|
|
150
|
+
* Only a published side that is exactly one variable counts. A literal port, a
|
|
151
|
+
* range, or a token that mixes text and a variable (`${A}0`) has no single
|
|
152
|
+
* variable an installer could pick a value for, and is left to the
|
|
153
|
+
* `stack-ports-free` check. A variable that publishes the same port twice (TCP
|
|
154
|
+
* and UDP) is one entry with two claims.
|
|
155
|
+
*
|
|
156
|
+
* @param options - The compose files' text in merge order, and the environment
|
|
157
|
+
* used to interpolate the host address (`${BIND_ADDRESS:-127.0.0.1}`).
|
|
158
|
+
* @returns the variables, by the order in which the files first list their services.
|
|
159
|
+
* @stability experimental
|
|
160
|
+
*/
|
|
161
|
+
export function publishedPortVariables(options) {
|
|
162
|
+
const found = new Map();
|
|
163
|
+
for (const [service, entries] of rawPortsByService(options.files)) {
|
|
164
|
+
for (const entry of entries) {
|
|
165
|
+
const match = WHOLE_VARIABLE.exec(entry.published.trim());
|
|
166
|
+
const variable = match?.[1] ?? match?.[5];
|
|
167
|
+
if (match === null || variable === undefined)
|
|
168
|
+
continue;
|
|
169
|
+
const argument = (match[4] ?? '').trim();
|
|
170
|
+
const defaultPort = match[3] === '-' && /^[0-9]+$/.test(argument) ? Number(argument) : undefined;
|
|
171
|
+
const hostIp = interpolate(entry.hostIp, options.env).replace(/^\[|\]$/g, '');
|
|
172
|
+
const known = found.get(variable);
|
|
173
|
+
if (known === undefined) {
|
|
174
|
+
found.set(variable, { variable, claims: [{ service, hostIp, protocol: entry.protocol }], defaultPort });
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
known.claims.push({ service, hostIp, protocol: entry.protocol });
|
|
178
|
+
known.defaultPort ??= defaultPort;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return [...found.values()];
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=compose-port-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-port-vari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"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ComposeProjectCommandRunner } from './compose-containers.js';
|
|
2
|
+
/**
|
|
3
|
+
* One host port the composed stack publishes.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface PublishedPort {
|
|
8
|
+
/** The compose service that publishes it. */
|
|
9
|
+
service: string;
|
|
10
|
+
/** The host address; `''` when none was given, which is every interface. */
|
|
11
|
+
hostIp: string;
|
|
12
|
+
/** The host port. A published range is one entry per port. */
|
|
13
|
+
port: number;
|
|
14
|
+
/** `tcp`, `udp` or `sctp`. */
|
|
15
|
+
protocol: string;
|
|
16
|
+
}
|
|
17
|
+
/** `docker compose config --format json` output that is not the stack this module can read. */
|
|
18
|
+
export declare class ComposeConfigError extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Splits a short-syntax port spec (`127.0.0.1:14003:4003/tcp`) at the colons
|
|
23
|
+
* that are not inside `${...}` or an IPv6 `[...]`, and returns the host side.
|
|
24
|
+
*
|
|
25
|
+
* Shared by the rendered-config fallback and the raw-file variable scan, so
|
|
26
|
+
* both read one grammar.
|
|
27
|
+
*
|
|
28
|
+
* @param spec - The spec, quotes and whitespace already removed.
|
|
29
|
+
* @returns the host address (`''` when none), the published token (which may
|
|
30
|
+
* still hold `${VAR:-default}`), and the protocol; `undefined` for a spec
|
|
31
|
+
* with no published side (`"80"`, a container-only port).
|
|
32
|
+
*/
|
|
33
|
+
export declare function splitPortSpec(spec: string): {
|
|
34
|
+
hostIp: string;
|
|
35
|
+
published: string;
|
|
36
|
+
protocol: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Every host port a rendered compose project publishes, from the JSON of
|
|
40
|
+
* `docker compose config --format json`.
|
|
41
|
+
*
|
|
42
|
+
* `published` is a string for compose v2 and a number elsewhere, and a range
|
|
43
|
+
* (`"8000-8002"`) is one entry per port; no `published` (or `0`) is a port
|
|
44
|
+
* Docker picks and is no claim; no `host_ip` is every interface; the protocol
|
|
45
|
+
* defaults to `tcp`. A service that lists a short-syntax string instead of the
|
|
46
|
+
* long form is read too. A range wider than 1024 ports is cut at 1024.
|
|
47
|
+
*
|
|
48
|
+
* @param json - The command's stdout.
|
|
49
|
+
* @returns the ports, deduplicated, in service order.
|
|
50
|
+
* @throws ComposeConfigError when the text is not a compose project. The
|
|
51
|
+
* message never quotes the text: it holds the stack's secrets.
|
|
52
|
+
* @stability experimental
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseComposePorts(json: string): PublishedPort[];
|
|
55
|
+
/**
|
|
56
|
+
* What asking compose for the stack's ports came to.
|
|
57
|
+
*
|
|
58
|
+
* @stability experimental
|
|
59
|
+
*/
|
|
60
|
+
export type StackPortsResult =
|
|
61
|
+
/** The ports the stack publishes. */
|
|
62
|
+
{
|
|
63
|
+
status: 'ok';
|
|
64
|
+
ports: PublishedPort[];
|
|
65
|
+
}
|
|
66
|
+
/** Docker could not be reached at all (no `docker`, no daemon, no socket access): nothing was learned. */
|
|
67
|
+
| {
|
|
68
|
+
status: 'docker-unreachable';
|
|
69
|
+
message: string;
|
|
70
|
+
}
|
|
71
|
+
/** Compose refused to render the stack (a missing required variable, an invalid file) or printed something unreadable. */
|
|
72
|
+
| {
|
|
73
|
+
status: 'render-failed';
|
|
74
|
+
message: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Renders the deployment's compose project exactly as `up -d` would and lists
|
|
78
|
+
* the host ports it publishes, with `docker compose config --format json` run
|
|
79
|
+
* under the run's project and files, in the checkout's compose directory. That
|
|
80
|
+
* directory is where compose finds the deployment's `.env`: no `--env-file` is
|
|
81
|
+
* passed by any `up`, so none is passed here, and the process environment
|
|
82
|
+
* overrides the file the same way. Never runs anything that changes a container.
|
|
83
|
+
*
|
|
84
|
+
* @param options - The command seam, the deployment and the project.
|
|
85
|
+
* @returns the ports, or why they could not be read.
|
|
86
|
+
* @stability experimental
|
|
87
|
+
*/
|
|
88
|
+
export declare function readStackPorts(options: {
|
|
89
|
+
/** The command seam; the engine's `runCommand`. */
|
|
90
|
+
run: ComposeProjectCommandRunner;
|
|
91
|
+
/** The deployment folder. */
|
|
92
|
+
deployRoot: string;
|
|
93
|
+
/** The compose project the run passes to `-p`. */
|
|
94
|
+
project: string;
|
|
95
|
+
/** The deployment's groups; the always-on ones are added. */
|
|
96
|
+
groups?: readonly string[] | undefined;
|
|
97
|
+
}): Promise<StackPortsResult>;
|
|
98
|
+
//# sourceMappingURL=compose-ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-ports.d.ts","sourceRoot":"","sources":["../../../src/engine/deploy/compose-ports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAgC3E;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,+FAA+F;AAC/F,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA2B/G;AAmBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAyC/D;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB;AAC1B,qCAAqC;AACnC;IAAE,MAAM,EAAE,IAA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