@marinoscar/platform-cli 0.1.0-next.12 → 0.1.0-next.14
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 +26 -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.map +1 -1
- package/dist/engine/commands/deploy.js +2 -0
- package/dist/engine/commands/deploy.js.map +1 -1
- package/dist/engine/deploy/checks/compose.d.ts +16 -0
- package/dist/engine/deploy/checks/compose.d.ts.map +1 -0
- package/dist/engine/deploy/checks/compose.js +149 -0
- package/dist/engine/deploy/checks/compose.js.map +1 -0
- package/dist/engine/deploy/checks/index.d.ts +2 -0
- package/dist/engine/deploy/checks/index.d.ts.map +1 -1
- package/dist/engine/deploy/checks/index.js +8 -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 +234 -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 +101 -0
- package/dist/engine/deploy/compose-containers.d.ts.map +1 -0
- package/dist/engine/deploy/compose-containers.js +191 -0
- package/dist/engine/deploy/compose-containers.js.map +1 -0
- package/dist/engine/deploy/compose-port-variables.d.ts +18 -0
- package/dist/engine/deploy/compose-port-variables.d.ts.map +1 -0
- package/dist/engine/deploy/compose-port-variables.js +136 -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 +38 -32
- package/dist/engine/deploy/compose-project.d.ts.map +1 -1
- package/dist/engine/deploy/compose-project.js +78 -100
- package/dist/engine/deploy/compose-project.js.map +1 -1
- package/dist/engine/deploy/install.d.ts +2 -10
- package/dist/engine/deploy/install.d.ts.map +1 -1
- package/dist/engine/deploy/install.js +83 -31
- 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 +29 -0
- package/dist/engine/deploy/testing/fake-containers.d.ts.map +1 -0
- package/dist/engine/deploy/testing/fake-containers.js +32 -0
- package/dist/engine/deploy/testing/fake-containers.js.map +1 -0
- 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.map +1 -1
- package/dist/engine/deploy/update.js +46 -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/package.json +3 -3
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { basename, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// Which containers does Docker know, and which compose project is each in?
|
|
4
|
+
// =============================================================================
|
|
5
|
+
//
|
|
6
|
+
// The leaf under compose-project.ts (detection and reconciliation) and the
|
|
7
|
+
// `bind-port-owner` / `stray-compose-stack` deploy checks: it imports nothing
|
|
8
|
+
// from the engine, so a check can ask Docker without importing the install
|
|
9
|
+
// pipeline. Read-only (`docker ps`, `docker inspect`), argv only.
|
|
10
|
+
// =============================================================================
|
|
11
|
+
/** The label a container carries naming its compose project. */
|
|
12
|
+
const COMPOSE_PROJECT_LABEL = 'com.docker.compose.project';
|
|
13
|
+
/** The label naming the directory compose was run from. */
|
|
14
|
+
const COMPOSE_WORKING_DIR_LABEL = 'com.docker.compose.project.working_dir';
|
|
15
|
+
/** Short by design: a wedged Docker socket must cost seconds, not the command. */
|
|
16
|
+
const DOCKER_QUERY_TIMEOUT_MS = 10_000;
|
|
17
|
+
/**
|
|
18
|
+
* One line per container: name, running state, host port bindings, compose
|
|
19
|
+
* project, then compose working directory.
|
|
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
|
+
*
|
|
30
|
+
* `{{if .Config.Labels}}` guards a container created without any labels, whose
|
|
31
|
+
* `Labels` is null rather than an empty map (`index` on nil renders
|
|
32
|
+
* `<no value>` into the line otherwise); the separators sit outside the guards
|
|
33
|
+
* so every line has all five fields. `PortBindings` is the CONFIGURED publish,
|
|
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.
|
|
37
|
+
*/
|
|
38
|
+
const INSPECT_FORMAT = '{{.Name}}|{{.State.Running}}|' +
|
|
39
|
+
'{{json .HostConfig.PortBindings}}|' +
|
|
40
|
+
`{{if .Config.Labels}}{{index .Config.Labels "${COMPOSE_PROJECT_LABEL}"}}{{end}}|` +
|
|
41
|
+
`{{if .Config.Labels}}{{index .Config.Labels "${COMPOSE_WORKING_DIR_LABEL}"}}{{end}}`;
|
|
42
|
+
/**
|
|
43
|
+
* Whether `path` is `root` or inside it, by path segment: `/opt/apps/app2` is
|
|
44
|
+
* NOT under `/opt/apps/app`. Both are resolved first; nothing touches the disk,
|
|
45
|
+
* because a container's recorded directory need not exist any more.
|
|
46
|
+
*
|
|
47
|
+
* @param path - The path to test.
|
|
48
|
+
* @param root - The folder it may be under.
|
|
49
|
+
* @returns true when `path` is `root` or below it.
|
|
50
|
+
* @stability experimental
|
|
51
|
+
*/
|
|
52
|
+
export function isPathUnder(path, root) {
|
|
53
|
+
const relation = relative(resolve(root), resolve(path));
|
|
54
|
+
return relation === '' || (relation !== '..' && !relation.startsWith(`..${sep}`) && !isAbsolute(relation));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The compose project a FRESH install of `deployRoot` gets: the folder name.
|
|
58
|
+
* An existing deployment keeps the one it runs under (`composeProjectFor`);
|
|
59
|
+
* only a deployment with no record and no evidence is named this way. Install
|
|
60
|
+
* and the `bind-port-owner` check both ask here, so they cannot disagree.
|
|
61
|
+
*
|
|
62
|
+
* @param deployRoot - The deployment folder.
|
|
63
|
+
* @returns the project name a fresh install would use.
|
|
64
|
+
*/
|
|
65
|
+
export function freshComposeProject(deployRoot) {
|
|
66
|
+
return basename(deployRoot);
|
|
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
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether `container` is configured to publish host port `port`. An empty
|
|
82
|
+
* `HostPort` (Docker picks one) is no claim; a range claims every port in it.
|
|
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
|
+
*
|
|
91
|
+
* @param container - The container.
|
|
92
|
+
* @param port - The host port.
|
|
93
|
+
* @param match - Narrow the claim to an address and/or protocol.
|
|
94
|
+
* @returns true when the container publishes it.
|
|
95
|
+
*/
|
|
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;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Every container Docker knows, in any state, with its compose labels and the
|
|
141
|
+
* host ports it is configured to publish: one `docker ps -aq` and ONE
|
|
142
|
+
* `docker inspect`, argv only, never a shell string.
|
|
143
|
+
*
|
|
144
|
+
* @param run - The command seam; pass the engine's `runCommand`.
|
|
145
|
+
* @returns the containers, or `undefined` when Docker cannot be asked.
|
|
146
|
+
*/
|
|
147
|
+
export async function listComposeContainers(run) {
|
|
148
|
+
try {
|
|
149
|
+
const ask = (argv) => run(argv, { cwd: process.cwd(), timeoutMs: DOCKER_QUERY_TIMEOUT_MS });
|
|
150
|
+
// `-aq`: every container, whatever its state. Ids, which can never be ambiguous.
|
|
151
|
+
const ids = (await ask(['docker', 'ps', '-aq']))
|
|
152
|
+
.stdout.split('\n')
|
|
153
|
+
.map((line) => line.trim())
|
|
154
|
+
.filter((line) => line !== '');
|
|
155
|
+
if (ids.length === 0)
|
|
156
|
+
return [];
|
|
157
|
+
const { stdout } = await ask(['docker', 'inspect', '--format', INSPECT_FORMAT, ...ids]);
|
|
158
|
+
const containers = [];
|
|
159
|
+
for (const line of stdout.split('\n')) {
|
|
160
|
+
// Four separators, then the working directory (which may hold more). A
|
|
161
|
+
// line with fewer is not ours, such as the `<no value>` an unguarded
|
|
162
|
+
// template prints.
|
|
163
|
+
const fields = [];
|
|
164
|
+
let rest = line;
|
|
165
|
+
for (let index = 0; index < 4; index += 1) {
|
|
166
|
+
const separator = rest.indexOf('|');
|
|
167
|
+
if (separator === -1)
|
|
168
|
+
break;
|
|
169
|
+
fields.push(rest.slice(0, separator));
|
|
170
|
+
rest = rest.slice(separator + 1);
|
|
171
|
+
}
|
|
172
|
+
if (fields.length < 4)
|
|
173
|
+
continue;
|
|
174
|
+
const [name = '', running = '', ports = '', project = ''] = fields;
|
|
175
|
+
const bindings = parseBindings(ports);
|
|
176
|
+
containers.push({
|
|
177
|
+
name: name.replace(/^\//, '').trim(),
|
|
178
|
+
running: running.trim() === 'true',
|
|
179
|
+
hostPorts: bindings.map((binding) => binding.hostPort),
|
|
180
|
+
bindings,
|
|
181
|
+
project: project.trim(),
|
|
182
|
+
workingDir: rest.trim(),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return containers;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=compose-containers.js.map
|
|
@@ -0,0 +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,CAAC;AAE3E,kFAAkF;AAClF,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,cAAc,GAClB,+BAA+B;IAC/B,oCAAoC;IACpC,gDAAgD,qBAAqB,aAAa;IAClF,gDAAgD,yBAAyB,YAAY,CAAC;AAqDxF;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY;IACpD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC7G,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC;AAED,kHAAkH;AAClH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,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AC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
//# 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;AA2IvE;;;;;;;;;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"}
|
|
@@ -0,0 +1,136 @@
|
|
|
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 `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.
|
|
52
|
+
*/
|
|
53
|
+
function rawPortsOf(service, texts) {
|
|
54
|
+
let entries = [];
|
|
55
|
+
for (const text of texts) {
|
|
56
|
+
let inServices = false;
|
|
57
|
+
let serviceIndent = -1;
|
|
58
|
+
let inService = false;
|
|
59
|
+
let portsIndent = -1; // >= 0 while inside this service's `ports:` list
|
|
60
|
+
for (const line of text.split(/\r?\n/)) {
|
|
61
|
+
const trimmed = line.trim();
|
|
62
|
+
if (trimmed === '' || trimmed.startsWith('#'))
|
|
63
|
+
continue;
|
|
64
|
+
const indent = indentOf(line);
|
|
65
|
+
if (indent === 0) {
|
|
66
|
+
inServices = /^services:\s*(#.*)?$/.test(trimmed);
|
|
67
|
+
inService = false;
|
|
68
|
+
portsIndent = -1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!inServices)
|
|
72
|
+
continue;
|
|
73
|
+
// Leaving a `ports:` list: the first line that is not deeper than its key
|
|
74
|
+
// (an item may sit at the key's own indent, which YAML allows).
|
|
75
|
+
if (portsIndent >= 0 && (indent < portsIndent || (indent === portsIndent && !trimmed.startsWith('-')))) {
|
|
76
|
+
portsIndent = -1;
|
|
77
|
+
}
|
|
78
|
+
if (portsIndent >= 0) {
|
|
79
|
+
const value = itemValue(line);
|
|
80
|
+
const split = value === undefined ? undefined : splitPortSpec(value);
|
|
81
|
+
if (split !== undefined)
|
|
82
|
+
entries.push(split);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
// The first key under `services:` fixes the indent of the service names.
|
|
86
|
+
if (serviceIndent === -1)
|
|
87
|
+
serviceIndent = indent;
|
|
88
|
+
if (indent === serviceIndent) {
|
|
89
|
+
const name = /^([A-Za-z0-9_.-]+):/.exec(trimmed)?.[1];
|
|
90
|
+
inService = name === service;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (!inService)
|
|
94
|
+
continue;
|
|
95
|
+
const ports = /^ports:\s*(!override|!reset)?\s*(\[\s*\])?\s*(#.*)?$/.exec(trimmed);
|
|
96
|
+
if (ports === null)
|
|
97
|
+
continue;
|
|
98
|
+
if (ports[1] !== undefined)
|
|
99
|
+
entries = [];
|
|
100
|
+
if (ports[2] === undefined)
|
|
101
|
+
portsIndent = indent;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return entries;
|
|
105
|
+
}
|
|
106
|
+
/** Whether an interpolated published token (`14003`, `8000-8010`) covers `port`. */
|
|
107
|
+
function covers(published, port) {
|
|
108
|
+
const [first = '', last = first] = published.trim().split('-');
|
|
109
|
+
const low = Number(first);
|
|
110
|
+
const high = Number(last);
|
|
111
|
+
return Number.isInteger(low) && Number.isInteger(high) && low <= port && port <= high;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The environment variable that sets the host port compose reported, or
|
|
115
|
+
* `undefined` when the port is a literal in the files (or cannot be traced).
|
|
116
|
+
*
|
|
117
|
+
* @param options - The port, the compose files' text in the order compose
|
|
118
|
+
* merges them, and the environment compose interpolates with (the
|
|
119
|
+
* deployment's `.env`, then the process environment).
|
|
120
|
+
* @returns the variable name, such as `GREPTIME_BIND_PG_PORT`.
|
|
121
|
+
* @stability experimental
|
|
122
|
+
*/
|
|
123
|
+
export function portVariableFor(options) {
|
|
124
|
+
const { port, files, env } = options;
|
|
125
|
+
const wildcard = (ip) => ip === '' || ip === '0.0.0.0' || ip === '::';
|
|
126
|
+
const matching = rawPortsOf(port.service, files).filter((entry) => {
|
|
127
|
+
const hostIp = interpolate(entry.hostIp, env).replace(/^\[|\]$/g, '');
|
|
128
|
+
return (covers(interpolate(entry.published, env), port.port) &&
|
|
129
|
+
entry.protocol === port.protocol &&
|
|
130
|
+
(hostIp === port.hostIp || (wildcard(hostIp) && wildcard(port.hostIp))));
|
|
131
|
+
});
|
|
132
|
+
// The last file wins, so the last matching entry names the variable.
|
|
133
|
+
const last = matching[matching.length - 1];
|
|
134
|
+
return last === undefined ? undefined : variableOf(last.published);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=compose-port-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-port-variables.js","sourceRoot":"","sources":["../../../src/engine/deploy/compose-port-variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,oBAAoB,CAAC;AA4BvE,+EAA+E;AAC/E,MAAM,aAAa,GAAG,wFAAwF,CAAC;AAE/G;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAa,EAAE,GAAgC;IAClE,OAAO,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAe,EAAE,KAAc,EAAE,QAAiB,EAAE,QAAiB,EAAE,IAAa,EAAE,EAAE;QAClI,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,GAAG,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,MAAM,KAAK,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;QACrE,IAAI,QAAQ,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QACtE,IAAI,QAAQ,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,IA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QAAQ,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,IAAI,CAAC;IAEvF,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAChE,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACtE,OAAO,CACL,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;YACpD,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ;YAChC,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,qEAAqE;IACrE,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -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,IAAI,CAAC;IAAC,KAAK,EAAE,aAAa,EAAE,CAAA;CAAE;AAC1C,0GAA0G;GACxG;IAAE,MAAM,EAAE,oBAAoB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;AACnD,0HAA0H;GACxH;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAcjD;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC5C,mDAAmD;IACnD,GAAG,EAAE,2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