@milaboratories/pl-deployments 1.1.5 → 1.1.6
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/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +365 -348
- package/dist/index.mjs.map +1 -1
- package/dist/ssh/pl.d.ts +1 -0
- package/dist/ssh/pl.d.ts.map +1 -1
- package/dist/ssh/ssh.d.ts +4 -1
- package/dist/ssh/ssh.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ssh/pl.ts +8 -2
- package/src/ssh/ssh.ts +23 -1
package/src/ssh/pl.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as ssh from 'ssh2';
|
|
2
2
|
import { SshClient } from './ssh';
|
|
3
3
|
import type { MiLogger } from '@milaboratories/ts-helpers';
|
|
4
|
-
import { sleep, notEmpty
|
|
4
|
+
import { sleep, notEmpty } from '@milaboratories/ts-helpers';
|
|
5
5
|
import type { DownloadBinaryResult } from '../common/pl_binary_download';
|
|
6
6
|
import { downloadBinaryNoExtract } from '../common/pl_binary_download';
|
|
7
7
|
import upath from 'upath';
|
|
@@ -19,7 +19,7 @@ export class SshPl {
|
|
|
19
19
|
public readonly logger: MiLogger,
|
|
20
20
|
public readonly sshClient: SshClient,
|
|
21
21
|
private readonly username: string,
|
|
22
|
-
) {}
|
|
22
|
+
) { }
|
|
23
23
|
|
|
24
24
|
public info() {
|
|
25
25
|
return {
|
|
@@ -38,6 +38,10 @@ export class SshPl {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
public cleanUp() {
|
|
42
|
+
this.sshClient.close();
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
public async isAlive(): Promise<boolean> {
|
|
42
46
|
const arch = await this.getArch();
|
|
43
47
|
const remoteHome = await this.getUserHomeDirectory();
|
|
@@ -89,6 +93,8 @@ export class SshPl {
|
|
|
89
93
|
this.logger.info(`pl.reset: Deleting Platforma workDir ${workDir} on the server`);
|
|
90
94
|
await this.sshClient.deleteFolder(plpath.workDir(workDir));
|
|
91
95
|
|
|
96
|
+
this.cleanUp();
|
|
97
|
+
|
|
92
98
|
return true;
|
|
93
99
|
}
|
|
94
100
|
|
package/src/ssh/ssh.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type SshDirContent = {
|
|
|
23
23
|
export class SshClient {
|
|
24
24
|
private config?: ConnectConfig;
|
|
25
25
|
public homeDir?: string;
|
|
26
|
+
private forwardedServers: net.Server[] = [];
|
|
26
27
|
|
|
27
28
|
constructor(
|
|
28
29
|
private readonly logger: MiLogger,
|
|
@@ -46,6 +47,10 @@ export class SshClient {
|
|
|
46
47
|
return client;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
public getForwardedServers() {
|
|
51
|
+
return this.forwardedServers;
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
public getFullHostName() {
|
|
50
55
|
return `${this.config?.host}:${this.config?.port}`;
|
|
51
56
|
}
|
|
@@ -224,6 +229,7 @@ export class SshClient {
|
|
|
224
229
|
|
|
225
230
|
server.listen(ports.localPort, '127.0.0.1', () => {
|
|
226
231
|
this.logger.info(`${log}.server: started listening`);
|
|
232
|
+
this.forwardedServers.push(server);
|
|
227
233
|
resolve({ server });
|
|
228
234
|
});
|
|
229
235
|
|
|
@@ -234,10 +240,25 @@ export class SshClient {
|
|
|
234
240
|
|
|
235
241
|
server.on('close', () => {
|
|
236
242
|
this.logger.info(`${log}.server: closed ${JSON.stringify(ports)}`);
|
|
243
|
+
this.forwardedServers = this.forwardedServers.filter((s) => s !== server);
|
|
237
244
|
});
|
|
238
245
|
});
|
|
239
246
|
}
|
|
240
247
|
|
|
248
|
+
public closeForwardedPorts(): void {
|
|
249
|
+
this.logger.info('[SSH] Closing all forwarded ports...');
|
|
250
|
+
this.forwardedServers.forEach((server) => {
|
|
251
|
+
const rawAddress = server.address();
|
|
252
|
+
if (rawAddress && typeof rawAddress !== 'string') {
|
|
253
|
+
const address: net.AddressInfo = rawAddress;
|
|
254
|
+
this.logger.info(`[SSH] Closing port forward for server ${address.address}:${address.port}`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
server.close();
|
|
258
|
+
});
|
|
259
|
+
this.forwardedServers = [];
|
|
260
|
+
}
|
|
261
|
+
|
|
241
262
|
/**
|
|
242
263
|
* Checks if a specified host is available by performing a DNS lookup.
|
|
243
264
|
* @param hostname - The hostname or IP address to check.
|
|
@@ -616,9 +637,10 @@ export class SshClient {
|
|
|
616
637
|
}
|
|
617
638
|
|
|
618
639
|
/**
|
|
619
|
-
* Closes the SSH client connection.
|
|
640
|
+
* Closes the SSH client connection and forwarded ports.
|
|
620
641
|
*/
|
|
621
642
|
public close(): void {
|
|
643
|
+
this.closeForwardedPorts();
|
|
622
644
|
this.client.end();
|
|
623
645
|
}
|
|
624
646
|
}
|