@underpostnet/underpost 2.98.3 → 2.99.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 +2 -3
- package/bin/deploy.js +1 -1
- package/cli.md +109 -110
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +4 -4
- package/package.json +1 -2
- package/src/api/user/user.router.js +7 -40
- package/src/cli/baremetal.js +67 -71
- package/src/cli/cloud-init.js +11 -12
- package/src/cli/cluster.js +22 -24
- package/src/cli/db.js +43 -50
- package/src/cli/deploy.js +162 -60
- package/src/cli/env.js +20 -5
- package/src/cli/fs.js +19 -21
- package/src/cli/index.js +35 -32
- package/src/cli/lxd.js +5 -5
- package/src/cli/monitor.js +66 -88
- package/src/cli/repository.js +7 -6
- package/src/cli/run.js +369 -261
- package/src/cli/secrets.js +3 -3
- package/src/cli/ssh.js +31 -32
- package/src/cli/static.js +1 -1
- package/src/cli/test.js +6 -7
- package/src/index.js +49 -32
- package/src/runtime/express/Express.js +7 -6
- package/src/server/auth.js +6 -1
- package/src/server/backup.js +11 -1
- package/src/server/conf.js +4 -4
- package/src/{cli → server}/cron.js +56 -29
- package/src/server/dns.js +39 -31
- package/src/server/peer.js +2 -2
- package/src/server/process.js +2 -2
- package/src/server/proxy.js +8 -7
- package/src/server/runtime.js +4 -7
- package/src/server/start.js +28 -15
- package/src/ws/IoServer.js +2 -3
- package/src/cli/script.js +0 -85
- package/src/monitor.js +0 -34
package/src/server/dns.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Provides a comprehensive set of DNS and IP management utilities,
|
|
3
3
|
* primarily focused on dynamic DNS (DDNS) updates and network checks.
|
|
4
4
|
* @module src/server/dns.js
|
|
5
|
-
* @namespace
|
|
5
|
+
* @namespace UnderpostDns
|
|
6
6
|
*/
|
|
7
7
|
import axios from 'axios';
|
|
8
8
|
import dotenv from 'dotenv';
|
|
9
9
|
import fs from 'fs';
|
|
10
10
|
import validator from 'validator';
|
|
11
11
|
import { loggerFactory } from './logger.js';
|
|
12
|
-
import UnderpostRootEnv from '../cli/env.js';
|
|
13
12
|
import dns from 'node:dns';
|
|
14
13
|
import os from 'node:os';
|
|
15
14
|
import { shellExec, pbcopy } from './process.js';
|
|
15
|
+
import Underpost from '../index.js';
|
|
16
16
|
|
|
17
17
|
dotenv.config();
|
|
18
18
|
|
|
@@ -23,14 +23,14 @@ const logger = loggerFactory(import.meta);
|
|
|
23
23
|
* All utility methods are implemented as static to serve as a namespace container.
|
|
24
24
|
* @class Dns
|
|
25
25
|
* @augments Dns
|
|
26
|
-
* @memberof
|
|
26
|
+
* @memberof UnderpostDns
|
|
27
27
|
*/
|
|
28
28
|
class Dns {
|
|
29
29
|
/**
|
|
30
30
|
* Retrieves the current public IP address (IPv4 or IPv6).
|
|
31
31
|
* @async
|
|
32
32
|
* @static
|
|
33
|
-
* @memberof
|
|
33
|
+
* @memberof UnderpostDns
|
|
34
34
|
* @returns {Promise<string>} The public IP address.
|
|
35
35
|
*/
|
|
36
36
|
static async getPublicIp() {
|
|
@@ -49,7 +49,7 @@ class Dns {
|
|
|
49
49
|
/**
|
|
50
50
|
* Checks for active internet connection by performing a DNS lookup on a specified domain.
|
|
51
51
|
* @static
|
|
52
|
-
* @memberof
|
|
52
|
+
* @memberof UnderpostDns
|
|
53
53
|
* @param {string} [domain='google.com'] The domain to check the connection against.
|
|
54
54
|
* @returns {Promise<boolean>} True if connected, false otherwise.
|
|
55
55
|
*/
|
|
@@ -61,9 +61,9 @@ class Dns {
|
|
|
61
61
|
* Determines the default network interface name using shell command.
|
|
62
62
|
* This method is primarily intended for Linux environments.
|
|
63
63
|
* @static
|
|
64
|
-
* @memberof
|
|
64
|
+
* @memberof UnderpostDns
|
|
65
65
|
* @returns {string} The default network interface name.
|
|
66
|
-
* @memberof
|
|
66
|
+
* @memberof UnderpostDns
|
|
67
67
|
*/
|
|
68
68
|
static getDefaultNetworkInterface() {
|
|
69
69
|
return shellExec(`ip route | grep default | cut -d ' ' -f 5`, {
|
|
@@ -77,7 +77,7 @@ class Dns {
|
|
|
77
77
|
* Gets the local device's IPv4 address by determining the active network interface.
|
|
78
78
|
* This relies on shell execution (`ip route`) and is primarily intended for Linux environments.
|
|
79
79
|
* @static
|
|
80
|
-
* @memberof
|
|
80
|
+
* @memberof UnderpostDns
|
|
81
81
|
* @returns {string} The local IPv4 address.
|
|
82
82
|
*/
|
|
83
83
|
static getLocalIPv4Address() {
|
|
@@ -105,7 +105,7 @@ class Dns {
|
|
|
105
105
|
/**
|
|
106
106
|
* Setup nftables tables and chains if they don't exist.
|
|
107
107
|
* @static
|
|
108
|
-
* @memberof
|
|
108
|
+
* @memberof UnderpostDns
|
|
109
109
|
*/
|
|
110
110
|
static setupNftables() {
|
|
111
111
|
shellExec(`sudo nft add table inet filter 2>/dev/null`, { silent: true });
|
|
@@ -126,7 +126,7 @@ class Dns {
|
|
|
126
126
|
/**
|
|
127
127
|
* Bans an IP address from ingress traffic.
|
|
128
128
|
* @static
|
|
129
|
-
* @memberof
|
|
129
|
+
* @memberof UnderpostDns
|
|
130
130
|
* @param {string} ip - The IP address to ban.
|
|
131
131
|
*/
|
|
132
132
|
static banIngress(ip) {
|
|
@@ -142,7 +142,7 @@ class Dns {
|
|
|
142
142
|
/**
|
|
143
143
|
* Bans an IP address from egress traffic.
|
|
144
144
|
* @static
|
|
145
|
-
* @memberof
|
|
145
|
+
* @memberof UnderpostDns
|
|
146
146
|
* @param {string} ip - The IP address to ban.
|
|
147
147
|
*/
|
|
148
148
|
static banEgress(ip) {
|
|
@@ -159,7 +159,7 @@ class Dns {
|
|
|
159
159
|
/**
|
|
160
160
|
* Helper to get nftables rule handles for a specific IP and chain.
|
|
161
161
|
* @static
|
|
162
|
-
* @memberof
|
|
162
|
+
* @memberof UnderpostDns
|
|
163
163
|
* @param {string} chain - The chain name (input, output, forward).
|
|
164
164
|
* @param {string} ip - The IP address.
|
|
165
165
|
* @param {string} type - The type (saddr or daddr).
|
|
@@ -184,7 +184,7 @@ class Dns {
|
|
|
184
184
|
/**
|
|
185
185
|
* Unbans an IP address from ingress traffic.
|
|
186
186
|
* @static
|
|
187
|
-
* @memberof
|
|
187
|
+
* @memberof UnderpostDns
|
|
188
188
|
* @param {string} ip - The IP address to unban.
|
|
189
189
|
*/
|
|
190
190
|
static unbanIngress(ip) {
|
|
@@ -198,7 +198,7 @@ class Dns {
|
|
|
198
198
|
/**
|
|
199
199
|
* Unbans an IP address from egress traffic.
|
|
200
200
|
* @static
|
|
201
|
-
* @memberof
|
|
201
|
+
* @memberof UnderpostDns
|
|
202
202
|
* @param {string} ip - The IP address to unban.
|
|
203
203
|
*/
|
|
204
204
|
static unbanEgress(ip) {
|
|
@@ -216,7 +216,7 @@ class Dns {
|
|
|
216
216
|
/**
|
|
217
217
|
* Lists all banned ingress IPs.
|
|
218
218
|
* @static
|
|
219
|
-
* @memberof
|
|
219
|
+
* @memberof UnderpostDns
|
|
220
220
|
*/
|
|
221
221
|
static listBannedIngress() {
|
|
222
222
|
const output = shellExec(`sudo nft list chain inet filter input`, { stdout: true, silent: true });
|
|
@@ -226,7 +226,7 @@ class Dns {
|
|
|
226
226
|
/**
|
|
227
227
|
* Lists all banned egress IPs.
|
|
228
228
|
* @static
|
|
229
|
-
* @memberof
|
|
229
|
+
* @memberof UnderpostDns
|
|
230
230
|
*/
|
|
231
231
|
static listBannedEgress() {
|
|
232
232
|
console.log('--- Output Chain ---');
|
|
@@ -238,7 +238,7 @@ class Dns {
|
|
|
238
238
|
/**
|
|
239
239
|
* Clears all banned ingress IPs.
|
|
240
240
|
* @static
|
|
241
|
-
* @memberof
|
|
241
|
+
* @memberof UnderpostDns
|
|
242
242
|
*/
|
|
243
243
|
static clearBannedIngress() {
|
|
244
244
|
shellExec(`sudo nft flush chain inet filter input`, { silent: true });
|
|
@@ -248,7 +248,7 @@ class Dns {
|
|
|
248
248
|
/**
|
|
249
249
|
* Clears all banned egress IPs.
|
|
250
250
|
* @static
|
|
251
|
-
* @memberof
|
|
251
|
+
* @memberof UnderpostDns
|
|
252
252
|
*/
|
|
253
253
|
static clearBannedEgress() {
|
|
254
254
|
shellExec(`sudo nft flush chain inet filter output`, { silent: true });
|
|
@@ -261,7 +261,7 @@ class Dns {
|
|
|
261
261
|
* It checks if the public IP has changed and, if so, updates the configured DNS records.
|
|
262
262
|
* @async
|
|
263
263
|
* @static
|
|
264
|
-
* @memberof
|
|
264
|
+
* @memberof UnderpostDns
|
|
265
265
|
* @param {string} deployList Comma-separated string of deployment IDs to process.
|
|
266
266
|
* @returns {Promise<void>}
|
|
267
267
|
*/
|
|
@@ -278,11 +278,11 @@ class Dns {
|
|
|
278
278
|
logger.error(error, { testIp, stack: error.stack });
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
const currentIp =
|
|
281
|
+
const currentIp = Underpost.env.get('ip');
|
|
282
282
|
|
|
283
283
|
if (validator.isIP(testIp) && currentIp !== testIp) {
|
|
284
284
|
logger.info(`New IP detected`, testIp);
|
|
285
|
-
|
|
285
|
+
Underpost.env.set('monitor-input', 'pause');
|
|
286
286
|
|
|
287
287
|
for (const _deployId of deployList.split(',')) {
|
|
288
288
|
const deployId = _deployId.trim();
|
|
@@ -326,8 +326,8 @@ class Dns {
|
|
|
326
326
|
logger.info(ipUrlTest + ' verify ip', verifyIp);
|
|
327
327
|
if (verifyIp === testIp) {
|
|
328
328
|
logger.info('IP updated successfully and verified', testIp);
|
|
329
|
-
|
|
330
|
-
|
|
329
|
+
Underpost.env.set('ip', testIp);
|
|
330
|
+
Underpost.env.delete('monitor-input');
|
|
331
331
|
} else {
|
|
332
332
|
logger.error('IP not updated or verification failed', { expected: testIp, received: verifyIp });
|
|
333
333
|
}
|
|
@@ -345,14 +345,14 @@ class Dns {
|
|
|
345
345
|
/**
|
|
346
346
|
* Internal collection of external DNS service update functions.
|
|
347
347
|
* @static
|
|
348
|
-
* @memberof
|
|
348
|
+
* @memberof UnderpostDns
|
|
349
349
|
* @property {object} updateIp - Functions keyed by DNS provider name to update A/AAAA records.
|
|
350
350
|
*/
|
|
351
351
|
static services = {
|
|
352
352
|
updateIp: {
|
|
353
353
|
/**
|
|
354
354
|
* Updates the IP address for a dondominio.com DNS record.
|
|
355
|
-
* @memberof
|
|
355
|
+
* @memberof UnderpostDns
|
|
356
356
|
* @param {object} options
|
|
357
357
|
* @param {string} options.user - The dondominio DDNS username.
|
|
358
358
|
* @param {string} options.api_key - The dondominio DDNS password/API key.
|
|
@@ -392,7 +392,7 @@ class Dns {
|
|
|
392
392
|
/**
|
|
393
393
|
* Dispatcher for IP ban/unban/list/clear operations based on CLI options.
|
|
394
394
|
* @static
|
|
395
|
-
* @memberof
|
|
395
|
+
* @memberof UnderpostDns
|
|
396
396
|
* @param {string} [ips=''] Comma-separated string of IPs to process.
|
|
397
397
|
* @param {object} options - Options indicating which action to perform.
|
|
398
398
|
* @property {boolean} [options.banIngressAdd=false] - Ban IPs from ingress.
|
|
@@ -483,7 +483,7 @@ class Dns {
|
|
|
483
483
|
|
|
484
484
|
/**
|
|
485
485
|
* @function isInternetConnection
|
|
486
|
-
* @memberof
|
|
486
|
+
* @memberof UnderpostDns
|
|
487
487
|
* @description Exported function for backward compatibility.
|
|
488
488
|
* @param {string} [domain='google.com']
|
|
489
489
|
* @returns {Promise<boolean>}
|
|
@@ -492,13 +492,21 @@ const isInternetConnection = Dns.isInternetConnection;
|
|
|
492
492
|
|
|
493
493
|
/**
|
|
494
494
|
* @function getLocalIPv4Address
|
|
495
|
-
* @memberof
|
|
495
|
+
* @memberof UnderpostDns
|
|
496
496
|
* @description Exported function for backward compatibility.
|
|
497
497
|
* @returns {string}
|
|
498
498
|
*/
|
|
499
499
|
const getLocalIPv4Address = Dns.getLocalIPv4Address;
|
|
500
500
|
|
|
501
|
-
|
|
502
|
-
|
|
501
|
+
/**
|
|
502
|
+
* Main UnderpostDns class exposing the Dns API.
|
|
503
|
+
* @class UnderpostDns
|
|
504
|
+
* @memberof UnderpostDns
|
|
505
|
+
*/
|
|
506
|
+
class UnderpostDns {
|
|
507
|
+
static API = Dns;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export default UnderpostDns;
|
|
503
511
|
|
|
504
|
-
export { Dns, isInternetConnection, getLocalIPv4Address };
|
|
512
|
+
export { Dns, isInternetConnection, getLocalIPv4Address, UnderpostDns };
|
package/src/server/peer.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { PeerServer } from 'peer';
|
|
11
11
|
import dotenv from 'dotenv';
|
|
12
12
|
import { loggerFactory } from './logger.js';
|
|
13
|
-
import
|
|
13
|
+
import Underpost from '../index.js';
|
|
14
14
|
|
|
15
15
|
dotenv.config();
|
|
16
16
|
|
|
@@ -61,7 +61,7 @@ const createPeerServer = async ({ port, origins, path }) => {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
// Use the framework's factory to listen on the server, ensuring graceful startup/shutdown
|
|
64
|
-
const peerServer =
|
|
64
|
+
const peerServer = Underpost.start.listenServerFactory(async () => PeerServer(options));
|
|
65
65
|
|
|
66
66
|
return { options, peerServer, meta: import.meta };
|
|
67
67
|
};
|
package/src/server/process.js
CHANGED
|
@@ -11,7 +11,7 @@ import shell from 'shelljs';
|
|
|
11
11
|
import dotenv from 'dotenv';
|
|
12
12
|
import { loggerFactory } from './logger.js';
|
|
13
13
|
import clipboard from 'clipboardy';
|
|
14
|
-
import
|
|
14
|
+
import Underpost from '../index.js';
|
|
15
15
|
|
|
16
16
|
dotenv.config();
|
|
17
17
|
|
|
@@ -83,7 +83,7 @@ const ProcessController = {
|
|
|
83
83
|
this.logger.info(`process on exit`, args);
|
|
84
84
|
});
|
|
85
85
|
this.onSigListen();
|
|
86
|
-
|
|
86
|
+
Underpost.env.delete('await-deploy');
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
|
package/src/server/proxy.js
CHANGED
|
@@ -12,12 +12,13 @@ import dotenv from 'dotenv';
|
|
|
12
12
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
13
13
|
import { loggerFactory, loggerMiddleware } from './logger.js';
|
|
14
14
|
import { buildPortProxyRouter, buildProxyRouter, getTlsHosts, isDevProxyContext, isTlsDevProxy } from './conf.js';
|
|
15
|
-
|
|
16
|
-
import UnderpostDeploy from '../cli/deploy.js';
|
|
15
|
+
|
|
17
16
|
import { SSL_BASE, TLS } from './tls.js';
|
|
18
17
|
import { shellExec } from './process.js';
|
|
19
18
|
import fs from 'fs-extra';
|
|
20
19
|
|
|
20
|
+
import Underpost from '../index.js';
|
|
21
|
+
|
|
21
22
|
dotenv.config();
|
|
22
23
|
|
|
23
24
|
const logger = loggerFactory(import.meta);
|
|
@@ -85,12 +86,12 @@ class ProxyService {
|
|
|
85
86
|
case 443:
|
|
86
87
|
// For port 443 (HTTPS), create the SSL server
|
|
87
88
|
const { ServerSSL } = await TLS.createSslServer(app, hosts);
|
|
88
|
-
await
|
|
89
|
+
await Underpost.start.listenPortController(ServerSSL, port, runningData);
|
|
89
90
|
break;
|
|
90
91
|
|
|
91
92
|
default:
|
|
92
93
|
// For other ports in production, use standard HTTP
|
|
93
|
-
await
|
|
94
|
+
await Underpost.start.listenPortController(app, port, runningData);
|
|
94
95
|
break;
|
|
95
96
|
}
|
|
96
97
|
break;
|
|
@@ -108,18 +109,18 @@ class ProxyService {
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
const { ServerSSL } = await TLS.createSslServer(app, tlsHosts);
|
|
111
|
-
await
|
|
112
|
+
await Underpost.start.listenPortController(ServerSSL, port, runningData);
|
|
112
113
|
break;
|
|
113
114
|
}
|
|
114
115
|
default: // In non-production, always use standard HTTP listener
|
|
115
|
-
await
|
|
116
|
+
await Underpost.start.listenPortController(app, port, runningData);
|
|
116
117
|
break;
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
logger.info('Proxy running', { port, options });
|
|
120
121
|
if (process.env.NODE_ENV === 'development')
|
|
121
122
|
logger.info(
|
|
122
|
-
|
|
123
|
+
Underpost.deploy.etcHostFactory(Object.keys(options.router), {
|
|
123
124
|
append: true,
|
|
124
125
|
}).renderHosts,
|
|
125
126
|
);
|
package/src/server/runtime.js
CHANGED
|
@@ -10,7 +10,6 @@ import fs from 'fs-extra';
|
|
|
10
10
|
import dotenv from 'dotenv';
|
|
11
11
|
import * as promClient from 'prom-client';
|
|
12
12
|
|
|
13
|
-
import UnderpostStartUp from './start.js';
|
|
14
13
|
import { loggerFactory } from './logger.js';
|
|
15
14
|
import { newInstance } from '../client/components/core/CommonJs.js';
|
|
16
15
|
import { Lampp } from '../runtime/lampp/Lampp.js';
|
|
@@ -18,6 +17,8 @@ import { getInstanceContext } from './conf.js';
|
|
|
18
17
|
|
|
19
18
|
import ExpressService from '../runtime/express/Express.js';
|
|
20
19
|
|
|
20
|
+
import Underpost from '../index.js';
|
|
21
|
+
|
|
21
22
|
dotenv.config();
|
|
22
23
|
|
|
23
24
|
const logger = loggerFactory(import.meta);
|
|
@@ -142,11 +143,7 @@ const buildRuntime = async () => {
|
|
|
142
143
|
resetRouter: currentPort === initPort,
|
|
143
144
|
});
|
|
144
145
|
if (disabled) continue;
|
|
145
|
-
await
|
|
146
|
-
UnderpostStartUp.API.listenServerFactory(),
|
|
147
|
-
port,
|
|
148
|
-
runningData,
|
|
149
|
-
);
|
|
146
|
+
await Underpost.start.listenPortController(Underpost.start.listenServerFactory(), port, runningData);
|
|
150
147
|
}
|
|
151
148
|
break;
|
|
152
149
|
default:
|
|
@@ -159,7 +156,7 @@ const buildRuntime = async () => {
|
|
|
159
156
|
|
|
160
157
|
if (Lampp.enabled() && Lampp.router) Lampp.initService();
|
|
161
158
|
|
|
162
|
-
|
|
159
|
+
Underpost.start.logRuntimeRouter();
|
|
163
160
|
};
|
|
164
161
|
|
|
165
162
|
export { buildRuntime };
|
package/src/server/start.js
CHANGED
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
* @namespace UnderpostStartUp
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import UnderpostDeploy from '../cli/deploy.js';
|
|
8
7
|
import fs from 'fs-extra';
|
|
9
8
|
import { awaitDeployMonitor } from './conf.js';
|
|
10
9
|
import { actionInitLog, loggerFactory } from './logger.js';
|
|
11
10
|
import { shellCd, shellExec } from './process.js';
|
|
12
|
-
import
|
|
13
|
-
|
|
11
|
+
import Underpost from '../index.js';
|
|
14
12
|
const logger = loggerFactory(import.meta);
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -19,17 +17,32 @@ const logger = loggerFactory(import.meta);
|
|
|
19
17
|
* @memberof UnderpostStartUp
|
|
20
18
|
*/
|
|
21
19
|
class UnderpostStartUp {
|
|
20
|
+
/**
|
|
21
|
+
* Holds the NETWORK configuration.
|
|
22
|
+
* @memberof UnderpostStartUp
|
|
23
|
+
* @type {Object}
|
|
24
|
+
* @static
|
|
25
|
+
*/
|
|
26
|
+
static NETWORK = {};
|
|
22
27
|
static API = {
|
|
23
28
|
/**
|
|
24
|
-
*
|
|
29
|
+
* Gets the current NETWORK configuration.
|
|
30
|
+
* @memberof UnderpostStartUp
|
|
31
|
+
* @returns {Object} The current NETWORK configuration.
|
|
32
|
+
*/
|
|
33
|
+
get NETWORK() {
|
|
34
|
+
return UnderpostStartUp.NETWORK;
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Logs the runtime this.NETWORK configuration.
|
|
25
38
|
* @memberof UnderpostStartUp
|
|
26
39
|
*/
|
|
27
40
|
logRuntimeRouter: () => {
|
|
28
41
|
const displayLog = {};
|
|
29
42
|
|
|
30
|
-
for (const host of Object.keys(
|
|
31
|
-
for (const path of Object.keys(
|
|
32
|
-
displayLog[
|
|
43
|
+
for (const host of Object.keys(this.NETWORK))
|
|
44
|
+
for (const path of Object.keys(this.NETWORK[host]))
|
|
45
|
+
displayLog[this.NETWORK[host][path].publicHost] = this.NETWORK[host][path].local;
|
|
33
46
|
|
|
34
47
|
logger.info('Runtime network', displayLog);
|
|
35
48
|
},
|
|
@@ -85,8 +98,8 @@ class UnderpostStartUp {
|
|
|
85
98
|
if (error.length > 0) throw new Error('Listen port controller requires values: ' + error.join(', '));
|
|
86
99
|
|
|
87
100
|
server.listen(port, () => {
|
|
88
|
-
if (!
|
|
89
|
-
|
|
101
|
+
if (!this.NETWORK[host]) this.NETWORK[host] = {};
|
|
102
|
+
this.NETWORK[host][path] = {
|
|
90
103
|
meta,
|
|
91
104
|
client,
|
|
92
105
|
runtime,
|
|
@@ -124,10 +137,10 @@ class UnderpostStartUp {
|
|
|
124
137
|
env = 'development',
|
|
125
138
|
options = { build: false, run: false, underpostQuicklyInstall: false },
|
|
126
139
|
) {
|
|
127
|
-
|
|
128
|
-
if (options.build === true) await
|
|
129
|
-
|
|
130
|
-
if (options.run === true) await
|
|
140
|
+
Underpost.env.set('container-status', `${deployId}-${env}-build-deployment`);
|
|
141
|
+
if (options.build === true) await Underpost.start.build(deployId, env, options);
|
|
142
|
+
Underpost.env.set('container-status', `${deployId}-${env}-initializing-deployment`);
|
|
143
|
+
if (options.run === true) await Underpost.start.run(deployId, env, options);
|
|
131
144
|
},
|
|
132
145
|
/**
|
|
133
146
|
* Run itc-scripts and builds client bundle.
|
|
@@ -177,7 +190,7 @@ class UnderpostStartUp {
|
|
|
177
190
|
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
178
191
|
shellExec(`npm ${runCmd} ${deployId}`, { async: true });
|
|
179
192
|
await awaitDeployMonitor(true);
|
|
180
|
-
|
|
193
|
+
Underpost.env.set('container-status', `${deployId}-${env}-running-deployment`);
|
|
181
194
|
},
|
|
182
195
|
};
|
|
183
196
|
}
|
|
@@ -188,7 +201,7 @@ class UnderpostStartUp {
|
|
|
188
201
|
* @returns
|
|
189
202
|
*/
|
|
190
203
|
const createKeepAliveProcess = async () =>
|
|
191
|
-
await
|
|
204
|
+
await Underpost.start.listenPortController(Underpost.start.listenServerFactory(), ':');
|
|
192
205
|
|
|
193
206
|
export default UnderpostStartUp;
|
|
194
207
|
|
package/src/ws/IoServer.js
CHANGED
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { Server } from 'socket.io';
|
|
10
10
|
import { loggerFactory } from '../server/logger.js';
|
|
11
|
-
import
|
|
12
|
-
|
|
11
|
+
import Underpost from '../index.js';
|
|
13
12
|
import http from 'http';
|
|
14
13
|
|
|
15
14
|
const logger = loggerFactory(import.meta);
|
|
@@ -60,7 +59,7 @@ class IoServerClass {
|
|
|
60
59
|
path: options.path !== '/' ? `${options.path}/socket.io/` : '/socket.io/',
|
|
61
60
|
};
|
|
62
61
|
|
|
63
|
-
const ioServerInstance =
|
|
62
|
+
const ioServerInstance = Underpost.start.listenServerFactory(() =>
|
|
64
63
|
new Server(httpServer, wsOptions).on('connection', ConnectionHandler),
|
|
65
64
|
);
|
|
66
65
|
|
package/src/cli/script.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Script module for managing the execution of scripts.
|
|
3
|
-
* @module src/cli/script.js
|
|
4
|
-
* @namespace UnderpostScript
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { getNpmRootPath } from '../server/conf.js';
|
|
8
|
-
import { loggerFactory } from '../server/logger.js';
|
|
9
|
-
import { shellExec } from '../server/process.js';
|
|
10
|
-
import fs from 'fs-extra';
|
|
11
|
-
import UnderpostDeploy from './deploy.js';
|
|
12
|
-
|
|
13
|
-
const logger = loggerFactory(import.meta);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @class UnderpostScript
|
|
17
|
-
* @description Manages the execution of scripts.
|
|
18
|
-
* @memberof UnderpostScript
|
|
19
|
-
*/
|
|
20
|
-
class UnderpostScript {
|
|
21
|
-
static API = {
|
|
22
|
-
/**
|
|
23
|
-
* @method set
|
|
24
|
-
* @description Sets a script in the package.json file.
|
|
25
|
-
* @param {string} key - The key for the script.
|
|
26
|
-
* @param {string} value - The value for the script.
|
|
27
|
-
* @memberof UnderpostScript
|
|
28
|
-
*/
|
|
29
|
-
set(key, value) {
|
|
30
|
-
const npmRoot = `${getNpmRootPath()}/underpost`;
|
|
31
|
-
const packageJson = JSON.parse(fs.readFileSync(`${npmRoot}/package.json`, 'utf8'));
|
|
32
|
-
packageJson.scripts[key] = value;
|
|
33
|
-
fs.writeFileSync(`${npmRoot}/package.json`, JSON.stringify(packageJson, null, 4));
|
|
34
|
-
},
|
|
35
|
-
/**
|
|
36
|
-
* @method run
|
|
37
|
-
* @description Runs a script.
|
|
38
|
-
* @param {string} key - The key for the script.
|
|
39
|
-
* @param {string} value - The value for the script.
|
|
40
|
-
* @param {object} options - The options for the script.
|
|
41
|
-
* @memberof UnderpostScript
|
|
42
|
-
*/
|
|
43
|
-
run(key, value, options) {
|
|
44
|
-
const npmRoot = `${getNpmRootPath()}/underpost`;
|
|
45
|
-
const packageJson = JSON.parse(fs.readFileSync(`${npmRoot}/package.json`, 'utf8'));
|
|
46
|
-
if (options.itc === true) {
|
|
47
|
-
value = packageJson.scripts[key];
|
|
48
|
-
const podScriptPath = `${options.itcPath && typeof options.itcPath === 'string' ? options.itcPath : '/'}${value
|
|
49
|
-
.split('/')
|
|
50
|
-
.pop()}`;
|
|
51
|
-
const nameSpace = options.ns && typeof options.ns === 'string' ? options.ns : 'default';
|
|
52
|
-
const podMatch = options.podName && typeof options.podName === 'string' ? options.podName : key;
|
|
53
|
-
|
|
54
|
-
if (fs.existsSync(`${value}`)) {
|
|
55
|
-
for (const pod of UnderpostDeploy.API.get(podMatch)) {
|
|
56
|
-
shellExec(`sudo kubectl cp ${value} ${nameSpace}/${pod.NAME}:${podScriptPath}`);
|
|
57
|
-
const cmd = `node ${podScriptPath}`;
|
|
58
|
-
shellExec(`sudo kubectl exec -i ${pod.NAME} -- sh -c "${cmd}"`);
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
for (const pod of UnderpostDeploy.API.get(podMatch)) {
|
|
62
|
-
shellExec(`sudo kubectl exec -i ${pod.NAME} -- sh -c "${value}"`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
shellExec(`cd ${npmRoot} && npm run ${key}`);
|
|
69
|
-
},
|
|
70
|
-
/**
|
|
71
|
-
* @method get
|
|
72
|
-
* @description Gets a script from the package.json file.
|
|
73
|
-
* @param {string} key - The key for the script.
|
|
74
|
-
* @memberof UnderpostScript
|
|
75
|
-
*/
|
|
76
|
-
get(key) {
|
|
77
|
-
const npmRoot = `${getNpmRootPath()}/underpost`;
|
|
78
|
-
const packageJson = JSON.parse(fs.readFileSync(`${npmRoot}/package.json`, 'utf8'));
|
|
79
|
-
logger.info('[get] ' + key, packageJson.scripts[key]);
|
|
80
|
-
return packageJson.scripts[key];
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export default UnderpostScript;
|
package/src/monitor.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// https://nodejs.org/api
|
|
4
|
-
// https://expressjs.com/en/4x/api.html
|
|
5
|
-
|
|
6
|
-
import dotenv from 'dotenv';
|
|
7
|
-
import { loggerFactory } from './server/logger.js';
|
|
8
|
-
import { ProcessController } from './server/process.js';
|
|
9
|
-
import { getUnderpostRootPath } from './server/conf.js';
|
|
10
|
-
import fs from 'fs-extra';
|
|
11
|
-
import UnderpostMonitor from './cli/monitor.js';
|
|
12
|
-
|
|
13
|
-
const underpostRootPath = getUnderpostRootPath();
|
|
14
|
-
fs.existsSync(`${underpostRootPath}/.env`)
|
|
15
|
-
? dotenv.config({ path: `${underpostRootPath}/.env`, override: true })
|
|
16
|
-
: dotenv.config();
|
|
17
|
-
|
|
18
|
-
const logger = loggerFactory(import.meta);
|
|
19
|
-
|
|
20
|
-
await logger.setUpInfo();
|
|
21
|
-
|
|
22
|
-
const deployId = process.argv[2];
|
|
23
|
-
const env = process.argv[3] || 'production';
|
|
24
|
-
const replicas = process.argv[4] || '1';
|
|
25
|
-
const namespace = process.argv[5] || 'default';
|
|
26
|
-
|
|
27
|
-
UnderpostMonitor.API.callback(deployId, env, {
|
|
28
|
-
type: 'blue-green',
|
|
29
|
-
sync: true,
|
|
30
|
-
replicas,
|
|
31
|
-
namespace,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
ProcessController.init(logger);
|