@cloud-cli/dx 1.3.1 → 1.4.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 CHANGED
@@ -12,10 +12,9 @@ npm i @cloud-cli/dx
12
12
 
13
13
  ```bash
14
14
  cy dx.list
15
- cy dx.status
16
15
  cy dx.prune
17
- cy dx.pull node:latest
18
- cy dx.add --name node-app --image node --version latest --command 'node --version' --volumes 'volume:/container/path' --ports '1234:80' --host 'foo.example.com'
16
+ cy dx.pull --image node:latest
17
+ cy dx.add --name node-app --image node:latest --volumes 'volume:/container/path' --ports '1234:80' --host 'foo.example.com'
19
18
  cy dx.start --name node-app --env 'FOO=bar' --ports '1234:80'
20
19
  cy dx.logs --name node-app
21
20
  cy dx.stop --name node-app
package/cloud.db ADDED
Binary file
@@ -6,12 +6,11 @@ interface GetLogsOptions {
6
6
  export declare function getLogs({ name, lines }: GetLogsOptions): Promise<string>;
7
7
  interface RunOptions {
8
8
  name: string;
9
- env?: string[] | string;
10
- ports?: string;
11
9
  }
10
+ export declare function refreshContainer(options: RunOptions, { run }: any): Promise<void>;
12
11
  export declare function startContainer(options: RunOptions, { run }: any): Promise<boolean>;
13
12
  export interface StopOptions {
14
13
  name: string;
15
14
  }
16
- export declare function stopContainer(options: StopOptions): Promise<boolean>;
15
+ export declare function stopContainer(options: StopOptions, { run }: any): Promise<boolean>;
17
16
  export {};
@@ -22,21 +22,29 @@ export async function getLogs({ name, lines }) {
22
22
  }
23
23
  return '';
24
24
  }
25
- const defaultRunOptions = { ports: '', env: [] };
25
+ export async function refreshContainer(options, { run }) {
26
+ const { name } = options;
27
+ const container = await findContainer(name);
28
+ await run('dx.stop', { name });
29
+ await run('dx.pull', { image: container.image });
30
+ await run('dx.prune');
31
+ await run('dx.start', { name });
32
+ }
26
33
  export async function startContainer(options, { run }) {
27
- options = { ...defaultRunOptions, ...options };
28
34
  const { name } = options;
29
35
  if (!name) {
30
36
  throw new Error('Name is required');
31
37
  }
32
38
  const vars = (await run('env.show', { app: name }));
33
- const { env, envKeys } = await getEnvVars(options.env, vars);
39
+ const { env, envKeys } = await getEnvVars(vars);
34
40
  const container = await findContainer(name);
35
41
  const volumes = addExecFlag(container.volumes, 'v');
36
- const ports = getPorts([...container.ports.split(','), ...options.ports.split(','), env.PORT + ':' + env.PORT]);
42
+ const ports = getPorts([...container.ports.split(','), env.PORT + ':' + env.PORT]);
37
43
  if (container.host) {
38
44
  await run('px.remove', { domain: container.host });
39
45
  await run('px.add', { domain: container.host, target: 'http://localhost:' + env.PORT, cors: true, redirect: true });
46
+ await run('dns.add', { domain: container.host });
47
+ await run('dns.reload');
40
48
  }
41
49
  await exec('docker', [
42
50
  'run',
@@ -60,30 +68,26 @@ function getPorts(ports) {
60
68
  });
61
69
  return Object.entries(map).map(([left, right]) => '-p' + left + ':' + right);
62
70
  }
63
- async function getEnvVars(inputEnv, vars) {
71
+ async function getEnvVars(vars) {
64
72
  const port = await getPort();
65
- const envVars = vars.concat({ key: 'PORT', value: String(port) });
66
- const additionalEnv = [inputEnv].flat();
67
- if (Array.isArray(additionalEnv)) {
68
- additionalEnv.forEach((str) => {
69
- let [key, value] = str.split('=');
70
- envVars.push({ key, value });
71
- });
72
- }
73
73
  const envKeys = [];
74
- const env = {};
75
- envVars.forEach(({ key, value }) => {
74
+ const env = { ...process.env };
75
+ vars.concat({ key: 'PORT', value: String(port) }).forEach(({ key, value }) => {
76
76
  envKeys.push(key);
77
77
  env[key] = String(value);
78
78
  });
79
79
  return { env, envKeys: [...new Set(envKeys)] };
80
80
  }
81
- export async function stopContainer(options) {
82
- if (!options.name) {
81
+ export async function stopContainer(options, { run }) {
82
+ let { name } = options;
83
+ if (!name) {
83
84
  throw new Error('Name is required');
84
85
  }
85
- await exec('docker', ['stop', '-t', '5', options.name]);
86
- await exec('docker', ['rm', options.name]);
86
+ const container = await findContainer(name);
87
+ await exec('docker', ['stop', '-t', '5', name]);
88
+ await exec('docker', ['rm', name]);
89
+ await run('dns.remove', { domain: container.host });
90
+ await run('dns.reload');
87
91
  return true;
88
92
  }
89
93
  function getListFromString(string) {
package/dist/images.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { exec } from '@cloud-cli/exec';
2
2
  export async function pull(options) {
3
+ if (!options.image) {
4
+ throw new Error('Image is required');
5
+ }
3
6
  return (await exec('docker', ['pull', options.image])).ok;
4
7
  }
5
8
  export async function prune() {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { init } from '@cloud-cli/cli';
2
- import { getRunningContainers, getLogs, startContainer, stopContainer } from './containers.js';
2
+ import { getRunningContainers, getLogs, startContainer, stopContainer, refreshContainer } from './containers.js';
3
3
  import { addContainer, removeContainer, listContainers, updateContainer, getContainer } from './store.js';
4
4
  import { pull, prune } from './images.js';
5
5
  declare function reload(): Promise<void>;
@@ -10,6 +10,7 @@ declare const _default: {
10
10
  remove: typeof removeContainer;
11
11
  get: typeof getContainer;
12
12
  list: typeof listContainers;
13
+ refresh: typeof refreshContainer;
13
14
  update: typeof updateContainer;
14
15
  start: typeof startContainer;
15
16
  stop: typeof stopContainer;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { init } from '@cloud-cli/cli';
2
2
  import { Resource, SQLiteDriver } from '@cloud-cli/store';
3
3
  import { Container } from './store.js';
4
- import { getRunningContainers, getLogs, startContainer, stopContainer } from './containers.js';
4
+ import { getRunningContainers, getLogs, startContainer, stopContainer, refreshContainer } from './containers.js';
5
5
  import { addContainer, removeContainer, listContainers, updateContainer, getContainer } from './store.js';
6
6
  import { pull, prune } from './images.js';
7
7
  async function reload() {
@@ -15,6 +15,7 @@ export default {
15
15
  remove: removeContainer,
16
16
  get: getContainer,
17
17
  list: listContainers,
18
+ refresh: refreshContainer,
18
19
  update: updateContainer,
19
20
  start: startContainer,
20
21
  stop: stopContainer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/dx",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Docker container management",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",