@cloud-cli/dx 1.5.1 → 1.7.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/cloud.db +0 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +7 -0
- package/dist/containers.js +15 -6
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/store.d.ts +6 -1
- package/dist/store.js +16 -6
- package/package.json +1 -1
package/cloud.db
CHANGED
|
Binary file
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
package/dist/containers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { exec } from '@cloud-cli/exec';
|
|
2
2
|
import { findContainer, listContainers } from './store.js';
|
|
3
|
+
import { getConfig } from './config.js';
|
|
3
4
|
import { addExecFlag, getEnvVars, getListFromString, getPorts } from './utils.js';
|
|
4
5
|
export async function getRunningContainers() {
|
|
5
6
|
const ps = await exec('docker', ['ps', '--format', '{{.Names}}']);
|
|
@@ -23,7 +24,7 @@ export async function getLogs({ name, lines }) {
|
|
|
23
24
|
return '';
|
|
24
25
|
}
|
|
25
26
|
export async function startAll(_, cli) {
|
|
26
|
-
const list = await listContainers();
|
|
27
|
+
const list = await listContainers({});
|
|
27
28
|
const running = await getRunningContainers();
|
|
28
29
|
const notRunning = list.filter(({ name }) => !running.includes(name));
|
|
29
30
|
for (const app of notRunning) {
|
|
@@ -35,6 +36,9 @@ export async function startAll(_, cli) {
|
|
|
35
36
|
return true;
|
|
36
37
|
}
|
|
37
38
|
export async function refreshContainer(options, { run }) {
|
|
39
|
+
if (!options.name) {
|
|
40
|
+
throw new Error('Name is required');
|
|
41
|
+
}
|
|
38
42
|
const { name } = options;
|
|
39
43
|
const container = await findContainer(name);
|
|
40
44
|
await run('dx.pull', { image: container.image });
|
|
@@ -47,17 +51,21 @@ export async function startContainer(options, { run }) {
|
|
|
47
51
|
if (!name) {
|
|
48
52
|
throw new Error('Name is required');
|
|
49
53
|
}
|
|
50
|
-
const vars = (await run('env.show', {
|
|
54
|
+
const vars = (await run('env.show', { name }));
|
|
51
55
|
const { env, envKeys } = await getEnvVars(vars);
|
|
52
56
|
const container = await findContainer(name);
|
|
53
57
|
const volumes = addExecFlag(container.volumes, 'v');
|
|
54
58
|
const ports = getPorts([...container.ports.split(','), env.PORT + ':' + env.PORT]);
|
|
55
59
|
if (container.host) {
|
|
56
|
-
|
|
57
|
-
await run('px.
|
|
58
|
-
await run('dns.add', { domain
|
|
60
|
+
const domain = container.host;
|
|
61
|
+
await run('px.update', { domain, target: 'http://localhost:' + env.PORT });
|
|
62
|
+
await run('dns.add', { domain });
|
|
59
63
|
await run('dns.reload', {});
|
|
60
64
|
}
|
|
65
|
+
const dnsOption = [];
|
|
66
|
+
if (getConfig('dns')) {
|
|
67
|
+
dnsOption.push('--dns=' + getConfig('dns'));
|
|
68
|
+
}
|
|
61
69
|
const execArgs = [
|
|
62
70
|
'run',
|
|
63
71
|
'--detach',
|
|
@@ -65,12 +73,13 @@ export async function startContainer(options, { run }) {
|
|
|
65
73
|
'always',
|
|
66
74
|
'--name',
|
|
67
75
|
name,
|
|
76
|
+
...dnsOption,
|
|
68
77
|
...volumes,
|
|
69
78
|
...ports,
|
|
70
79
|
...envKeys.map((e) => '-e' + e),
|
|
71
80
|
container.image,
|
|
72
81
|
];
|
|
73
|
-
const output = await exec('docker', execArgs, { env });
|
|
82
|
+
const output = await exec('docker', execArgs.filter(Boolean), { env });
|
|
74
83
|
if (!output.ok) {
|
|
75
84
|
throw new Error('Failed to start ' + name);
|
|
76
85
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { init } from '@cloud-cli/cli';
|
|
|
2
2
|
import { getRunningContainers, getLogs, startContainer, stopContainer, refreshContainer, startAll } from './containers.js';
|
|
3
3
|
import { addContainer, removeContainer, listContainers, updateContainer, getContainer } from './store.js';
|
|
4
4
|
import { pull, prune } from './images.js';
|
|
5
|
+
import { Config } from './config';
|
|
6
|
+
export { Config } from './config';
|
|
5
7
|
declare const _default: {
|
|
6
8
|
pull: typeof pull;
|
|
7
9
|
prune: typeof prune;
|
|
@@ -16,6 +18,6 @@ declare const _default: {
|
|
|
16
18
|
stop: typeof stopContainer;
|
|
17
19
|
ps: typeof getRunningContainers;
|
|
18
20
|
logs: typeof getLogs;
|
|
19
|
-
[init](): Promise<void>;
|
|
21
|
+
[init](config?: Config): Promise<void>;
|
|
20
22
|
};
|
|
21
23
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Container } from './store.js';
|
|
|
4
4
|
import { getRunningContainers, getLogs, startContainer, stopContainer, refreshContainer, startAll } from './containers.js';
|
|
5
5
|
import { addContainer, removeContainer, listContainers, updateContainer, getContainer } from './store.js';
|
|
6
6
|
import { pull, prune } from './images.js';
|
|
7
|
+
import { setConfig } from './config';
|
|
7
8
|
async function initResource() {
|
|
8
9
|
Resource.use(new SQLiteDriver());
|
|
9
10
|
await Resource.create(Container);
|
|
@@ -22,7 +23,8 @@ export default {
|
|
|
22
23
|
stop: stopContainer,
|
|
23
24
|
ps: getRunningContainers,
|
|
24
25
|
logs: getLogs,
|
|
25
|
-
async [init]() {
|
|
26
|
+
async [init](config) {
|
|
27
|
+
setConfig(config);
|
|
26
28
|
await initResource();
|
|
27
29
|
}
|
|
28
30
|
};
|
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,10 @@ export async function updateContainer(options) {
|
|
|
83
83
|
await container.save();
|
|
84
84
|
return container;
|
|
85
85
|
}
|
|
86
|
-
export async function listContainers() {
|
|
87
|
-
const
|
|
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);
|
|
88
90
|
return list.sort((a, b) => Number(a.name > b.name) || -1);
|
|
89
91
|
}
|
|
90
92
|
export async function findContainer(name) {
|
|
@@ -93,9 +95,17 @@ export async function findContainer(name) {
|
|
|
93
95
|
}
|
|
94
96
|
const portTester = /^\d+:\d+$/;
|
|
95
97
|
function sanitisePorts(ports) {
|
|
96
|
-
return ports
|
|
98
|
+
return ports
|
|
99
|
+
.split(optionSplitter)
|
|
100
|
+
.map((s) => s.trim())
|
|
101
|
+
.filter((s) => portTester.test(s))
|
|
102
|
+
.join(',');
|
|
97
103
|
}
|
|
98
104
|
const volumeTester = /^\S+:\S+$/;
|
|
99
105
|
function sanitiseVolumes(volumes) {
|
|
100
|
-
return volumes
|
|
106
|
+
return volumes
|
|
107
|
+
.split(optionSplitter)
|
|
108
|
+
.map((s) => s.trim())
|
|
109
|
+
.filter((s) => volumeTester.test(s))
|
|
110
|
+
.join(',');
|
|
101
111
|
}
|