@cloud-cli/dx 1.5.0 → 1.6.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/dist/containers.js +15 -7
- package/dist/store.d.ts +6 -1
- package/dist/store.js +17 -6
- package/package.json +1 -1
package/dist/containers.js
CHANGED
|
@@ -6,7 +6,7 @@ export async function getRunningContainers() {
|
|
|
6
6
|
if (!ps.ok) {
|
|
7
7
|
throw new Error('Failed to list containers: ' + ps.stderr);
|
|
8
8
|
}
|
|
9
|
-
return getListFromString(ps.stdout);
|
|
9
|
+
return getListFromString(ps.stdout).sort();
|
|
10
10
|
}
|
|
11
11
|
export async function getLogs({ name, lines }) {
|
|
12
12
|
if (!name) {
|
|
@@ -23,15 +23,21 @@ export async function getLogs({ name, lines }) {
|
|
|
23
23
|
return '';
|
|
24
24
|
}
|
|
25
25
|
export async function startAll(_, cli) {
|
|
26
|
-
const list = await listContainers();
|
|
26
|
+
const list = await listContainers({});
|
|
27
27
|
const running = await getRunningContainers();
|
|
28
28
|
const notRunning = list.filter(({ name }) => !running.includes(name));
|
|
29
29
|
for (const app of notRunning) {
|
|
30
|
-
|
|
30
|
+
try {
|
|
31
|
+
await refreshContainer({ name: app.name }, cli);
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
31
34
|
}
|
|
32
35
|
return true;
|
|
33
36
|
}
|
|
34
37
|
export async function refreshContainer(options, { run }) {
|
|
38
|
+
if (!options.name) {
|
|
39
|
+
throw new Error('Name is required');
|
|
40
|
+
}
|
|
35
41
|
const { name } = options;
|
|
36
42
|
const container = await findContainer(name);
|
|
37
43
|
await run('dx.pull', { image: container.image });
|
|
@@ -44,15 +50,17 @@ export async function startContainer(options, { run }) {
|
|
|
44
50
|
if (!name) {
|
|
45
51
|
throw new Error('Name is required');
|
|
46
52
|
}
|
|
47
|
-
const vars = (await run('env.show', {
|
|
53
|
+
const vars = (await run('env.show', { name }));
|
|
48
54
|
const { env, envKeys } = await getEnvVars(vars);
|
|
49
55
|
const container = await findContainer(name);
|
|
50
56
|
const volumes = addExecFlag(container.volumes, 'v');
|
|
51
57
|
const ports = getPorts([...container.ports.split(','), env.PORT + ':' + env.PORT]);
|
|
52
58
|
if (container.host) {
|
|
53
|
-
|
|
54
|
-
await run('px.
|
|
55
|
-
await run('
|
|
59
|
+
const domain = container.host;
|
|
60
|
+
const proxy = await run('px.get', { domain });
|
|
61
|
+
await run('px.remove', { domain });
|
|
62
|
+
await run('px.add', { ...proxy, domain, target: 'http://localhost:' + env.PORT });
|
|
63
|
+
await run('dns.add', { domain });
|
|
56
64
|
await run('dns.reload', {});
|
|
57
65
|
}
|
|
58
66
|
const execArgs = [
|
package/dist/store.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ interface UpdateOptions extends ContainerName {
|
|
|
26
26
|
host?: string;
|
|
27
27
|
}
|
|
28
28
|
export declare function updateContainer(options: UpdateOptions): Promise<Container>;
|
|
29
|
-
|
|
29
|
+
interface ListOptions {
|
|
30
|
+
name?: string;
|
|
31
|
+
image?: string;
|
|
32
|
+
host?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function listContainers(options: ListOptions): Promise<Container[]>;
|
|
30
35
|
export declare function findContainer(name: string): Promise<Container | null>;
|
|
31
36
|
export {};
|
package/dist/store.js
CHANGED
|
@@ -42,8 +42,8 @@ export async function addContainer(options) {
|
|
|
42
42
|
throw new Error('Name required');
|
|
43
43
|
if (!image)
|
|
44
44
|
throw new Error('Image required');
|
|
45
|
-
const volumes =
|
|
46
|
-
const ports =
|
|
45
|
+
const volumes = options.volumes ? sanitiseVolumes(options.volumes) : '';
|
|
46
|
+
const ports = options.ports ? sanitisePorts(options.ports) : '';
|
|
47
47
|
const host = options.host;
|
|
48
48
|
const container = new Container({ name, image, volumes, ports, host });
|
|
49
49
|
const id = await container.save();
|
|
@@ -83,8 +83,11 @@ export async function updateContainer(options) {
|
|
|
83
83
|
await container.save();
|
|
84
84
|
return container;
|
|
85
85
|
}
|
|
86
|
-
export async function listContainers() {
|
|
87
|
-
|
|
86
|
+
export async function listContainers(options) {
|
|
87
|
+
const query = new Query();
|
|
88
|
+
['name', 'image', 'host'].forEach((key) => !options[key] || query.where(key).is(options[key]));
|
|
89
|
+
const list = await Resource.find(Container, query);
|
|
90
|
+
return list.sort((a, b) => Number(a.name > b.name) || -1);
|
|
88
91
|
}
|
|
89
92
|
export async function findContainer(name) {
|
|
90
93
|
const found = await Resource.find(Container, new Query().where('name').is(name));
|
|
@@ -92,9 +95,17 @@ export async function findContainer(name) {
|
|
|
92
95
|
}
|
|
93
96
|
const portTester = /^\d+:\d+$/;
|
|
94
97
|
function sanitisePorts(ports) {
|
|
95
|
-
return ports
|
|
98
|
+
return ports
|
|
99
|
+
.split(optionSplitter)
|
|
100
|
+
.map((s) => s.trim())
|
|
101
|
+
.filter((s) => portTester.test(s))
|
|
102
|
+
.join(',');
|
|
96
103
|
}
|
|
97
104
|
const volumeTester = /^\S+:\S+$/;
|
|
98
105
|
function sanitiseVolumes(volumes) {
|
|
99
|
-
return volumes
|
|
106
|
+
return volumes
|
|
107
|
+
.split(optionSplitter)
|
|
108
|
+
.map((s) => s.trim())
|
|
109
|
+
.filter((s) => volumeTester.test(s))
|
|
110
|
+
.join(',');
|
|
100
111
|
}
|