dhti-cli 0.3.2 → 0.3.3

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.
@@ -8,6 +8,7 @@ export default class Docker extends Command {
8
8
  static flags: {
9
9
  down: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
10
  file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ container: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
12
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  type: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
14
  up: import("@oclif/core/interfaces").BooleanFlag<boolean>;
@@ -9,12 +9,19 @@ export default class Docker extends Command {
9
9
  path: Args.string({ default: `${os.homedir()}/dhti`, description: 'Docker project path to build. Ex: dhti' }),
10
10
  };
11
11
  static description = 'Build a docker project and update docker-compose file';
12
- static examples = [
13
- '<%= config.bin %> <%= command.id %>',
14
- ];
12
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
13
  static flags = {
16
14
  down: Flags.boolean({ char: 'd', default: false, description: 'Run docker-compose down after building' }),
17
- file: Flags.string({ char: 'f', default: `${os.homedir()}/dhti/docker-compose.yml`, description: 'Full path to the docker compose file to edit or run.' }),
15
+ file: Flags.string({
16
+ char: 'f',
17
+ default: `${os.homedir()}/dhti/docker-compose.yml`,
18
+ description: 'Full path to the docker compose file to edit or run.',
19
+ }),
20
+ container: Flags.string({
21
+ char: 'c',
22
+ default: 'dhti-langserve-1',
23
+ description: 'Name of the container to copy the bootstrap file to while in dev mode',
24
+ }),
18
25
  name: Flags.string({ char: 'n', description: 'Name of the container to build' }),
19
26
  type: Flags.string({ char: 't', default: 'elixir', description: 'Type of the service (elixir/conch)' }),
20
27
  up: Flags.boolean({ char: 'u', default: false, description: 'Run docker-compose up after building' }),
@@ -43,10 +50,36 @@ export default class Docker extends Command {
43
50
  });
44
51
  return;
45
52
  }
46
- if (!flags.name && (!flags.up || !flags.down)) {
47
- console.log("Please provide a name for the container to build");
53
+ if (args.path !== 'bootstrap' && !flags.name && !flags.up && !flags.down) {
54
+ console.log('Please provide a name for the container to build');
48
55
  this.exit(1);
49
56
  }
57
+ if (args.path === 'bootstrap') {
58
+ // if flags.file does not end with bootstrap.py then exit
59
+ if (!flags.file.endsWith('bootstrap.py')) {
60
+ console.log('Please provide a valid path to bootstrap.py file');
61
+ this.exit(1);
62
+ }
63
+ // copy -f to container:/app/app/ and only restart after copy completes
64
+ exec(`docker cp ${flags.file} ${flags.container}:/app/app/bootstrap.py`, (error, stdout, stderr) => {
65
+ if (error) {
66
+ console.error(`exec error: ${error}`);
67
+ return;
68
+ }
69
+ console.log(`stdout: ${stdout}`);
70
+ console.error(`stderr: ${stderr}`);
71
+ // restart the container only after copy completes
72
+ exec(`docker restart ${flags.container}`, (restartError, restartStdout, restartStderr) => {
73
+ if (restartError) {
74
+ console.error(`exec error: ${restartError}`);
75
+ return;
76
+ }
77
+ console.log(`stdout: ${restartStdout}`);
78
+ console.error(`stderr: ${restartStderr}`);
79
+ });
80
+ });
81
+ return;
82
+ }
50
83
  // cd to path, docker build tag with name
51
84
  const spinner = ora('Running docker build ..').start();
52
85
  exec(`cd ${args.path}/${flags.type} && docker build -t ${flags.name} . > /dev/null 2>&1`, (error, stdout, stderr) => {
@@ -60,15 +93,19 @@ export default class Docker extends Command {
60
93
  console.error(`stderr: ${stderr}`);
61
94
  });
62
95
  // read the docker-compose file
96
+ if (!fs.existsSync(flags.file)) {
97
+ console.error(`Error: The file "${flags.file}" does not exist.`);
98
+ this.exit(1);
99
+ }
63
100
  const dockerCompose = yaml.load(fs.readFileSync(flags.file, 'utf8'));
64
101
  // if type is elixir set image of backend to name, else set image of frontend to name
65
102
  if (flags.type === 'elixir') {
66
103
  dockerCompose.services.langserve.image = flags.name;
67
- dockerCompose.services.langserve.pull_policy = "if_not_present";
104
+ dockerCompose.services.langserve.pull_policy = 'if_not_present';
68
105
  }
69
106
  else {
70
107
  dockerCompose.services.frontend.image = flags.name;
71
- dockerCompose.services.frontend.pull_policy = "if_not_present";
108
+ dockerCompose.services.frontend.pull_policy = 'if_not_present';
72
109
  }
73
110
  // write the docker-compose file
74
111
  fs.writeFileSync(flags.file, yaml.dump(dockerCompose));
@@ -176,6 +176,15 @@
176
176
  "multiple": false,
177
177
  "type": "option"
178
178
  },
179
+ "container": {
180
+ "char": "c",
181
+ "description": "Name of the container to copy the bootstrap file to while in dev mode",
182
+ "name": "container",
183
+ "default": "dhti-langserve-1",
184
+ "hasDynamicHelp": false,
185
+ "multiple": false,
186
+ "type": "option"
187
+ },
179
188
  "name": {
180
189
  "char": "n",
181
190
  "description": "Name of the container to build",
@@ -440,5 +449,5 @@
440
449
  ]
441
450
  }
442
451
  },
443
- "version": "0.3.2"
452
+ "version": "0.3.3"
444
453
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dhti-cli",
3
3
  "description": "DHTI CLI",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "author": "Bell Eapen",
6
6
  "bin": {
7
7
  "dhti-cli": "bin/run.js"