@cloud-cli/dx 2.2.2 → 2.3.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 +7 -2
- package/dist/containers.js +20 -5
- package/dist/index.d.ts +5 -4
- package/dist/index.js +4 -3
- package/dist/store.d.ts +3 -0
- package/dist/store.js +21 -9
- package/dist/types.d.ts +6 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +3 -0
- package/package.json +4 -6
package/dist/containers.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { ServerParams } from '@cloud-cli/cli';
|
|
2
|
-
import { ContainerName, GetLogsOptions, NameAndStatus } from './types.js';
|
|
2
|
+
import { Container, ContainerName, GetLogsOptions, NameAndStatus, RenameOptions } from './types.js';
|
|
3
3
|
export declare function getRunningContainers(): Promise<string[]>;
|
|
4
4
|
export declare function getAllContainers(): Promise<NameAndStatus[]>;
|
|
5
5
|
export declare function getLogs(options: GetLogsOptions): Promise<string>;
|
|
6
|
+
export declare function renameContainer(options: RenameOptions): Container;
|
|
6
7
|
export declare function startAll(_: any, cli: any): Promise<boolean>;
|
|
7
8
|
export declare function refreshContainer(options: ContainerName, { run }: ServerParams): Promise<void>;
|
|
8
9
|
export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
9
|
-
export
|
|
10
|
+
export interface StartOptions {
|
|
11
|
+
worker?: boolean;
|
|
12
|
+
startArgs?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function startContainer(options: ContainerName & StartOptions, { run }: ServerParams): Promise<boolean>;
|
|
10
15
|
export declare function stopContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
package/dist/containers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { exec } from '@cloud-cli/exec';
|
|
2
2
|
import { getConfig, logInfo, logError } from '@cloud-cli/cli';
|
|
3
|
-
import { findContainer, listContainers } from './store.js';
|
|
4
|
-
import { addExecFlag, getEnvVars, getListFromString, readTargetName } from './utils.js';
|
|
3
|
+
import { findContainer, listContainers, rename } from './store.js';
|
|
4
|
+
import { addExecFlag, getEnvVars, getListFromString, readTargetName, readTargetNewName } from './utils.js';
|
|
5
5
|
import getPort from 'get-port';
|
|
6
6
|
export async function getRunningContainers() {
|
|
7
7
|
const ps = await exec('docker', ['ps', '--format', '{{.Names}}']);
|
|
@@ -31,6 +31,19 @@ export async function getLogs(options) {
|
|
|
31
31
|
const sh = await exec('docker', args);
|
|
32
32
|
return [sh.stdout, sh.stderr].join('\n\n').trim();
|
|
33
33
|
}
|
|
34
|
+
export function renameContainer(options) {
|
|
35
|
+
readTargetName(options);
|
|
36
|
+
readTargetNewName(options);
|
|
37
|
+
const { name, newName } = options;
|
|
38
|
+
if (!name || !newName) {
|
|
39
|
+
throw new Error('Name and new name required');
|
|
40
|
+
}
|
|
41
|
+
const container = findContainer(name);
|
|
42
|
+
if (!container) {
|
|
43
|
+
throw new Error('Container not found: ' + name);
|
|
44
|
+
}
|
|
45
|
+
return rename(name, newName);
|
|
46
|
+
}
|
|
34
47
|
export async function startAll(_, cli) {
|
|
35
48
|
const list = listContainers();
|
|
36
49
|
const running = (await getRunningContainers());
|
|
@@ -92,7 +105,7 @@ export async function startContainer(options, { run }) {
|
|
|
92
105
|
const portBindings = addExecFlag([ports.join(':')], 'p');
|
|
93
106
|
const extraArgs = [];
|
|
94
107
|
const config = await getConfig('dx');
|
|
95
|
-
if (container.domain) {
|
|
108
|
+
if (container.domain && !options.worker) {
|
|
96
109
|
const [domain, path = ''] = container.domain.split("/");
|
|
97
110
|
await run("dns.add", { domain });
|
|
98
111
|
extraArgs.push("--label", "px:host=" + domain, "--label", "px:path=" + path);
|
|
@@ -106,8 +119,7 @@ export async function startContainer(options, { run }) {
|
|
|
106
119
|
const execArgs = [
|
|
107
120
|
'run',
|
|
108
121
|
'--detach',
|
|
109
|
-
'--restart',
|
|
110
|
-
'always',
|
|
122
|
+
...(!options.worker ? ['--restart', 'always'] : []),
|
|
111
123
|
'--name',
|
|
112
124
|
name,
|
|
113
125
|
...extraArgs,
|
|
@@ -116,6 +128,9 @@ export async function startContainer(options, { run }) {
|
|
|
116
128
|
...addExecFlag(envKeys, 'e'),
|
|
117
129
|
container.image,
|
|
118
130
|
];
|
|
131
|
+
if (options.startArgs) {
|
|
132
|
+
execArgs.push(...JSON.parse(options.startArgs));
|
|
133
|
+
}
|
|
119
134
|
const output = await exec('docker', execArgs.filter(Boolean), { env });
|
|
120
135
|
if (!output.ok) {
|
|
121
136
|
const e = 'Failed to start container ' + name;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getLogs, refreshContainer, restartContainer, startAll, startContainer, stopContainer } from
|
|
2
|
-
import { prune, pull } from
|
|
3
|
-
import { addContainer, getContainer, listContainers, removeContainer, updateContainer } from
|
|
4
|
-
export type { Config } from
|
|
1
|
+
import { getLogs, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer } from "./containers.js";
|
|
2
|
+
import { prune, pull } from "./images.js";
|
|
3
|
+
import { addContainer, getContainer, listContainers, removeContainer, updateContainer } from "./store.js";
|
|
4
|
+
export type { Config } from "./types.js";
|
|
5
5
|
declare function ps(options?: {
|
|
6
6
|
status?: boolean;
|
|
7
7
|
}): Promise<string[]> | Promise<import("./types.js").NameAndStatus[]>;
|
|
@@ -10,6 +10,7 @@ declare const _default: {
|
|
|
10
10
|
prune: typeof prune;
|
|
11
11
|
add: typeof addContainer;
|
|
12
12
|
remove: typeof removeContainer;
|
|
13
|
+
rename: typeof renameContainer;
|
|
13
14
|
get: typeof getContainer;
|
|
14
15
|
list: typeof listContainers;
|
|
15
16
|
refresh: typeof refreshContainer;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer } from
|
|
2
|
-
import { prune, pull } from
|
|
3
|
-
import { addContainer, getContainer, listContainers, removeContainer, updateContainer } from
|
|
1
|
+
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer, } from "./containers.js";
|
|
2
|
+
import { prune, pull } from "./images.js";
|
|
3
|
+
import { addContainer, getContainer, listContainers, removeContainer, updateContainer, } from "./store.js";
|
|
4
4
|
function ps(options = {}) {
|
|
5
5
|
if (options.status) {
|
|
6
6
|
return getAllContainers();
|
|
@@ -12,6 +12,7 @@ export default {
|
|
|
12
12
|
prune,
|
|
13
13
|
add: addContainer,
|
|
14
14
|
remove: removeContainer,
|
|
15
|
+
rename: renameContainer,
|
|
15
16
|
get: getContainer,
|
|
16
17
|
list: listContainers,
|
|
17
18
|
refresh: refreshContainer,
|
package/dist/store.d.ts
CHANGED
|
@@ -7,12 +7,15 @@ interface ContainerUpdateOptions extends ContainerName {
|
|
|
7
7
|
domain?: string;
|
|
8
8
|
volumes?: string;
|
|
9
9
|
port?: string;
|
|
10
|
+
worker?: boolean;
|
|
11
|
+
startArgs?: string;
|
|
10
12
|
}
|
|
11
13
|
type ContainerListOptions = Partial<Container>;
|
|
12
14
|
export declare function addContainer(options: ContainerUpdateOptions): Container;
|
|
13
15
|
export declare function removeContainer(options: ContainerName): boolean;
|
|
14
16
|
export declare function getContainer(options: ContainerName): Container;
|
|
15
17
|
export declare function updateContainer(options: Partial<ContainerUpdateOptions>): Container;
|
|
18
|
+
export declare function rename(name: string, newName: string): Container;
|
|
16
19
|
export declare function listContainers(options?: ContainerListOptions): Container[];
|
|
17
20
|
export declare function findContainer(name: string): Container;
|
|
18
21
|
export {};
|
package/dist/store.js
CHANGED
|
@@ -10,9 +10,8 @@ export function addContainer(options) {
|
|
|
10
10
|
if (!image)
|
|
11
11
|
throw new Error('Image required');
|
|
12
12
|
const volumes = options.volumes ? sanitiseVolumes(options.volumes) : '';
|
|
13
|
-
const port =
|
|
14
|
-
const
|
|
15
|
-
const container = { name, image, volumes, port, domain };
|
|
13
|
+
const { port = '', domain = '', worker = false, startArgs = '' } = options;
|
|
14
|
+
const container = { name, image, volumes, port, domain, worker, startArgs };
|
|
16
15
|
set(name, container);
|
|
17
16
|
return container;
|
|
18
17
|
}
|
|
@@ -31,32 +30,45 @@ export function getContainer(options) {
|
|
|
31
30
|
const optionSplitter = /,\s*/;
|
|
32
31
|
export function updateContainer(options) {
|
|
33
32
|
readTargetName(options);
|
|
34
|
-
let { port, volumes, name, image, domain } = options;
|
|
33
|
+
let { port, volumes, name, image, domain, startArgs, worker } = options;
|
|
35
34
|
const container = get(name);
|
|
36
35
|
if (!container) {
|
|
37
36
|
throw new Error('Container not found');
|
|
38
37
|
}
|
|
39
|
-
if (port) {
|
|
38
|
+
if (port !== undefined) {
|
|
40
39
|
container.port = port;
|
|
41
40
|
}
|
|
42
|
-
if (volumes) {
|
|
41
|
+
if (volumes !== undefined) {
|
|
43
42
|
container.volumes = sanitiseVolumes(volumes);
|
|
44
43
|
}
|
|
45
|
-
if (image) {
|
|
44
|
+
if (image !== undefined) {
|
|
46
45
|
container.image = image;
|
|
47
46
|
}
|
|
48
|
-
if (domain) {
|
|
47
|
+
if (domain !== undefined) {
|
|
49
48
|
container.domain = domain;
|
|
50
49
|
}
|
|
50
|
+
if (startArgs !== undefined) {
|
|
51
|
+
container.startArgs = startArgs;
|
|
52
|
+
}
|
|
53
|
+
if (worker !== undefined) {
|
|
54
|
+
container.worker = worker;
|
|
55
|
+
}
|
|
51
56
|
set(container.name, container);
|
|
52
57
|
return container;
|
|
53
58
|
}
|
|
59
|
+
export function rename(name, newName) {
|
|
60
|
+
const container = get(name);
|
|
61
|
+
container.name = newName;
|
|
62
|
+
set(newName, container);
|
|
63
|
+
remove(name);
|
|
64
|
+
return container;
|
|
65
|
+
}
|
|
54
66
|
export function listContainers(options = {}) {
|
|
55
67
|
const keys = ['name', 'image', 'domain', 'port', 'volumes'];
|
|
56
68
|
const list = getAll();
|
|
57
69
|
const filtered = keys.reduce((list, key) => {
|
|
58
70
|
if (options[key]) {
|
|
59
|
-
return list.filter((c) => String(c[key]).toLowerCase().includes(options[key].toLowerCase()));
|
|
71
|
+
return list.filter((c) => String(c[key]).toLowerCase().includes(String(options[key]).toLowerCase()));
|
|
60
72
|
}
|
|
61
73
|
return list;
|
|
62
74
|
}, list);
|
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface Container {
|
|
|
8
8
|
domain: string;
|
|
9
9
|
port: string;
|
|
10
10
|
volumes: string;
|
|
11
|
+
worker: boolean;
|
|
12
|
+
startArgs: string;
|
|
11
13
|
}
|
|
12
14
|
export interface NameAndStatus {
|
|
13
15
|
name: string;
|
|
@@ -23,3 +25,7 @@ export interface GetLogsOptions extends ExtraOptions {
|
|
|
23
25
|
export interface ContainerName extends ExtraOptions {
|
|
24
26
|
name: string;
|
|
25
27
|
}
|
|
28
|
+
export interface RenameOptions extends ExtraOptions {
|
|
29
|
+
name: string;
|
|
30
|
+
newName: string;
|
|
31
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export declare function getEnvVars(vars: EnvList): Promise<{
|
|
|
12
12
|
export declare function getListFromString(string: string): string[];
|
|
13
13
|
export declare function addExecFlag(list: string[], flag: string): string[];
|
|
14
14
|
export declare function readTargetName(args: any): void;
|
|
15
|
+
export declare function readTargetNewName(args: any): void;
|
|
15
16
|
export declare function readTargetImage(args: any): void;
|
package/dist/utils.js
CHANGED
|
@@ -18,6 +18,9 @@ export function addExecFlag(list, flag) {
|
|
|
18
18
|
export function readTargetName(args) {
|
|
19
19
|
readPositionalArgs(args, 'name');
|
|
20
20
|
}
|
|
21
|
+
export function readTargetNewName(args) {
|
|
22
|
+
readPositionalArgs(args, 'newName');
|
|
23
|
+
}
|
|
21
24
|
export function readTargetImage(args) {
|
|
22
25
|
readPositionalArgs(args, 'image');
|
|
23
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/dx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Docker container management",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,18 +10,16 @@
|
|
|
10
10
|
"test": "vitest",
|
|
11
11
|
"build": "rm -rf ./dist/* && tsc"
|
|
12
12
|
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"cloudy"
|
|
15
|
-
],
|
|
13
|
+
"keywords": ["cloudy"],
|
|
16
14
|
"license": "MIT",
|
|
17
15
|
"author": "Darlan Alves <me@darlanalv.es>",
|
|
18
16
|
"devDependencies": {
|
|
19
17
|
"@cloud-cli/prettier-config": "^1.0.0",
|
|
20
18
|
"@cloud-cli/typescript-config": "^1.0.1",
|
|
21
19
|
"@types/node": "^20.12.8",
|
|
22
|
-
"@vitest/coverage-v8": "^1.
|
|
20
|
+
"@vitest/coverage-v8": "^3.1.1",
|
|
23
21
|
"typescript": "^5.4.5",
|
|
24
|
-
"vitest": "^1.
|
|
22
|
+
"vitest": "^3.1.1"
|
|
25
23
|
},
|
|
26
24
|
"repository": {
|
|
27
25
|
"type": "git",
|