@cyklang/cli 0.7.3 → 0.7.4

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/build/index.js CHANGED
@@ -73,32 +73,40 @@ async function startServer() {
73
73
  if (orchestrator === 'kubernetes') {
74
74
  // apply resource files
75
75
  await (0, Cmd_1.spawnCommand)('kubectl', ['apply', '-f', path_1.default.join(process.cwd(), 'k8s')]);
76
+ // port-forward
77
+ const portForwardPath = path_1.default.join(process.cwd(), 'k8s', 'port-forward');
78
+ if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
79
+ throw portForwardPath + ' file not found';
80
+ const portForwardContent = JSON.parse(fs.readFileSync(portForwardPath).toString());
76
81
  // wait for the services to be available
77
82
  while (true) {
78
- const services = await (0, Cmd_1.spawnCommandData)('kubectl', ['get', 'svc', '-o', 'name']);
79
- if (services.includes('service/nodejs') && services.includes('service/postgres')) {
80
- const availNodejs = await serviceAvailable('nodejs');
81
- const availPostgres = await serviceAvailable('postgres');
82
- if (availNodejs && availPostgres)
83
+ const declared_services = await (0, Cmd_1.spawnCommandData)('kubectl', ['get', 'svc', '-o', 'name']);
84
+ let ok = true;
85
+ for (const service in portForwardContent) {
86
+ if (!Object.prototype.hasOwnProperty.call(portForwardContent, service))
87
+ continue;
88
+ if (!declared_services.includes(`service/${service}`)) {
89
+ ok = false;
90
+ break;
91
+ }
92
+ const avail = await serviceAvailable(service);
93
+ if (!avail) {
94
+ ok = false;
83
95
  break;
96
+ }
84
97
  }
98
+ if (ok)
99
+ break;
85
100
  // wait for 1 second
86
101
  logger.info('Wait for nodejs and postgres services...');
87
102
  await new Promise((resolve) => setTimeout(() => {
88
103
  resolve();
89
104
  }, 1000));
90
105
  }
91
- // port-forward
92
- const portForwardPath = path_1.default.join(process.cwd(), 'k8s', 'port-forward');
93
- if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
94
- throw portForwardPath + ' file not found';
95
- const config = JSON.parse(fs.readFileSync(portForwardPath).toString());
96
- if (!config.postgres || !config.nodejs)
97
- throw portForwardPath + ' : file format incorrect';
98
- (0, Cmd_1.spawnCommand)('kubectl', ['port-forward', 'svc/postgres', config.postgres + ':5432']);
99
- logger.info('Postgresql proxy at localhost:' + config.postgres);
100
- (0, Cmd_1.spawnCommand)('kubectl', ['port-forward', 'svc/nodejs', config.nodejs + ':3000']);
101
- logger.info('Nodejs proxy at localhost:' + config.nodejs);
106
+ for (const service in portForwardContent) {
107
+ (0, Cmd_1.spawnCommand)('kubectl', ['port-forward', `svc/${service}`, portForwardContent[service]]);
108
+ logger.info(`${service} proxy via localhost ${portForwardContent[service].split(':')[0]}`);
109
+ }
102
110
  }
103
111
  if (!orchestrator) {
104
112
  logger.error('No cyk server is defined in current folder ' + process.cwd());
@@ -173,7 +181,7 @@ class StopCommand extends commander_1.Command {
173
181
  */
174
182
  const program = new commander_1.Command();
175
183
  program.name('cyk').description('cyklang CLI')
176
- .version('0.7.3');
184
+ .version('0.7.4');
177
185
  program.addCommand(new StartCommand('start'));
178
186
  program.addCommand(new StopCommand('stop'));
179
187
  program.addCommand(new InstallCommand_1.InstallCommand('install'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -52,18 +52,35 @@ async function startServer() {
52
52
  // apply resource files
53
53
  await spawnCommand('kubectl', ['apply', '-f', path.join(process.cwd(), 'k8s')])
54
54
 
55
+ // port-forward
56
+ const portForwardPath = path.join(process.cwd(), 'k8s', 'port-forward')
57
+ if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
58
+ throw portForwardPath + ' file not found'
59
+ const portForwardContent = JSON.parse(fs.readFileSync(portForwardPath).toString())
60
+
55
61
  // wait for the services to be available
56
62
 
57
63
  while (true) {
58
64
 
59
- const services = await spawnCommandData('kubectl', ['get', 'svc', '-o', 'name'])
60
-
61
- if (services.includes('service/nodejs') && services.includes('service/postgres')) {
62
- const availNodejs = await serviceAvailable('nodejs')
63
- const availPostgres = await serviceAvailable('postgres')
64
- if (availNodejs && availPostgres) break
65
+ const declared_services = await spawnCommandData('kubectl', ['get', 'svc', '-o', 'name'])
66
+
67
+ let ok = true
68
+
69
+ for(const service in portForwardContent) {
70
+ if (! Object.prototype.hasOwnProperty.call(portForwardContent, service)) continue
71
+ if (! declared_services.includes(`service/${service}`)) {
72
+ ok = false
73
+ break
74
+ }
75
+ const avail = await serviceAvailable(service)
76
+ if (! avail) {
77
+ ok = false
78
+ break
79
+ }
65
80
  }
66
-
81
+
82
+ if (ok) break
83
+
67
84
  // wait for 1 second
68
85
  logger.info('Wait for nodejs and postgres services...')
69
86
  await new Promise<void>((resolve) =>
@@ -73,17 +90,11 @@ async function startServer() {
73
90
  );
74
91
  }
75
92
 
76
- // port-forward
77
- const portForwardPath = path.join(process.cwd(), 'k8s', 'port-forward')
78
- if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
79
- throw portForwardPath + ' file not found'
80
- const config = JSON.parse(fs.readFileSync(portForwardPath).toString())
81
- if (!config.postgres || !config.nodejs)
82
- throw portForwardPath + ' : file format incorrect'
83
- spawnCommand('kubectl', ['port-forward', 'svc/postgres', config.postgres + ':5432'])
84
- logger.info('Postgresql proxy at localhost:' + config.postgres)
85
- spawnCommand('kubectl', ['port-forward', 'svc/nodejs', config.nodejs + ':3000'])
86
- logger.info('Nodejs proxy at localhost:' + config.nodejs)
93
+ for(const service in portForwardContent) {
94
+ spawnCommand('kubectl', ['port-forward', `svc/${service}`, portForwardContent[service]])
95
+ logger.info(`${service} proxy via localhost ${portForwardContent[service].split(':')[0]}`)
96
+ }
97
+
87
98
  }
88
99
  if (!orchestrator) {
89
100
  logger.error('No cyk server is defined in current folder ' + process.cwd())
@@ -100,12 +111,12 @@ async function startServer() {
100
111
  * @returns
101
112
  */
102
113
  async function serviceAvailable(service: string): Promise<boolean> {
103
-
114
+
104
115
  const descNodejs = await spawnCommandData('kubectl', ['describe', 'service', service])
105
116
  const lines = descNodejs.split('\n')
106
- for(const line of lines) {
117
+ for (const line of lines) {
107
118
  if (line.includes('Endpoints')) {
108
- return ! line.includes('<none>')
119
+ return !line.includes('<none>')
109
120
  }
110
121
  }
111
122
  return false
@@ -164,7 +175,7 @@ class StopCommand extends Command {
164
175
  */
165
176
  const program = new Command()
166
177
  program.name('cyk').description('cyklang CLI')
167
- .version('0.7.3')
178
+ .version('0.7.4')
168
179
  program.addCommand(new StartCommand('start'))
169
180
  program.addCommand(new StopCommand('stop'))
170
181
  program.addCommand(new InstallCommand('install'))