@cloud-cli/dx 2.0.0 → 2.1.1
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 -1
- package/dist/containers.d.ts +2 -9
- package/dist/containers.js +16 -8
- package/dist/index.d.ts +5 -2
- package/dist/index.js +8 -2
- package/dist/store.d.ts +1 -1
- package/dist/store.js +6 -6
- package/dist/types.d.ts +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm i @cloud-cli/dx
|
|
|
14
14
|
cy dx.list
|
|
15
15
|
cy dx.prune
|
|
16
16
|
cy dx.pull --image node:latest
|
|
17
|
-
cy dx.add --name node-app --image node:latest --volumes 'volume:/container/path' --port '8080' --
|
|
17
|
+
cy dx.add --name node-app --image node:latest --volumes 'volume:/container/path' --port '8080' --domain 'foo.example.com'
|
|
18
18
|
cy dx.start --name node-app --env 'FOO=bar'
|
|
19
19
|
cy dx.logs --name node-app
|
|
20
20
|
cy dx.stop --name node-app
|
package/dist/containers.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { ServerParams } from '@cloud-cli/cli';
|
|
2
|
-
import {
|
|
2
|
+
import { ContainerName, GetLogsOptions, NameAndStatus } from './types.js';
|
|
3
3
|
export declare function getRunningContainers(): Promise<string[]>;
|
|
4
|
-
|
|
5
|
-
name: string;
|
|
6
|
-
lines?: string;
|
|
7
|
-
}
|
|
8
|
-
interface ContainerName extends ExtraOptions {
|
|
9
|
-
name: string;
|
|
10
|
-
}
|
|
4
|
+
export declare function getAllContainers(): Promise<NameAndStatus[]>;
|
|
11
5
|
export declare function getLogs(options: GetLogsOptions): Promise<string>;
|
|
12
6
|
export declare function startAll(_: any, cli: any): Promise<boolean>;
|
|
13
7
|
export declare function refreshContainer(options: ContainerName, { run }: ServerParams): Promise<void>;
|
|
14
8
|
export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
15
9
|
export declare function startContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
16
10
|
export declare function stopContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
17
|
-
export {};
|
package/dist/containers.js
CHANGED
|
@@ -7,7 +7,15 @@ export async function getRunningContainers() {
|
|
|
7
7
|
if (!ps.ok) {
|
|
8
8
|
throw new Error('Failed to list containers: ' + ps.stderr);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const list = getListFromString(ps.stdout).sort();
|
|
11
|
+
return list;
|
|
12
|
+
}
|
|
13
|
+
export async function getAllContainers() {
|
|
14
|
+
const running = await getRunningContainers();
|
|
15
|
+
return listContainers().map((c) => ({
|
|
16
|
+
name: c.name,
|
|
17
|
+
status: running.includes(c.name) ? 'running' : 'stopped',
|
|
18
|
+
}));
|
|
11
19
|
}
|
|
12
20
|
export async function getLogs(options) {
|
|
13
21
|
readTargetName(options);
|
|
@@ -23,8 +31,8 @@ export async function getLogs(options) {
|
|
|
23
31
|
return [sh.stdout, sh.stderr].join('\n\n').trim();
|
|
24
32
|
}
|
|
25
33
|
export async function startAll(_, cli) {
|
|
26
|
-
const list =
|
|
27
|
-
const running = await getRunningContainers();
|
|
34
|
+
const list = listContainers();
|
|
35
|
+
const running = (await getRunningContainers());
|
|
28
36
|
const notRunning = list.filter(({ name }) => !running.includes(name));
|
|
29
37
|
for (const app of notRunning) {
|
|
30
38
|
try {
|
|
@@ -61,11 +69,11 @@ export async function startContainer(options, { run }) {
|
|
|
61
69
|
}
|
|
62
70
|
const vars = (await run('env.show', { name }));
|
|
63
71
|
const { env, envKeys } = await getEnvVars(vars);
|
|
64
|
-
const container =
|
|
72
|
+
const container = findContainer(name);
|
|
65
73
|
const volumes = addExecFlag(container.volumes, 'v');
|
|
66
74
|
const ports = ['-p' + env.PORT + ':' + (container.port || env.PORT)];
|
|
67
|
-
if (container.
|
|
68
|
-
const domain = container.
|
|
75
|
+
if (container.domain) {
|
|
76
|
+
const [domain] = container.domain.split('/');
|
|
69
77
|
await run('px.update', { domain, target: 'http://localhost:' + env.PORT });
|
|
70
78
|
await run('dns.add', { domain });
|
|
71
79
|
}
|
|
@@ -105,9 +113,9 @@ export async function stopContainer(options, { run }) {
|
|
|
105
113
|
}
|
|
106
114
|
await exec('docker', ['stop', '-t', '5', name]);
|
|
107
115
|
await exec('docker', ['rm', name]);
|
|
108
|
-
const containers = [
|
|
116
|
+
const containers = [findContainer(name)].filter(Boolean);
|
|
109
117
|
for (const container of containers) {
|
|
110
|
-
await run('dns.remove', { domain: container.
|
|
118
|
+
await run('dns.remove', { domain: container.domain });
|
|
111
119
|
}
|
|
112
120
|
return true;
|
|
113
121
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { getLogs,
|
|
1
|
+
import { getLogs, refreshContainer, restartContainer, startAll, startContainer, stopContainer } 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';
|
|
5
|
+
declare function ps(options?: {
|
|
6
|
+
status?: boolean;
|
|
7
|
+
}): Promise<string[]> | Promise<import("./types.js").NameAndStatus[]>;
|
|
5
8
|
declare const _default: {
|
|
6
9
|
pull: typeof pull;
|
|
7
10
|
prune: typeof prune;
|
|
@@ -15,7 +18,7 @@ declare const _default: {
|
|
|
15
18
|
start: typeof startContainer;
|
|
16
19
|
stop: typeof stopContainer;
|
|
17
20
|
restart: typeof restartContainer;
|
|
18
|
-
ps: typeof
|
|
21
|
+
ps: typeof ps;
|
|
19
22
|
logs: typeof getLogs;
|
|
20
23
|
};
|
|
21
24
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer } from './containers.js';
|
|
1
|
+
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer } from './containers.js';
|
|
2
2
|
import { prune, pull } from './images.js';
|
|
3
3
|
import { addContainer, getContainer, listContainers, removeContainer, updateContainer } from './store.js';
|
|
4
|
+
function ps(options = {}) {
|
|
5
|
+
if (options.status) {
|
|
6
|
+
return getAllContainers();
|
|
7
|
+
}
|
|
8
|
+
return getRunningContainers();
|
|
9
|
+
}
|
|
4
10
|
export default {
|
|
5
11
|
pull,
|
|
6
12
|
prune,
|
|
@@ -14,6 +20,6 @@ export default {
|
|
|
14
20
|
start: startContainer,
|
|
15
21
|
stop: stopContainer,
|
|
16
22
|
restart: restartContainer,
|
|
17
|
-
ps:
|
|
23
|
+
ps: ps,
|
|
18
24
|
logs: getLogs,
|
|
19
25
|
};
|
package/dist/store.d.ts
CHANGED
package/dist/store.js
CHANGED
|
@@ -11,8 +11,8 @@ export function addContainer(options) {
|
|
|
11
11
|
throw new Error('Image required');
|
|
12
12
|
const volumes = options.volumes ? sanitiseVolumes(options.volumes) : '';
|
|
13
13
|
const port = options.port || '';
|
|
14
|
-
const
|
|
15
|
-
const container = { name, image, volumes, port,
|
|
14
|
+
const domain = options.domain || '';
|
|
15
|
+
const container = { name, image, volumes, port, domain };
|
|
16
16
|
set(name, container);
|
|
17
17
|
return container;
|
|
18
18
|
}
|
|
@@ -31,7 +31,7 @@ export function getContainer(options) {
|
|
|
31
31
|
const optionSplitter = /,\s*/;
|
|
32
32
|
export function updateContainer(options) {
|
|
33
33
|
readTargetName(options);
|
|
34
|
-
let { port, volumes, name, image,
|
|
34
|
+
let { port, volumes, name, image, domain } = options;
|
|
35
35
|
const container = get(name);
|
|
36
36
|
if (!container) {
|
|
37
37
|
throw new Error('Container not found');
|
|
@@ -45,14 +45,14 @@ export function updateContainer(options) {
|
|
|
45
45
|
if (image) {
|
|
46
46
|
container.image = image;
|
|
47
47
|
}
|
|
48
|
-
if (
|
|
49
|
-
container.
|
|
48
|
+
if (domain) {
|
|
49
|
+
container.domain = domain;
|
|
50
50
|
}
|
|
51
51
|
set(container.name, container);
|
|
52
52
|
return container;
|
|
53
53
|
}
|
|
54
54
|
export function listContainers(options = {}) {
|
|
55
|
-
const keys = ['name', 'image', '
|
|
55
|
+
const keys = ['name', 'image', 'domain', 'port', 'volumes'];
|
|
56
56
|
const list = getAll();
|
|
57
57
|
const filtered = keys.reduce((list, key) => {
|
|
58
58
|
if (options[key]) {
|
package/dist/types.d.ts
CHANGED
|
@@ -5,10 +5,21 @@ export interface Config {
|
|
|
5
5
|
export interface Container {
|
|
6
6
|
name: string;
|
|
7
7
|
image: string;
|
|
8
|
-
|
|
8
|
+
domain: string;
|
|
9
9
|
port: string;
|
|
10
10
|
volumes: string;
|
|
11
11
|
}
|
|
12
|
+
export interface NameAndStatus {
|
|
13
|
+
name: string;
|
|
14
|
+
status: string;
|
|
15
|
+
}
|
|
12
16
|
export interface ExtraOptions {
|
|
13
17
|
_?: string[];
|
|
14
18
|
}
|
|
19
|
+
export interface GetLogsOptions extends ExtraOptions {
|
|
20
|
+
name: string;
|
|
21
|
+
lines?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ContainerName extends ExtraOptions {
|
|
24
|
+
name: string;
|
|
25
|
+
}
|