@matterbridge/utils 3.10.14-dev-20261014-ad770e2 → 3.10.14-dev-20261015-97e1ff6
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/dist/export.d.ts +1 -0
- package/dist/export.js +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +18 -0
- package/dist/runtimeDocker.d.ts +19 -0
- package/dist/runtimeDocker.js +54 -2
- package/package.json +1 -1
package/dist/export.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './measurementUtils.js';
|
|
|
16
16
|
export * from './network.js';
|
|
17
17
|
export * from './npmPrefix.js';
|
|
18
18
|
export * from './npmVersion.js';
|
|
19
|
+
export * from './runtime.js';
|
|
19
20
|
export * from './runtimeBun.js';
|
|
20
21
|
export * from './runtimeDocker.js';
|
|
21
22
|
export * from './tracker.js';
|
package/dist/export.js
CHANGED
|
@@ -16,6 +16,7 @@ export * from './measurementUtils.js';
|
|
|
16
16
|
export * from './network.js';
|
|
17
17
|
export * from './npmPrefix.js';
|
|
18
18
|
export * from './npmVersion.js';
|
|
19
|
+
export * from './runtime.js';
|
|
19
20
|
export * from './runtimeBun.js';
|
|
20
21
|
export * from './runtimeDocker.js';
|
|
21
22
|
export * from './tracker.js';
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { logModuleLoaded } from './loader.js';
|
|
3
|
+
logModuleLoaded('Runtime');
|
|
4
|
+
const SUDO_PROBE_TIMEOUT_MS = 5000;
|
|
5
|
+
export function isRoot() {
|
|
6
|
+
return process.getuid?.() === 0;
|
|
7
|
+
}
|
|
8
|
+
export function hasPasswordlessSudo() {
|
|
9
|
+
if (process.platform === 'win32')
|
|
10
|
+
return false;
|
|
11
|
+
try {
|
|
12
|
+
const result = spawnSync('sudo', ['-n', 'true'], { stdio: 'ignore', timeout: SUDO_PROBE_TIMEOUT_MS });
|
|
13
|
+
return !result.error && result.status === 0;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/runtimeDocker.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
export declare const DOCKERENV_FILE = "/.dockerenv";
|
|
3
|
+
export declare const CONTAINERENV_FILE = "/run/.containerenv";
|
|
4
|
+
export declare const DOCKER_BUILD_CONFIG_FILE = "/matterbridge/.dockerbuild.json";
|
|
1
5
|
export declare const DOCKER_MARKER_FILES: readonly string[];
|
|
6
|
+
export type ContainerKind = 'codespaces' | 'devcontainer' | 'kubernetes' | 'podman' | 'docker';
|
|
7
|
+
export interface DockerRuntimeInfo {
|
|
8
|
+
container: boolean;
|
|
9
|
+
kind: ContainerKind | undefined;
|
|
10
|
+
dockerParameter: boolean;
|
|
11
|
+
imageBuildConfig: Record<string, unknown> | undefined;
|
|
12
|
+
bridgeNetwork: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface DockerRuntimeFiles {
|
|
15
|
+
dockerenv?: string;
|
|
16
|
+
containerenv?: string;
|
|
17
|
+
buildConfig?: string;
|
|
18
|
+
}
|
|
2
19
|
export declare function isDocker(markerFiles?: readonly string[]): boolean;
|
|
20
|
+
export declare function isDockerBridgeNetwork(interfaces?: NodeJS.Dict<os.NetworkInterfaceInfo[]>): boolean;
|
|
21
|
+
export declare function getDockerRuntimeInfo(files?: DockerRuntimeFiles, interfaces?: NodeJS.Dict<os.NetworkInterfaceInfo[]>): DockerRuntimeInfo;
|
package/dist/runtimeDocker.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { hasParameter } from './commandLine.js';
|
|
2
4
|
import { logModuleLoaded } from './loader.js';
|
|
5
|
+
import { isValidObject } from './validate.js';
|
|
3
6
|
logModuleLoaded('RuntimeDocker');
|
|
4
|
-
export const
|
|
7
|
+
export const DOCKERENV_FILE = '/.dockerenv';
|
|
8
|
+
export const CONTAINERENV_FILE = '/run/.containerenv';
|
|
9
|
+
export const DOCKER_BUILD_CONFIG_FILE = '/matterbridge/.dockerbuild.json';
|
|
10
|
+
export const DOCKER_MARKER_FILES = [DOCKERENV_FILE, CONTAINERENV_FILE];
|
|
5
11
|
export function isDocker(markerFiles = DOCKER_MARKER_FILES) {
|
|
6
12
|
if (process.platform !== 'linux')
|
|
7
13
|
return false;
|
|
@@ -9,3 +15,49 @@ export function isDocker(markerFiles = DOCKER_MARKER_FILES) {
|
|
|
9
15
|
return true;
|
|
10
16
|
return markerFiles.some((file) => existsSync(file));
|
|
11
17
|
}
|
|
18
|
+
function isDockerBridgeAddress(address) {
|
|
19
|
+
const [first, second] = address.split('.').map(Number);
|
|
20
|
+
return first === 172 && second >= 16 && second <= 31;
|
|
21
|
+
}
|
|
22
|
+
export function isDockerBridgeNetwork(interfaces = os.networkInterfaces()) {
|
|
23
|
+
const addresses = Object.values(interfaces)
|
|
24
|
+
.flatMap((infos) => infos ?? [])
|
|
25
|
+
.filter((info) => info.family === 'IPv4' && !info.internal)
|
|
26
|
+
.map((info) => info.address);
|
|
27
|
+
return addresses.length > 0 && addresses.every(isDockerBridgeAddress);
|
|
28
|
+
}
|
|
29
|
+
function getContainerKind(files) {
|
|
30
|
+
if (process.platform !== 'linux')
|
|
31
|
+
return undefined;
|
|
32
|
+
if (process.env.CODESPACES === 'true')
|
|
33
|
+
return 'codespaces';
|
|
34
|
+
if (process.env.REMOTE_CONTAINERS === 'true')
|
|
35
|
+
return 'devcontainer';
|
|
36
|
+
if (process.env.KUBERNETES_SERVICE_HOST)
|
|
37
|
+
return 'kubernetes';
|
|
38
|
+
if (existsSync(files.containerenv ?? CONTAINERENV_FILE))
|
|
39
|
+
return 'podman';
|
|
40
|
+
if (existsSync(files.dockerenv ?? DOCKERENV_FILE))
|
|
41
|
+
return 'docker';
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
function readImageBuildConfig(file) {
|
|
45
|
+
try {
|
|
46
|
+
const config = JSON.parse(readFileSync(file, 'utf-8'));
|
|
47
|
+
return isValidObject(config) ? Object.fromEntries(Object.entries(config)) : undefined;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function getDockerRuntimeInfo(files = {}, interfaces) {
|
|
54
|
+
const kind = getContainerKind(files);
|
|
55
|
+
const container = kind !== undefined;
|
|
56
|
+
return {
|
|
57
|
+
container,
|
|
58
|
+
kind,
|
|
59
|
+
dockerParameter: hasParameter('docker'),
|
|
60
|
+
imageBuildConfig: container ? readImageBuildConfig(files.buildConfig ?? DOCKER_BUILD_CONFIG_FILE) : undefined,
|
|
61
|
+
bridgeNetwork: container && isDockerBridgeNetwork(interfaces),
|
|
62
|
+
};
|
|
63
|
+
}
|
package/package.json
CHANGED