@cloud-cli/dx 1.0.0 → 1.0.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/dist/containers.d.ts +2 -1
- package/dist/containers.js +16 -12
- package/dist/images.js +0 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/store.d.ts +1 -0
- package/dist/store.js +11 -1
- package/package.json +1 -1
package/dist/containers.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export declare function getLogs({ name, lines }: GetLogsOptions): Promise<string
|
|
|
7
7
|
interface RunOptions {
|
|
8
8
|
name: string;
|
|
9
9
|
env?: string[];
|
|
10
|
+
ports?: string;
|
|
10
11
|
}
|
|
11
|
-
export declare function
|
|
12
|
+
export declare function startContainer(options: RunOptions): Promise<boolean>;
|
|
12
13
|
export interface StopOptions {
|
|
13
14
|
name: string;
|
|
14
15
|
}
|
package/dist/containers.js
CHANGED
|
@@ -21,30 +21,34 @@ export async function getLogs({ name, lines }) {
|
|
|
21
21
|
}
|
|
22
22
|
return '';
|
|
23
23
|
}
|
|
24
|
-
const defaultRunOptions = { env: [] };
|
|
25
|
-
export async function
|
|
24
|
+
const defaultRunOptions = { ports: '', env: [] };
|
|
25
|
+
export async function startContainer(options) {
|
|
26
26
|
options = { ...defaultRunOptions, ...options };
|
|
27
27
|
const { name } = options;
|
|
28
28
|
if (!name) {
|
|
29
29
|
throw new Error('Name is required');
|
|
30
30
|
}
|
|
31
|
+
const env = [];
|
|
32
|
+
if (Array.isArray(options.env)) {
|
|
33
|
+
env.push(...options.env.flatMap((e) => ['-e', e]));
|
|
34
|
+
}
|
|
31
35
|
const container = await findContainer(name);
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.map((v) => `-v${v}`);
|
|
37
|
-
const ports = container.ports
|
|
38
|
-
.split(',')
|
|
39
|
-
.filter(Boolean)
|
|
40
|
-
.map((p) => `-p${p}`);
|
|
41
|
-
await exec('docker', ['run', '--rm', '--detach', '--name', name, ...volumes, ...ports, ...env, container.image]);
|
|
36
|
+
const volumes = addExecFlag(container.volumes, 'v');
|
|
37
|
+
const ports = addExecFlag(container.ports, 'p');
|
|
38
|
+
const extraPorts = addExecFlag(options.ports, 'p');
|
|
39
|
+
await exec('docker', ['run', '--rm', '--detach', '--name', name, ...volumes, ...ports, ...extraPorts, ...env, container.image]);
|
|
42
40
|
return true;
|
|
43
41
|
}
|
|
44
42
|
export async function stopContainer(options) {
|
|
45
43
|
await exec('docker', ['stop', '-t', '5', options.name]);
|
|
44
|
+
await exec('docker', ['rm', options.name]);
|
|
46
45
|
return true;
|
|
47
46
|
}
|
|
48
47
|
function getListFromString(string) {
|
|
49
48
|
return string.trim().split('\n').filter(Boolean);
|
|
50
49
|
}
|
|
50
|
+
function addExecFlag(string, flag) {
|
|
51
|
+
return string.split(',')
|
|
52
|
+
.filter(Boolean)
|
|
53
|
+
.map((p) => `-${flag}${p}`);
|
|
54
|
+
}
|
package/dist/images.js
CHANGED
|
@@ -2,10 +2,3 @@ import { exec } from '@cloud-cli/exec';
|
|
|
2
2
|
export async function pull(options) {
|
|
3
3
|
return (await exec('docker', ['pull', options.image])).ok;
|
|
4
4
|
}
|
|
5
|
-
/*
|
|
6
|
-
async getImages(): Promise<string[]> {
|
|
7
|
-
const list = await this.shellExec('docker', ['image', 'ls', '--format', '{{.Repository}}']);
|
|
8
|
-
|
|
9
|
-
return list.filter((s: string) => s !== '<none>');
|
|
10
|
-
}
|
|
11
|
-
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { init } from '@cloud-cli/cli';
|
|
2
|
-
import { getRunningContainers, getLogs,
|
|
2
|
+
import { getRunningContainers, getLogs, startContainer, stopContainer } from './containers.js';
|
|
3
3
|
import { addContainer, removeContainer, listContainers, updateContainer } from './store.js';
|
|
4
4
|
import { pull } from './images.js';
|
|
5
5
|
declare function reload(): Promise<void>;
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
remove: typeof removeContainer;
|
|
10
10
|
list: typeof listContainers;
|
|
11
11
|
update: typeof updateContainer;
|
|
12
|
-
|
|
12
|
+
start: typeof startContainer;
|
|
13
13
|
stop: typeof stopContainer;
|
|
14
14
|
ps: typeof getRunningContainers;
|
|
15
15
|
logs: typeof getLogs;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { init } from '@cloud-cli/cli';
|
|
2
2
|
import { Resource } from '@cloud-cli/store';
|
|
3
3
|
import { Container } from './store.js';
|
|
4
|
-
import { getRunningContainers, getLogs,
|
|
4
|
+
import { getRunningContainers, getLogs, startContainer, stopContainer } from './containers.js';
|
|
5
5
|
import { addContainer, removeContainer, listContainers, updateContainer } from './store.js';
|
|
6
6
|
import { pull } from './images.js';
|
|
7
7
|
async function reload() {
|
|
@@ -13,7 +13,7 @@ export default {
|
|
|
13
13
|
remove: removeContainer,
|
|
14
14
|
list: listContainers,
|
|
15
15
|
update: updateContainer,
|
|
16
|
-
|
|
16
|
+
start: startContainer,
|
|
17
17
|
stop: stopContainer,
|
|
18
18
|
ps: getRunningContainers,
|
|
19
19
|
logs: getLogs,
|
package/dist/store.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare function removeContainer(options: ContainerName): Promise<boolean
|
|
|
19
19
|
interface UpdateOptions extends ContainerName {
|
|
20
20
|
ports?: string;
|
|
21
21
|
volumes?: string;
|
|
22
|
+
image?: string;
|
|
22
23
|
}
|
|
23
24
|
export declare function updateContainer(options: UpdateOptions): Promise<Container>;
|
|
24
25
|
export declare function listContainers(): Promise<Container[]>;
|
package/dist/store.js
CHANGED
|
@@ -34,6 +34,10 @@ Container = __decorate([
|
|
|
34
34
|
export { Container };
|
|
35
35
|
export async function addContainer(options) {
|
|
36
36
|
const { name, image } = options;
|
|
37
|
+
if (!name)
|
|
38
|
+
throw new Error('Name required');
|
|
39
|
+
if (!image)
|
|
40
|
+
throw new Error('Image required');
|
|
37
41
|
const volumes = (options.volumes ? sanitiseVolumes(options.volumes) : '');
|
|
38
42
|
const ports = (options.ports ? sanitisePorts(options.ports) : '');
|
|
39
43
|
const container = new Container({ name, image, volumes, ports });
|
|
@@ -51,14 +55,20 @@ export async function removeContainer(options) {
|
|
|
51
55
|
}
|
|
52
56
|
const optionSplitter = /,\s*/;
|
|
53
57
|
export async function updateContainer(options) {
|
|
54
|
-
let { ports, volumes, name } = options;
|
|
58
|
+
let { ports, volumes, name, image } = options;
|
|
55
59
|
const container = await findContainer(name);
|
|
60
|
+
if (!container) {
|
|
61
|
+
throw new Error('Container not found');
|
|
62
|
+
}
|
|
56
63
|
if (ports) {
|
|
57
64
|
container.ports = sanitisePorts(ports);
|
|
58
65
|
}
|
|
59
66
|
if (volumes) {
|
|
60
67
|
container.volumes = sanitiseVolumes(volumes);
|
|
61
68
|
}
|
|
69
|
+
if (image) {
|
|
70
|
+
container.image = image;
|
|
71
|
+
}
|
|
62
72
|
await container.save();
|
|
63
73
|
return container;
|
|
64
74
|
}
|