@cloud-cli/dx 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/containers.d.ts +9 -1
- package/dist/containers.js +27 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.js +14 -9
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/containers.d.ts
CHANGED
|
@@ -5,7 +5,15 @@ export declare function getAllContainers(): Promise<NameAndStatus[]>;
|
|
|
5
5
|
export declare function getLogs(options: GetLogsOptions): Promise<string>;
|
|
6
6
|
export declare function renameContainer(options: RenameOptions): Container;
|
|
7
7
|
export declare function startAll(_: any, cli: any): Promise<boolean>;
|
|
8
|
+
export declare function updateAll(options: {
|
|
9
|
+
image: string;
|
|
10
|
+
}, cli: any): Promise<any[]>;
|
|
8
11
|
export declare function refreshContainer(options: ContainerName, { run }: ServerParams): Promise<void>;
|
|
9
12
|
export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
10
|
-
export
|
|
13
|
+
export interface StartOptions {
|
|
14
|
+
worker?: boolean;
|
|
15
|
+
startArgs?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function runContainer(options: ContainerName & StartOptions, p: ServerParams): Promise<boolean>;
|
|
18
|
+
export declare function startContainer(options: ContainerName & StartOptions, { run }: ServerParams): Promise<boolean>;
|
|
11
19
|
export declare function stopContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
package/dist/containers.js
CHANGED
|
@@ -56,6 +56,20 @@ export async function startAll(_, cli) {
|
|
|
56
56
|
}
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
|
+
export async function updateAll(options, cli) {
|
|
60
|
+
const list = listContainers();
|
|
61
|
+
const affected = [];
|
|
62
|
+
for (const app of list) {
|
|
63
|
+
if (app.image !== options.image)
|
|
64
|
+
continue;
|
|
65
|
+
try {
|
|
66
|
+
await refreshContainer({ name: app.name }, cli);
|
|
67
|
+
affected.push(app.name);
|
|
68
|
+
}
|
|
69
|
+
catch { }
|
|
70
|
+
}
|
|
71
|
+
return affected;
|
|
72
|
+
}
|
|
59
73
|
export async function refreshContainer(options, { run }) {
|
|
60
74
|
readTargetName(options);
|
|
61
75
|
if (!options.name) {
|
|
@@ -87,6 +101,9 @@ async function getPorts(container) {
|
|
|
87
101
|
const port = Number(container.port);
|
|
88
102
|
return [port, port];
|
|
89
103
|
}
|
|
104
|
+
export function runContainer(options, p) {
|
|
105
|
+
return startContainer({ ...options, worker: true }, p);
|
|
106
|
+
}
|
|
90
107
|
export async function startContainer(options, { run }) {
|
|
91
108
|
readTargetName(options);
|
|
92
109
|
const { name } = options;
|
|
@@ -105,10 +122,10 @@ export async function startContainer(options, { run }) {
|
|
|
105
122
|
const portBindings = addExecFlag([ports.join(':')], 'p');
|
|
106
123
|
const extraArgs = [];
|
|
107
124
|
const config = await getConfig('dx');
|
|
108
|
-
if (container.domain) {
|
|
109
|
-
const [domain, path = ''] = container.domain.split(
|
|
110
|
-
await run(
|
|
111
|
-
extraArgs.push(
|
|
125
|
+
if (container.domain && !options.worker) {
|
|
126
|
+
const [domain, path = ''] = container.domain.split('/');
|
|
127
|
+
await run('dns.add', { domain });
|
|
128
|
+
extraArgs.push('--label', 'px:host=' + domain, '--label', 'px:path=' + path);
|
|
112
129
|
}
|
|
113
130
|
if (config.dns) {
|
|
114
131
|
extraArgs.push('--dns=' + config.dns);
|
|
@@ -119,8 +136,7 @@ export async function startContainer(options, { run }) {
|
|
|
119
136
|
const execArgs = [
|
|
120
137
|
'run',
|
|
121
138
|
'--detach',
|
|
122
|
-
'--restart',
|
|
123
|
-
'always',
|
|
139
|
+
...(!options.worker ? ['--restart', 'always'] : []),
|
|
124
140
|
'--name',
|
|
125
141
|
name,
|
|
126
142
|
...extraArgs,
|
|
@@ -129,6 +145,10 @@ export async function startContainer(options, { run }) {
|
|
|
129
145
|
...addExecFlag(envKeys, 'e'),
|
|
130
146
|
container.image,
|
|
131
147
|
];
|
|
148
|
+
if (options.startArgs) {
|
|
149
|
+
const p = options.startArgs;
|
|
150
|
+
execArgs.push(...(Array.isArray(p) ? p : JSON.parse(p)));
|
|
151
|
+
}
|
|
132
152
|
const output = await exec('docker', execArgs.filter(Boolean), { env });
|
|
133
153
|
if (!output.ok) {
|
|
134
154
|
const e = 'Failed to start container ' + name;
|
|
@@ -150,7 +170,7 @@ export async function stopContainer(options, { run }) {
|
|
|
150
170
|
}
|
|
151
171
|
await exec('docker', ['stop', '-t', '5', name]);
|
|
152
172
|
await exec('docker', ['rm', name]);
|
|
153
|
-
const containers = [findContainer(name)].filter(c => c && c.domain);
|
|
173
|
+
const containers = [findContainer(name)].filter((c) => c && c.domain);
|
|
154
174
|
for (const container of containers) {
|
|
155
175
|
await run('dns.remove', { domain: container.domain });
|
|
156
176
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getLogs, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer } from "./containers.js";
|
|
1
|
+
import { getLogs, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer, runContainer } from "./containers.js";
|
|
2
2
|
import { prune, pull } from "./images.js";
|
|
3
3
|
import { addContainer, getContainer, listContainers, removeContainer, updateContainer } from "./store.js";
|
|
4
4
|
export type { Config } from "./types.js";
|
|
@@ -17,6 +17,7 @@ declare const _default: {
|
|
|
17
17
|
update: typeof updateContainer;
|
|
18
18
|
startAll: typeof startAll;
|
|
19
19
|
start: typeof startContainer;
|
|
20
|
+
run: typeof runContainer;
|
|
20
21
|
stop: typeof stopContainer;
|
|
21
22
|
restart: typeof restartContainer;
|
|
22
23
|
ps: typeof ps;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer, } from "./containers.js";
|
|
1
|
+
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer, runContainer, } from "./containers.js";
|
|
2
2
|
import { prune, pull } from "./images.js";
|
|
3
3
|
import { addContainer, getContainer, listContainers, removeContainer, updateContainer, } from "./store.js";
|
|
4
4
|
function ps(options = {}) {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
update: updateContainer,
|
|
20
20
|
startAll,
|
|
21
21
|
start: startContainer,
|
|
22
|
+
run: runContainer,
|
|
22
23
|
stop: stopContainer,
|
|
23
24
|
restart: restartContainer,
|
|
24
25
|
ps: ps,
|
package/dist/store.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ interface ContainerUpdateOptions extends ContainerName {
|
|
|
7
7
|
domain?: string;
|
|
8
8
|
volumes?: string;
|
|
9
9
|
port?: string;
|
|
10
|
+
worker?: boolean;
|
|
11
|
+
startArgs?: string;
|
|
10
12
|
}
|
|
11
13
|
type ContainerListOptions = Partial<Container>;
|
|
12
14
|
export declare function addContainer(options: ContainerUpdateOptions): Container;
|
package/dist/store.js
CHANGED
|
@@ -10,9 +10,8 @@ export function addContainer(options) {
|
|
|
10
10
|
if (!image)
|
|
11
11
|
throw new Error('Image required');
|
|
12
12
|
const volumes = options.volumes ? sanitiseVolumes(options.volumes) : '';
|
|
13
|
-
const port =
|
|
14
|
-
const
|
|
15
|
-
const container = { name, image, volumes, port, domain };
|
|
13
|
+
const { port = '', domain = '', worker = false, startArgs = '' } = options;
|
|
14
|
+
const container = { name, image, volumes, port, domain, worker, startArgs };
|
|
16
15
|
set(name, container);
|
|
17
16
|
return container;
|
|
18
17
|
}
|
|
@@ -31,23 +30,29 @@ export function getContainer(options) {
|
|
|
31
30
|
const optionSplitter = /,\s*/;
|
|
32
31
|
export function updateContainer(options) {
|
|
33
32
|
readTargetName(options);
|
|
34
|
-
let { port, volumes, name, image, domain } = options;
|
|
33
|
+
let { port, volumes, name, image, domain, startArgs, worker } = options;
|
|
35
34
|
const container = get(name);
|
|
36
35
|
if (!container) {
|
|
37
36
|
throw new Error('Container not found');
|
|
38
37
|
}
|
|
39
|
-
if (port) {
|
|
38
|
+
if (port !== undefined) {
|
|
40
39
|
container.port = port;
|
|
41
40
|
}
|
|
42
|
-
if (volumes) {
|
|
41
|
+
if (volumes !== undefined) {
|
|
43
42
|
container.volumes = sanitiseVolumes(volumes);
|
|
44
43
|
}
|
|
45
|
-
if (image) {
|
|
44
|
+
if (image !== undefined) {
|
|
46
45
|
container.image = image;
|
|
47
46
|
}
|
|
48
|
-
if (domain) {
|
|
47
|
+
if (domain !== undefined) {
|
|
49
48
|
container.domain = domain;
|
|
50
49
|
}
|
|
50
|
+
if (startArgs !== undefined) {
|
|
51
|
+
container.startArgs = startArgs;
|
|
52
|
+
}
|
|
53
|
+
if (worker !== undefined) {
|
|
54
|
+
container.worker = worker;
|
|
55
|
+
}
|
|
51
56
|
set(container.name, container);
|
|
52
57
|
return container;
|
|
53
58
|
}
|
|
@@ -63,7 +68,7 @@ export function listContainers(options = {}) {
|
|
|
63
68
|
const list = getAll();
|
|
64
69
|
const filtered = keys.reduce((list, key) => {
|
|
65
70
|
if (options[key]) {
|
|
66
|
-
return list.filter((c) => String(c[key]).toLowerCase().includes(options[key].toLowerCase()));
|
|
71
|
+
return list.filter((c) => String(c[key]).toLowerCase().includes(String(options[key]).toLowerCase()));
|
|
67
72
|
}
|
|
68
73
|
return list;
|
|
69
74
|
}, list);
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/dx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Docker container management",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"@cloud-cli/prettier-config": "^1.0.0",
|
|
20
20
|
"@cloud-cli/typescript-config": "^1.0.1",
|
|
21
21
|
"@types/node": "^20.12.8",
|
|
22
|
-
"@vitest/coverage-v8": "^1.
|
|
22
|
+
"@vitest/coverage-v8": "^3.1.1",
|
|
23
23
|
"typescript": "^5.4.5",
|
|
24
|
-
"vitest": "^1.
|
|
24
|
+
"vitest": "^3.1.1"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|