@cloud-cli/dx 2.3.1 → 2.5.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 +10 -9
- package/dist/containers.d.ts +4 -0
- package/dist/containers.js +23 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# DX
|
|
2
2
|
|
|
3
3
|
Run Docker containers
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```sh
|
|
8
8
|
npm i @cloud-cli/dx
|
|
9
9
|
```
|
|
10
10
|
|
|
@@ -19,14 +19,15 @@ cy dx.start --name node-app
|
|
|
19
19
|
cy dx.logs --name node-app
|
|
20
20
|
cy dx.stop --name node-app
|
|
21
21
|
cy dx.remove --name node-app
|
|
22
|
+
cy dx.updateAll --image node:latest
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
## Options
|
|
25
26
|
|
|
26
|
-
| Option
|
|
27
|
-
|
|
28
|
-
| name
|
|
29
|
-
| image
|
|
30
|
-
| volumes | Comma-separated list of volume bindings
|
|
31
|
-
| port
|
|
32
|
-
| domain
|
|
27
|
+
| Option | Description |
|
|
28
|
+
| ------- | -------------------------------------------------------------------------------------------- |
|
|
29
|
+
| name | Required. Container name |
|
|
30
|
+
| image | Required: Container image |
|
|
31
|
+
| volumes | Comma-separated list of volume bindings |
|
|
32
|
+
| port | Empty = random port. `:port` = random host port. `number` = fixed port on host and container |
|
|
33
|
+
| domain | Domain to bind this container to. Requires `@cloud-cli/px` and `@cloud-cli/dns` |
|
package/dist/containers.d.ts
CHANGED
|
@@ -5,11 +5,15 @@ export declare function getAllContainers(): Promise<NameAndStatus[]>;
|
|
|
5
5
|
export declare function getLogs(options: GetLogsOptions): Promise<string>;
|
|
6
6
|
export declare function renameContainer(options: RenameOptions): Container;
|
|
7
7
|
export declare function startAll(_: any, cli: any): Promise<boolean>;
|
|
8
|
+
export declare function updateAll(options: {
|
|
9
|
+
image: string;
|
|
10
|
+
}, cli: any): Promise<any[]>;
|
|
8
11
|
export declare function refreshContainer(options: ContainerName, { run }: ServerParams): Promise<void>;
|
|
9
12
|
export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
|
10
13
|
export interface StartOptions {
|
|
11
14
|
worker?: boolean;
|
|
12
15
|
startArgs?: string;
|
|
13
16
|
}
|
|
17
|
+
export declare function runContainer(options: ContainerName & StartOptions, p: ServerParams): Promise<boolean>;
|
|
14
18
|
export declare function startContainer(options: ContainerName & StartOptions, { run }: ServerParams): Promise<boolean>;
|
|
15
19
|
export declare function stopContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
|
package/dist/containers.js
CHANGED
|
@@ -56,6 +56,20 @@ export async function startAll(_, cli) {
|
|
|
56
56
|
}
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
|
+
export async function updateAll(options, cli) {
|
|
60
|
+
const list = listContainers();
|
|
61
|
+
const affected = [];
|
|
62
|
+
for (const app of list) {
|
|
63
|
+
if (app.image !== options.image)
|
|
64
|
+
continue;
|
|
65
|
+
try {
|
|
66
|
+
await refreshContainer({ name: app.name }, cli);
|
|
67
|
+
affected.push(app.name);
|
|
68
|
+
}
|
|
69
|
+
catch { }
|
|
70
|
+
}
|
|
71
|
+
return affected;
|
|
72
|
+
}
|
|
59
73
|
export async function refreshContainer(options, { run }) {
|
|
60
74
|
readTargetName(options);
|
|
61
75
|
if (!options.name) {
|
|
@@ -87,6 +101,9 @@ async function getPorts(container) {
|
|
|
87
101
|
const port = Number(container.port);
|
|
88
102
|
return [port, port];
|
|
89
103
|
}
|
|
104
|
+
export function runContainer(options, p) {
|
|
105
|
+
return startContainer({ ...options, worker: true }, p);
|
|
106
|
+
}
|
|
90
107
|
export async function startContainer(options, { run }) {
|
|
91
108
|
readTargetName(options);
|
|
92
109
|
const { name } = options;
|
|
@@ -106,9 +123,9 @@ export async function startContainer(options, { run }) {
|
|
|
106
123
|
const extraArgs = [];
|
|
107
124
|
const config = await getConfig('dx');
|
|
108
125
|
if (container.domain && !options.worker) {
|
|
109
|
-
const [domain, path = ''] = container.domain.split(
|
|
110
|
-
await run(
|
|
111
|
-
extraArgs.push(
|
|
126
|
+
const [domain, path = ''] = container.domain.split('/');
|
|
127
|
+
await run('dns.add', { domain });
|
|
128
|
+
extraArgs.push('--label', 'px:host=' + domain, '--label', 'px:path=' + path);
|
|
112
129
|
}
|
|
113
130
|
if (config.dns) {
|
|
114
131
|
extraArgs.push('--dns=' + config.dns);
|
|
@@ -129,7 +146,8 @@ export async function startContainer(options, { run }) {
|
|
|
129
146
|
container.image,
|
|
130
147
|
];
|
|
131
148
|
if (options.startArgs) {
|
|
132
|
-
|
|
149
|
+
const p = options.startArgs;
|
|
150
|
+
execArgs.push(...(Array.isArray(p) ? p : JSON.parse(p)));
|
|
133
151
|
}
|
|
134
152
|
const output = await exec('docker', execArgs.filter(Boolean), { env });
|
|
135
153
|
if (!output.ok) {
|
|
@@ -152,7 +170,7 @@ export async function stopContainer(options, { run }) {
|
|
|
152
170
|
}
|
|
153
171
|
await exec('docker', ['stop', '-t', '5', name]);
|
|
154
172
|
await exec('docker', ['rm', name]);
|
|
155
|
-
const containers = [findContainer(name)].filter(c => c && c.domain);
|
|
173
|
+
const containers = [findContainer(name)].filter((c) => c && c.domain);
|
|
156
174
|
for (const container of containers) {
|
|
157
175
|
await run('dns.remove', { domain: container.domain });
|
|
158
176
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getLogs, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer } from "./containers.js";
|
|
1
|
+
import { getLogs, refreshContainer, restartContainer, startAll, updateAll, startContainer, stopContainer, renameContainer, runContainer } 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";
|
|
@@ -16,7 +16,9 @@ declare const _default: {
|
|
|
16
16
|
refresh: typeof refreshContainer;
|
|
17
17
|
update: typeof updateContainer;
|
|
18
18
|
startAll: typeof startAll;
|
|
19
|
+
updateAll: typeof updateAll;
|
|
19
20
|
start: typeof startContainer;
|
|
21
|
+
run: typeof runContainer;
|
|
20
22
|
stop: typeof stopContainer;
|
|
21
23
|
restart: typeof restartContainer;
|
|
22
24
|
ps: typeof ps;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, startContainer, stopContainer, renameContainer, } from "./containers.js";
|
|
1
|
+
import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, updateAll, startContainer, stopContainer, renameContainer, runContainer, } from "./containers.js";
|
|
2
2
|
import { prune, pull } from "./images.js";
|
|
3
3
|
import { addContainer, getContainer, listContainers, removeContainer, updateContainer, } from "./store.js";
|
|
4
4
|
function ps(options = {}) {
|
|
@@ -18,7 +18,9 @@ export default {
|
|
|
18
18
|
refresh: refreshContainer,
|
|
19
19
|
update: updateContainer,
|
|
20
20
|
startAll,
|
|
21
|
+
updateAll,
|
|
21
22
|
start: startContainer,
|
|
23
|
+
run: runContainer,
|
|
22
24
|
stop: stopContainer,
|
|
23
25
|
restart: restartContainer,
|
|
24
26
|
ps: ps,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/dx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Docker container management",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
"test": "vitest",
|
|
11
11
|
"build": "rm -rf ./dist/* && tsc"
|
|
12
12
|
},
|
|
13
|
-
"keywords": [
|
|
13
|
+
"keywords": [
|
|
14
|
+
"cloudy"
|
|
15
|
+
],
|
|
14
16
|
"license": "MIT",
|
|
15
17
|
"author": "Darlan Alves <me@darlanalv.es>",
|
|
16
18
|
"devDependencies": {
|