@cloud-cli/dx 1.8.2 → 1.8.3
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/containers.d.ts +4 -2
- package/dist/containers.js +11 -8
- package/dist/images.js +2 -0
- package/dist/store.d.ts +1 -0
- package/dist/store.js +6 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +11 -0
- package/package.json +1 -1
package/dist/containers.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { ServerParams } from '@cloud-cli/cli';
|
|
2
2
|
export declare function getRunningContainers(): Promise<string[]>;
|
|
3
3
|
interface GetLogsOptions {
|
|
4
|
+
_?: string[];
|
|
4
5
|
name: string;
|
|
5
6
|
lines?: string;
|
|
6
7
|
}
|
|
7
8
|
interface ContainerName {
|
|
9
|
+
_?: string[];
|
|
8
10
|
name: string;
|
|
9
11
|
}
|
|
10
|
-
export declare function getLogs(
|
|
12
|
+
export declare function getLogs(options: GetLogsOptions): Promise<string>;
|
|
11
13
|
export declare function startAll(_: any, cli: any): Promise<boolean>;
|
|
12
14
|
export declare function refreshContainer(options: ContainerName, { run }: ServerParams): Promise<void>;
|
|
13
|
-
export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<
|
|
15
|
+
export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
14
16
|
export declare function startContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
15
17
|
export declare function stopContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
16
18
|
export {};
|
package/dist/containers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { exec } from '@cloud-cli/exec';
|
|
2
2
|
import { findContainer, listContainers } from './store.js';
|
|
3
3
|
import { getConfig } from './config.js';
|
|
4
|
-
import { addExecFlag, getEnvVars, getListFromString, getPorts } from './utils.js';
|
|
4
|
+
import { addExecFlag, getEnvVars, getListFromString, getPorts, readTargetName, } from './utils.js';
|
|
5
5
|
export async function getRunningContainers() {
|
|
6
6
|
const ps = await exec('docker', ['ps', '--format', '{{.Names}}']);
|
|
7
7
|
if (!ps.ok) {
|
|
@@ -9,7 +9,9 @@ export async function getRunningContainers() {
|
|
|
9
9
|
}
|
|
10
10
|
return getListFromString(ps.stdout).sort();
|
|
11
11
|
}
|
|
12
|
-
export async function getLogs(
|
|
12
|
+
export async function getLogs(options) {
|
|
13
|
+
readTargetName(options);
|
|
14
|
+
const { name, lines } = options;
|
|
13
15
|
if (!name) {
|
|
14
16
|
throw new Error('Name not specified');
|
|
15
17
|
}
|
|
@@ -18,10 +20,7 @@ export async function getLogs({ name, lines }) {
|
|
|
18
20
|
args.push('-n', String(Number(lines)));
|
|
19
21
|
}
|
|
20
22
|
const sh = await exec('docker', args);
|
|
21
|
-
|
|
22
|
-
return [sh.stdout, sh.stderr].join('\n');
|
|
23
|
-
}
|
|
24
|
-
return '';
|
|
23
|
+
return [sh.stdout, sh.stderr].join('\n\n').trim();
|
|
25
24
|
}
|
|
26
25
|
export async function startAll(_, cli) {
|
|
27
26
|
const list = await listContainers({});
|
|
@@ -36,6 +35,7 @@ export async function startAll(_, cli) {
|
|
|
36
35
|
return true;
|
|
37
36
|
}
|
|
38
37
|
export async function refreshContainer(options, { run }) {
|
|
38
|
+
readTargetName(options);
|
|
39
39
|
if (!options.name) {
|
|
40
40
|
throw new Error('Name is required');
|
|
41
41
|
}
|
|
@@ -47,12 +47,14 @@ export async function refreshContainer(options, { run }) {
|
|
|
47
47
|
await run('dx.start', { name });
|
|
48
48
|
}
|
|
49
49
|
export async function restartContainer(options, { run }) {
|
|
50
|
+
readTargetName(options);
|
|
50
51
|
const { name } = options;
|
|
51
52
|
await run('dx.stop', { name });
|
|
52
53
|
await run('dx.start', { name });
|
|
53
|
-
return
|
|
54
|
+
return true;
|
|
54
55
|
}
|
|
55
56
|
export async function startContainer(options, { run }) {
|
|
57
|
+
readTargetName(options);
|
|
56
58
|
const { name } = options;
|
|
57
59
|
if (!name) {
|
|
58
60
|
throw new Error('Name is required');
|
|
@@ -87,11 +89,13 @@ export async function startContainer(options, { run }) {
|
|
|
87
89
|
];
|
|
88
90
|
const output = await exec('docker', execArgs.filter(Boolean), { env });
|
|
89
91
|
if (!output.ok) {
|
|
92
|
+
console.log([output.stdout, output.stderr].join('\n\n'));
|
|
90
93
|
throw new Error('Failed to start ' + name);
|
|
91
94
|
}
|
|
92
95
|
return true;
|
|
93
96
|
}
|
|
94
97
|
export async function stopContainer(options, { run }) {
|
|
98
|
+
readTargetName(options);
|
|
95
99
|
let { name } = options;
|
|
96
100
|
if (!name) {
|
|
97
101
|
throw new Error('Name is required');
|
|
@@ -101,7 +105,6 @@ export async function stopContainer(options, { run }) {
|
|
|
101
105
|
const containers = [await findContainer(name)].filter(Boolean);
|
|
102
106
|
for (const container of containers) {
|
|
103
107
|
await run('dns.remove', { domain: container.host });
|
|
104
|
-
await run('dns.reload', {});
|
|
105
108
|
}
|
|
106
109
|
return true;
|
|
107
110
|
}
|
package/dist/images.js
CHANGED
package/dist/store.d.ts
CHANGED
package/dist/store.js
CHANGED
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Model, Resource, Primary, NotNull, Property, Query } from '@cloud-cli/store';
|
|
8
|
+
import { readTargetImage, readTargetName } from './utils';
|
|
8
9
|
let Container = class Container extends Resource {
|
|
9
10
|
};
|
|
10
11
|
__decorate([
|
|
@@ -37,6 +38,8 @@ Container = __decorate([
|
|
|
37
38
|
], Container);
|
|
38
39
|
export { Container };
|
|
39
40
|
export async function addContainer(options) {
|
|
41
|
+
readTargetName(options);
|
|
42
|
+
readTargetImage(options);
|
|
40
43
|
const { name, image } = options;
|
|
41
44
|
if (!name)
|
|
42
45
|
throw new Error('Name required');
|
|
@@ -51,6 +54,7 @@ export async function addContainer(options) {
|
|
|
51
54
|
return container;
|
|
52
55
|
}
|
|
53
56
|
export async function removeContainer(options) {
|
|
57
|
+
readTargetName(options);
|
|
54
58
|
const found = await findContainer(options.name);
|
|
55
59
|
if (found) {
|
|
56
60
|
await found.remove();
|
|
@@ -59,10 +63,12 @@ export async function removeContainer(options) {
|
|
|
59
63
|
throw new Error('Container not found: ' + options.name);
|
|
60
64
|
}
|
|
61
65
|
export async function getContainer(options) {
|
|
66
|
+
readTargetName(options);
|
|
62
67
|
return await findContainer(options.name);
|
|
63
68
|
}
|
|
64
69
|
const optionSplitter = /,\s*/;
|
|
65
70
|
export async function updateContainer(options) {
|
|
71
|
+
readTargetName(options);
|
|
66
72
|
let { ports, volumes, name, image, host } = options;
|
|
67
73
|
const container = await findContainer(name);
|
|
68
74
|
if (!container) {
|
package/dist/utils.d.ts
CHANGED
|
@@ -11,3 +11,5 @@ export declare function getEnvVars(vars: EnvList): Promise<{
|
|
|
11
11
|
}>;
|
|
12
12
|
export declare function getListFromString(string: string): string[];
|
|
13
13
|
export declare function addExecFlag(string: string, flag: string): string[];
|
|
14
|
+
export declare function readTargetName(args: any): void;
|
|
15
|
+
export declare function readTargetImage(args: any): void;
|
package/dist/utils.js
CHANGED
|
@@ -26,3 +26,14 @@ export function addExecFlag(string, flag) {
|
|
|
26
26
|
.filter(Boolean)
|
|
27
27
|
.map((p) => `-${flag}${p}`);
|
|
28
28
|
}
|
|
29
|
+
export function readTargetName(args) {
|
|
30
|
+
readPositionalArgs(args, 'name');
|
|
31
|
+
}
|
|
32
|
+
export function readTargetImage(args) {
|
|
33
|
+
readPositionalArgs(args, 'image');
|
|
34
|
+
}
|
|
35
|
+
function readPositionalArgs(args, name) {
|
|
36
|
+
if (!args[name]) {
|
|
37
|
+
args[name] = (args._ || []).shift();
|
|
38
|
+
}
|
|
39
|
+
}
|