@cloud-cli/dx 2.1.4 → 2.2.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/README.md +12 -2
- package/dist/containers.js +16 -4
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -14,9 +14,19 @@ 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 '
|
|
18
|
-
cy dx.start --name node-app
|
|
17
|
+
cy dx.add --name node-app --image node:latest --volumes 'volume:/container/path' --port ':80' --domain 'foo.example.com'
|
|
18
|
+
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
22
|
```
|
|
23
|
+
|
|
24
|
+
## Options
|
|
25
|
+
|
|
26
|
+
| Option | Description |
|
|
27
|
+
|-|-|
|
|
28
|
+
| name | Required. Container name |
|
|
29
|
+
| image | Required: Container image |
|
|
30
|
+
| volumes | Comma-separated list of volume bindings |
|
|
31
|
+
| port | Empty = random port. `:port` = random host port. `number` = fixed port on host and container |
|
|
32
|
+
| domain | Domain to bind this container to. Requires `@cloud-cli/px` and `@cloud-cli/dns` |
|
package/dist/containers.js
CHANGED
|
@@ -62,6 +62,18 @@ export async function restartContainer(options, { run }) {
|
|
|
62
62
|
await run('dx.start', { name });
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
|
+
async function getPorts(container) {
|
|
66
|
+
if (!container.port) {
|
|
67
|
+
const port = await getPort();
|
|
68
|
+
return [port, port];
|
|
69
|
+
}
|
|
70
|
+
if (container.port.startsWith(':')) {
|
|
71
|
+
const port = await getPort();
|
|
72
|
+
return [port, Number(container.port.slice(1))];
|
|
73
|
+
}
|
|
74
|
+
const port = Number(container.port);
|
|
75
|
+
return [port, port];
|
|
76
|
+
}
|
|
65
77
|
export async function startContainer(options, { run }) {
|
|
66
78
|
readTargetName(options);
|
|
67
79
|
const { name } = options;
|
|
@@ -73,11 +85,11 @@ export async function startContainer(options, { run }) {
|
|
|
73
85
|
throw new Error('Container not found: ' + name);
|
|
74
86
|
}
|
|
75
87
|
const vars = (await run('env.show', { name }));
|
|
76
|
-
const
|
|
77
|
-
vars.push({ key: 'PORT', value:
|
|
88
|
+
const ports = await getPorts(container);
|
|
89
|
+
vars.push({ key: 'PORT', value: String(ports[1]) });
|
|
78
90
|
const { env, envKeys } = await getEnvVars(vars);
|
|
79
91
|
const volumes = addExecFlag(container.volumes.split(','), 'v');
|
|
80
|
-
const
|
|
92
|
+
const portBindings = addExecFlag([ports.join(':')], 'p');
|
|
81
93
|
if (container.domain) {
|
|
82
94
|
const [domain] = container.domain.split('/');
|
|
83
95
|
await run('px.update', { domain, target: 'http://localhost:' + env.PORT });
|
|
@@ -100,7 +112,7 @@ export async function startContainer(options, { run }) {
|
|
|
100
112
|
name,
|
|
101
113
|
...extraArgs,
|
|
102
114
|
...volumes,
|
|
103
|
-
...
|
|
115
|
+
...portBindings,
|
|
104
116
|
...addExecFlag(envKeys, 'e'),
|
|
105
117
|
container.image,
|
|
106
118
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/dx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Docker container management",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"get-port": "^7.1.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@cloud-cli/cli": "^2.0.0"
|
|
38
|
+
"@cloud-cli/cli": "^2.0.0",
|
|
39
|
+
"@cloud-cli/env": "^1.0.0",
|
|
40
|
+
"@cloud-cli/dns": "^2.0.0",
|
|
41
|
+
"@cloud-cli/px": "^4.0.0"
|
|
39
42
|
}
|
|
40
43
|
}
|