underpost 2.8.1 → 2.8.7
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/.dockerignore +1 -0
- package/.github/workflows/ghpkg.yml +19 -49
- package/.github/workflows/npmpkg.yml +67 -0
- package/.github/workflows/publish.yml +5 -5
- package/.github/workflows/pwa-microservices-template.page.yml +12 -4
- package/.github/workflows/pwa-microservices-template.test.yml +2 -2
- package/.vscode/extensions.json +18 -71
- package/.vscode/settings.json +20 -3
- package/AUTHORS.md +16 -5
- package/CHANGELOG.md +123 -3
- package/Dockerfile +27 -70
- package/README.md +39 -29
- package/bin/build.js +186 -0
- package/bin/db.js +2 -24
- package/bin/deploy.js +1467 -236
- package/bin/file.js +67 -16
- package/bin/hwt.js +0 -10
- package/bin/index.js +1 -77
- package/bin/ssl.js +19 -11
- package/bin/util.js +9 -104
- package/bin/vs.js +26 -2
- package/cli.md +451 -0
- package/conf.js +29 -138
- package/docker-compose.yml +1 -1
- package/jsdoc.json +1 -1
- package/manifests/calico-custom-resources.yaml +25 -0
- package/manifests/deployment/adminer/deployment.yaml +32 -0
- package/manifests/deployment/adminer/kustomization.yaml +7 -0
- package/manifests/deployment/adminer/service.yaml +13 -0
- package/manifests/deployment/fastapi/backend-deployment.yml +120 -0
- package/manifests/deployment/fastapi/backend-service.yml +19 -0
- package/manifests/deployment/fastapi/frontend-deployment.yml +54 -0
- package/manifests/deployment/fastapi/frontend-service.yml +15 -0
- package/manifests/deployment/kafka/deployment.yaml +69 -0
- package/manifests/deployment/mongo-express/deployment.yaml +60 -0
- package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
- package/manifests/kind-config-dev.yaml +12 -0
- package/manifests/kind-config.yaml +12 -0
- package/manifests/kubeadm-calico-config.yaml +119 -0
- package/manifests/letsencrypt-prod.yaml +15 -0
- package/manifests/mariadb/config.yaml +10 -0
- package/manifests/mariadb/kustomization.yaml +9 -0
- package/manifests/mariadb/pv.yaml +12 -0
- package/manifests/mariadb/pvc.yaml +10 -0
- package/manifests/mariadb/secret.yaml +8 -0
- package/manifests/mariadb/service.yaml +10 -0
- package/manifests/mariadb/statefulset.yaml +55 -0
- package/manifests/mongodb/backup-access.yaml +16 -0
- package/manifests/mongodb/backup-cronjob.yaml +42 -0
- package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
- package/manifests/mongodb/configmap.yaml +26 -0
- package/manifests/mongodb/headless-service.yaml +10 -0
- package/manifests/mongodb/kustomization.yaml +11 -0
- package/manifests/mongodb/pv-pvc.yaml +23 -0
- package/manifests/mongodb/statefulset.yaml +125 -0
- package/manifests/mongodb-4.4/kustomization.yaml +7 -0
- package/manifests/mongodb-4.4/pv-pvc.yaml +23 -0
- package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
- package/manifests/postgresql/configmap.yaml +9 -0
- package/manifests/postgresql/kustomization.yaml +10 -0
- package/manifests/postgresql/pv.yaml +15 -0
- package/manifests/postgresql/pvc.yaml +13 -0
- package/manifests/postgresql/service.yaml +10 -0
- package/manifests/postgresql/statefulset.yaml +37 -0
- package/manifests/valkey/kustomization.yaml +7 -0
- package/manifests/valkey/service.yaml +17 -0
- package/manifests/valkey/statefulset.yaml +41 -0
- package/package.json +127 -136
- package/src/api/core/core.service.js +1 -1
- package/src/api/default/default.service.js +1 -1
- package/src/api/user/user.model.js +16 -3
- package/src/api/user/user.service.js +15 -12
- package/src/cli/cluster.js +389 -0
- package/src/cli/cron.js +121 -0
- package/src/cli/db.js +222 -0
- package/src/cli/deploy.js +487 -0
- package/src/cli/env.js +58 -0
- package/src/cli/fs.js +161 -0
- package/src/cli/image.js +66 -0
- package/src/cli/index.js +312 -0
- package/src/cli/monitor.js +236 -0
- package/src/cli/repository.js +128 -0
- package/src/cli/script.js +53 -0
- package/src/cli/secrets.js +37 -0
- package/src/cli/test.js +118 -0
- package/src/client/components/core/Account.js +28 -24
- package/src/client/components/core/Auth.js +22 -4
- package/src/client/components/core/Blockchain.js +1 -1
- package/src/client/components/core/CalendarCore.js +128 -121
- package/src/client/components/core/CommonJs.js +283 -19
- package/src/client/components/core/CssCore.js +16 -4
- package/src/client/components/core/Docs.js +1 -2
- package/src/client/components/core/DropDown.js +5 -1
- package/src/client/components/core/EventsUI.js +3 -3
- package/src/client/components/core/FileExplorer.js +86 -78
- package/src/client/components/core/Input.js +22 -6
- package/src/client/components/core/JoyStick.js +2 -2
- package/src/client/components/core/LoadingAnimation.js +3 -12
- package/src/client/components/core/LogIn.js +3 -3
- package/src/client/components/core/LogOut.js +1 -1
- package/src/client/components/core/Modal.js +54 -20
- package/src/client/components/core/Panel.js +109 -90
- package/src/client/components/core/PanelForm.js +23 -30
- package/src/client/components/core/Recover.js +3 -3
- package/src/client/components/core/RichText.js +1 -11
- package/src/client/components/core/Router.js +3 -1
- package/src/client/components/core/Scroll.js +1 -0
- package/src/client/components/core/SignUp.js +2 -2
- package/src/client/components/core/Translate.js +47 -9
- package/src/client/components/core/Validator.js +9 -1
- package/src/client/components/core/VanillaJs.js +0 -9
- package/src/client/components/core/Worker.js +34 -31
- package/src/client/components/default/RoutesDefault.js +3 -2
- package/src/client/services/core/core.service.js +15 -10
- package/src/client/services/default/default.management.js +46 -37
- package/src/client/ssr/Render.js +6 -1
- package/src/client/ssr/body/CacheControl.js +2 -3
- package/src/client/sw/default.sw.js +3 -3
- package/src/db/mongo/MongooseDB.js +29 -1
- package/src/index.js +101 -19
- package/src/mailer/MailerProvider.js +3 -0
- package/src/runtime/lampp/Dockerfile +65 -0
- package/src/runtime/lampp/Lampp.js +1 -13
- package/src/runtime/xampp/Xampp.js +0 -13
- package/src/server/auth.js +3 -3
- package/src/server/backup.js +49 -93
- package/src/server/client-build.js +49 -46
- package/src/server/client-formatted.js +6 -3
- package/src/server/conf.js +297 -55
- package/src/server/dns.js +75 -62
- package/src/server/downloader.js +0 -8
- package/src/server/json-schema.js +77 -0
- package/src/server/logger.js +15 -10
- package/src/server/network.js +20 -161
- package/src/server/peer.js +2 -2
- package/src/server/process.js +25 -2
- package/src/server/proxy.js +7 -29
- package/src/server/runtime.js +53 -40
- package/src/server/ssl.js +1 -1
- package/src/server/start.js +122 -0
- package/src/server/valkey.js +27 -11
- package/test/api.test.js +0 -8
- package/src/dns.js +0 -22
- package/src/server/prompt-optimizer.js +0 -28
- package/startup.js +0 -11
package/src/server/runtime.js
CHANGED
|
@@ -9,17 +9,19 @@ import compression from 'compression';
|
|
|
9
9
|
|
|
10
10
|
import { createServer } from 'http';
|
|
11
11
|
import { getRootDirectory } from './process.js';
|
|
12
|
-
import
|
|
12
|
+
import UnderpostStartUp from './start.js';
|
|
13
13
|
import { loggerFactory, loggerMiddleware } from './logger.js';
|
|
14
14
|
import { getCapVariableName, newInstance } from '../client/components/core/CommonJs.js';
|
|
15
15
|
import { Xampp } from '../runtime/xampp/Xampp.js';
|
|
16
16
|
import { MailerProvider } from '../mailer/MailerProvider.js';
|
|
17
17
|
import { DataBaseProvider } from '../db/DataBaseProvider.js';
|
|
18
|
-
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
18
|
+
// import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
19
19
|
import { createPeerServer } from './peer.js';
|
|
20
20
|
import { Lampp } from '../runtime/lampp/Lampp.js';
|
|
21
21
|
import { getDeployId } from './conf.js';
|
|
22
|
-
import { ssrFactory } from './client-formatted.js';
|
|
22
|
+
import { JSONweb, ssrFactory } from './client-formatted.js';
|
|
23
|
+
import Underpost from '../index.js';
|
|
24
|
+
import { createValkeyConnection } from './valkey.js';
|
|
23
25
|
|
|
24
26
|
dotenv.config();
|
|
25
27
|
|
|
@@ -31,20 +33,6 @@ const buildRuntime = async () => {
|
|
|
31
33
|
const collectDefaultMetrics = promClient.collectDefaultMetrics;
|
|
32
34
|
collectDefaultMetrics();
|
|
33
35
|
|
|
34
|
-
if (fs.existsSync(`/root/.bashrc`) && !fs.readFileSync(`/root/.bashrc`, 'utf8').match(`underpost-engine`)) {
|
|
35
|
-
fs.writeFileSync(
|
|
36
|
-
`/root/.bashrc`,
|
|
37
|
-
`${fs.readFileSync(`/root/.bashrc`, 'utf8')}
|
|
38
|
-
` +
|
|
39
|
-
`export NVM_DIR="$HOME/.nvm"
|
|
40
|
-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
|
41
|
-
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm underpost-engine bash_completion
|
|
42
|
-
|
|
43
|
-
export PATH=$PATH:/opt/lampp/bin`,
|
|
44
|
-
'utf8',
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
36
|
const promCounterOption = {
|
|
49
37
|
name: `${deployId.replaceAll('-', '_')}_http_requests_total`,
|
|
50
38
|
help: 'Total number of HTTP requests',
|
|
@@ -54,8 +42,6 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
54
42
|
// logger.info('promCounterOption', promCounterOption);
|
|
55
43
|
|
|
56
44
|
const requestCounter = new promClient.Counter(promCounterOption);
|
|
57
|
-
|
|
58
|
-
const ipInstance = ''; // await ip.public.ipv4();
|
|
59
45
|
const initPort = parseInt(process.env.PORT) + 1;
|
|
60
46
|
let currentPort = initPort;
|
|
61
47
|
const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
|
|
@@ -82,6 +68,7 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
82
68
|
peer,
|
|
83
69
|
singleReplica,
|
|
84
70
|
replicas,
|
|
71
|
+
valkey,
|
|
85
72
|
} = confServer[host][path];
|
|
86
73
|
|
|
87
74
|
if (singleReplica && replicas && replicas.length > 0 && !singleReplicaHosts.includes(host)) {
|
|
@@ -101,12 +88,13 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
101
88
|
apis,
|
|
102
89
|
};
|
|
103
90
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
const redirectTarget = redirect
|
|
92
|
+
? redirect[redirect.length - 1] === '/'
|
|
93
|
+
? redirect.slice(0, -1)
|
|
94
|
+
: redirect
|
|
95
|
+
: undefined;
|
|
96
|
+
|
|
97
|
+
// if (redirect) logger.info('redirect', new URL(redirect));
|
|
110
98
|
|
|
111
99
|
switch (runtime) {
|
|
112
100
|
case 'lampp':
|
|
@@ -154,6 +142,8 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
154
142
|
// if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
|
|
155
143
|
// $_SERVER['HTTPS'] = 'on';
|
|
156
144
|
// }
|
|
145
|
+
// For plugins:
|
|
146
|
+
// define( 'FS_METHOD', 'direct' );
|
|
157
147
|
|
|
158
148
|
// ErrorDocument 404 /custom_404.html
|
|
159
149
|
// ErrorDocument 500 /custom_50x.html
|
|
@@ -196,7 +186,11 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
196
186
|
// RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
|
|
197
187
|
// RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
|
|
198
188
|
|
|
199
|
-
await listenPortController(
|
|
189
|
+
await UnderpostStartUp.API.listenPortController(
|
|
190
|
+
UnderpostStartUp.API.listenServerFactory(),
|
|
191
|
+
port,
|
|
192
|
+
runningData,
|
|
193
|
+
);
|
|
200
194
|
break;
|
|
201
195
|
case 'xampp':
|
|
202
196
|
if (!Xampp.enabled()) continue;
|
|
@@ -243,7 +237,11 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
243
237
|
// if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
|
|
244
238
|
// $_SERVER['HTTPS'] = 'on';
|
|
245
239
|
// }
|
|
246
|
-
await listenPortController(
|
|
240
|
+
await UnderpostStartUp.API.listenPortController(
|
|
241
|
+
UnderpostStartUp.API.listenServerFactory(),
|
|
242
|
+
port,
|
|
243
|
+
runningData,
|
|
244
|
+
);
|
|
247
245
|
break;
|
|
248
246
|
case 'nodejs':
|
|
249
247
|
const app = express();
|
|
@@ -295,8 +293,8 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
295
293
|
logger.info('Build static server runtime', `${host}${path}`);
|
|
296
294
|
currentPort += 2;
|
|
297
295
|
const staticPort = newInstance(currentPort);
|
|
298
|
-
|
|
299
|
-
await listenPortController(app, staticPort, runningData);
|
|
296
|
+
|
|
297
|
+
await UnderpostStartUp.API.listenPortController(app, staticPort, runningData);
|
|
300
298
|
currentPort++;
|
|
301
299
|
continue;
|
|
302
300
|
}
|
|
@@ -346,8 +344,8 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
346
344
|
// changeOrigin: true,
|
|
347
345
|
// }),
|
|
348
346
|
// );
|
|
349
|
-
|
|
350
|
-
await listenPortController(app, port, runningData);
|
|
347
|
+
|
|
348
|
+
await UnderpostStartUp.API.listenPortController(app, port, runningData);
|
|
351
349
|
break;
|
|
352
350
|
}
|
|
353
351
|
|
|
@@ -367,6 +365,9 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
367
365
|
|
|
368
366
|
if (db && apis) await DataBaseProvider.load({ apis, host, path, db });
|
|
369
367
|
|
|
368
|
+
// valkey server
|
|
369
|
+
await createValkeyConnection({ host, path }, valkey);
|
|
370
|
+
|
|
370
371
|
if (mailer) {
|
|
371
372
|
const mailerSsrConf = confSSR[getCapVariableName(client)];
|
|
372
373
|
await MailerProvider.load({
|
|
@@ -398,6 +399,13 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
398
399
|
ssrPath,
|
|
399
400
|
ssrHeadComponents: '',
|
|
400
401
|
ssrBodyComponents: (await ssrFactory(`./src/client/ssr/body/404.js`))(),
|
|
402
|
+
renderPayload: {
|
|
403
|
+
apiBasePath: process.env.BASE_API,
|
|
404
|
+
version: Underpost.version,
|
|
405
|
+
},
|
|
406
|
+
renderApi: {
|
|
407
|
+
JSONweb,
|
|
408
|
+
},
|
|
401
409
|
});
|
|
402
410
|
const path404 = `${directory ? directory : `${getRootDirectory()}${rootHostPath}`}/404/index.html`;
|
|
403
411
|
const page404 = fs.existsSync(path404) ? `${path === '/' ? '' : path}/404` : undefined;
|
|
@@ -414,6 +422,13 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
414
422
|
ssrPath,
|
|
415
423
|
ssrHeadComponents: '',
|
|
416
424
|
ssrBodyComponents: (await ssrFactory(`./src/client/ssr/body/500.js`))(),
|
|
425
|
+
renderPayload: {
|
|
426
|
+
apiBasePath: process.env.BASE_API,
|
|
427
|
+
version: Underpost.version,
|
|
428
|
+
},
|
|
429
|
+
renderApi: {
|
|
430
|
+
JSONweb,
|
|
431
|
+
},
|
|
417
432
|
});
|
|
418
433
|
const path500 = `${directory ? directory : `${getRootDirectory()}${rootHostPath}`}/500/index.html`;
|
|
419
434
|
const page500 = fs.existsSync(path500) ? `${path === '/' ? '' : path}/500` : undefined;
|
|
@@ -441,7 +456,7 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
441
456
|
port,
|
|
442
457
|
origins,
|
|
443
458
|
});
|
|
444
|
-
await listenPortController(listenServerFactory(), port, {
|
|
459
|
+
await UnderpostStartUp.API.listenPortController(UnderpostStartUp.API.listenServerFactory(), port, {
|
|
445
460
|
runtime: 'nodejs',
|
|
446
461
|
client: null,
|
|
447
462
|
host,
|
|
@@ -460,8 +475,8 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
460
475
|
host,
|
|
461
476
|
path,
|
|
462
477
|
});
|
|
463
|
-
|
|
464
|
-
await listenPortController(peerServer, peerPort, {
|
|
478
|
+
|
|
479
|
+
await UnderpostStartUp.API.listenPortController(peerServer, peerPort, {
|
|
465
480
|
runtime: 'nodejs',
|
|
466
481
|
client: null,
|
|
467
482
|
host,
|
|
@@ -470,8 +485,7 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
470
485
|
});
|
|
471
486
|
}
|
|
472
487
|
|
|
473
|
-
await
|
|
474
|
-
await listenPortController(server, port, runningData);
|
|
488
|
+
await UnderpostStartUp.API.listenPortController(server, port, runningData);
|
|
475
489
|
|
|
476
490
|
break;
|
|
477
491
|
default:
|
|
@@ -481,11 +495,10 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
481
495
|
}
|
|
482
496
|
}
|
|
483
497
|
|
|
484
|
-
if (Xampp.enabled() && Xampp.router)
|
|
485
|
-
if (Lampp.enabled() && Lampp.router)
|
|
498
|
+
if (Xampp.enabled() && Xampp.router) Xampp.initService();
|
|
499
|
+
if (Lampp.enabled() && Lampp.router) Lampp.initService();
|
|
486
500
|
|
|
487
|
-
|
|
488
|
-
logRuntimeRouter();
|
|
501
|
+
UnderpostStartUp.API.logRuntimeRouter();
|
|
489
502
|
};
|
|
490
503
|
|
|
491
504
|
export { buildRuntime };
|
package/src/server/ssl.js
CHANGED
|
@@ -70,7 +70,7 @@ const validateSecureContext = (host) => {
|
|
|
70
70
|
const buildSecureContext = (host) => {
|
|
71
71
|
return {
|
|
72
72
|
key: fs.readFileSync(`./engine-private/ssl/${host}/key.key`, 'utf8'),
|
|
73
|
-
cert: fs.readFileSync(`./engine-private/ssl/${host}/
|
|
73
|
+
cert: fs.readFileSync(`./engine-private/ssl/${host}/ca_bundle.crt`, 'utf8'),
|
|
74
74
|
ca: fs.readFileSync(`./engine-private/ssl/${host}/ca_bundle.crt`, 'utf8'),
|
|
75
75
|
};
|
|
76
76
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import UnderpostDeploy from '../cli/deploy.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { awaitDeployMonitor } from './conf.js';
|
|
4
|
+
import { actionInitLog, loggerFactory } from './logger.js';
|
|
5
|
+
import { shellCd, shellExec } from './process.js';
|
|
6
|
+
import UnderpostRootEnv from '../cli/env.js';
|
|
7
|
+
|
|
8
|
+
const logger = loggerFactory(import.meta);
|
|
9
|
+
|
|
10
|
+
class UnderpostStartUp {
|
|
11
|
+
static API = {
|
|
12
|
+
logRuntimeRouter: () => {
|
|
13
|
+
const displayLog = {};
|
|
14
|
+
|
|
15
|
+
for (const host of Object.keys(UnderpostDeploy.NETWORK))
|
|
16
|
+
for (const path of Object.keys(UnderpostDeploy.NETWORK[host]))
|
|
17
|
+
displayLog[UnderpostDeploy.NETWORK[host][path].publicHost] = UnderpostDeploy.NETWORK[host][path].local;
|
|
18
|
+
|
|
19
|
+
logger.info('Runtime network', displayLog);
|
|
20
|
+
},
|
|
21
|
+
listenServerFactory: (logic = async () => {}) => {
|
|
22
|
+
return {
|
|
23
|
+
listen: async (...args) => {
|
|
24
|
+
const msDelta = 1000;
|
|
25
|
+
const msMax = 30 * 24 * 60 * 60 * 1000; // ~ 1 month
|
|
26
|
+
let msCount = 0;
|
|
27
|
+
setInterval(() => {
|
|
28
|
+
msCount += msDelta;
|
|
29
|
+
if (msCount >= msMax) {
|
|
30
|
+
const message = 'Listen server factory timeout';
|
|
31
|
+
logger.error(message);
|
|
32
|
+
throw new Error(message);
|
|
33
|
+
}
|
|
34
|
+
}, msDelta);
|
|
35
|
+
return logic ? await logic(...args) : undefined, args[1]();
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
listenPortController: async (server, port, metadata) =>
|
|
40
|
+
new Promise((resolve) => {
|
|
41
|
+
try {
|
|
42
|
+
if (port === ':') {
|
|
43
|
+
server.listen(port, actionInitLog);
|
|
44
|
+
return resolve(true);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { host, path, client, runtime, meta } = metadata;
|
|
48
|
+
const error = [];
|
|
49
|
+
if (port === undefined) error.push(`port`);
|
|
50
|
+
if (host === undefined) error.push(`host`);
|
|
51
|
+
if (path === undefined) error.push(`path`);
|
|
52
|
+
if (client === undefined) error.push(`client`);
|
|
53
|
+
if (runtime === undefined) error.push(`runtime`);
|
|
54
|
+
if (meta === undefined) error.push(`meta`);
|
|
55
|
+
if (error.length > 0) throw new Error('Listen port controller requires values: ' + error.join(', '));
|
|
56
|
+
|
|
57
|
+
server.listen(port, () => {
|
|
58
|
+
if (!UnderpostDeploy.NETWORK[host]) UnderpostDeploy.NETWORK[host] = {};
|
|
59
|
+
UnderpostDeploy.NETWORK[host][path] = {
|
|
60
|
+
meta,
|
|
61
|
+
client,
|
|
62
|
+
runtime,
|
|
63
|
+
port,
|
|
64
|
+
publicHost:
|
|
65
|
+
port === 80
|
|
66
|
+
? `http://${host}${path}`
|
|
67
|
+
: port === 443
|
|
68
|
+
? `https://${host}${path}`
|
|
69
|
+
: `http://${host}:${port}${path}`,
|
|
70
|
+
local: `http://localhost:${port}${path}`,
|
|
71
|
+
apis: metadata.apis,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return resolve(true);
|
|
75
|
+
});
|
|
76
|
+
} catch (error) {
|
|
77
|
+
logger.error(error, { metadata, port, stack: error.stack });
|
|
78
|
+
resolve(false);
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
|
|
82
|
+
async callback(deployId = 'default', env = 'development', options = { build: false, run: false }) {
|
|
83
|
+
if (options.build === true) await UnderpostStartUp.API.build(deployId, env);
|
|
84
|
+
if (options.run === true) await UnderpostStartUp.API.run(deployId, env);
|
|
85
|
+
},
|
|
86
|
+
async build(deployId = 'default', env = 'development') {
|
|
87
|
+
const buildBasePath = `/home/dd`;
|
|
88
|
+
const repoName = `engine-${deployId.split('-')[1]}`;
|
|
89
|
+
shellExec(`cd ${buildBasePath} && underpost clone underpostnet/${repoName}`);
|
|
90
|
+
shellExec(`cd ${buildBasePath} && sudo mv ./${repoName} ./engine`);
|
|
91
|
+
shellExec(`cd ${buildBasePath}/engine && underpost clone underpostnet/${repoName}-private`);
|
|
92
|
+
shellExec(`cd ${buildBasePath}/engine && sudo mv ./${repoName}-private ./engine-private`);
|
|
93
|
+
shellCd(`${buildBasePath}/engine`);
|
|
94
|
+
shellExec(`npm install`);
|
|
95
|
+
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
96
|
+
if (fs.existsSync('./engine-private/itc-scripts')) {
|
|
97
|
+
const itcScripts = await fs.readdir('./engine-private/itc-scripts');
|
|
98
|
+
for (const itcScript of itcScripts)
|
|
99
|
+
if (itcScript.match(deployId)) shellExec(`node ./engine-private/itc-scripts/${itcScript}`);
|
|
100
|
+
}
|
|
101
|
+
shellExec(`node bin/deploy build-full-client ${deployId}`);
|
|
102
|
+
},
|
|
103
|
+
async run(deployId = 'default', env = 'development') {
|
|
104
|
+
const runCmd = env === 'production' ? 'run prod-img' : 'run dev-img';
|
|
105
|
+
if (fs.existsSync(`./engine-private/replica`)) {
|
|
106
|
+
const replicas = await fs.readdir(`./engine-private/replica`);
|
|
107
|
+
for (const replica of replicas) {
|
|
108
|
+
if (!replica.match(deployId)) continue;
|
|
109
|
+
shellExec(`node bin/deploy conf ${replica} ${env}`);
|
|
110
|
+
shellExec(`npm ${runCmd} deploy deploy-id:${replica}`, { async: true });
|
|
111
|
+
await awaitDeployMonitor(true);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
115
|
+
shellExec(`npm ${runCmd} deploy deploy-id:${deployId}`, { async: true });
|
|
116
|
+
await awaitDeployMonitor(true);
|
|
117
|
+
UnderpostRootEnv.API.set('container-status', `${deployId}-${env}-running-deployment`);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default UnderpostStartUp;
|
package/src/server/valkey.js
CHANGED
|
@@ -5,12 +5,24 @@ import { loggerFactory } from './logger.js';
|
|
|
5
5
|
|
|
6
6
|
const logger = loggerFactory(import.meta);
|
|
7
7
|
|
|
8
|
+
const ValkeyInstances = {};
|
|
9
|
+
|
|
8
10
|
let valkeyEnabled = true;
|
|
9
11
|
|
|
10
12
|
const disableValkeyErrorMessage = 'valkey is not enabled';
|
|
11
13
|
|
|
12
14
|
const isValkeyEnable = () => valkeyEnabled;
|
|
13
15
|
|
|
16
|
+
const createValkeyConnection = async (
|
|
17
|
+
instance = { host: '', port: 0 },
|
|
18
|
+
valkeyServerConnectionOptions = { host: '', port: 0 },
|
|
19
|
+
) => {
|
|
20
|
+
ValkeyInstances[`${instance.host}${instance.path}`] = await ValkeyAPI.valkeyClientFactory(
|
|
21
|
+
valkeyServerConnectionOptions,
|
|
22
|
+
);
|
|
23
|
+
return ValkeyInstances[`${instance.host}${instance.path}`];
|
|
24
|
+
};
|
|
25
|
+
|
|
14
26
|
const selectDtoFactory = (payload, select) => {
|
|
15
27
|
const result = {};
|
|
16
28
|
for (const key of Object.keys(select)) {
|
|
@@ -19,8 +31,12 @@ const selectDtoFactory = (payload, select) => {
|
|
|
19
31
|
return result;
|
|
20
32
|
};
|
|
21
33
|
|
|
22
|
-
const valkeyClientFactory = async () => {
|
|
34
|
+
const valkeyClientFactory = async (options) => {
|
|
23
35
|
const valkey = new Valkey({
|
|
36
|
+
// port: 6379,
|
|
37
|
+
// host: 'service-valkey.default.svc.cluster.local',
|
|
38
|
+
port: options?.port ? options.port : undefined,
|
|
39
|
+
host: options?.port ? options.host : undefined,
|
|
24
40
|
retryStrategy: (attempt) => {
|
|
25
41
|
if (attempt === 1) {
|
|
26
42
|
valkey.disconnect();
|
|
@@ -44,12 +60,12 @@ const valkeyClientFactory = async () => {
|
|
|
44
60
|
return valkey;
|
|
45
61
|
};
|
|
46
62
|
|
|
47
|
-
const getValkeyObject = async (key = '') => {
|
|
63
|
+
const getValkeyObject = async (options = { host: '', port: 0 }, key = '') => {
|
|
48
64
|
if (!valkeyEnabled) {
|
|
49
65
|
logger.warn(disableValkeyErrorMessage + ' get', key);
|
|
50
66
|
return null;
|
|
51
67
|
}
|
|
52
|
-
const object = await
|
|
68
|
+
const object = await ValkeyInstances[`${options.host}${options.path}`].get(key);
|
|
53
69
|
try {
|
|
54
70
|
return JSON.parse(object);
|
|
55
71
|
} catch (error) {
|
|
@@ -58,19 +74,19 @@ const getValkeyObject = async (key = '') => {
|
|
|
58
74
|
}
|
|
59
75
|
};
|
|
60
76
|
|
|
61
|
-
const setValkeyObject = async (key = '', payload = {}) => {
|
|
77
|
+
const setValkeyObject = async (options = { host: '', port: 0 }, key = '', payload = {}) => {
|
|
62
78
|
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
63
|
-
return await
|
|
79
|
+
return await ValkeyInstances[`${options.host}${options.path}`].set(key, JSON.stringify(payload));
|
|
64
80
|
};
|
|
65
81
|
|
|
66
|
-
const updateValkeyObject = async (key = '', payload = {}) => {
|
|
82
|
+
const updateValkeyObject = async (options = { host: '', port: 0 }, key = '', payload = {}) => {
|
|
67
83
|
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
68
|
-
const object = await getValkeyObject(key
|
|
84
|
+
const object = await getValkeyObject(key);
|
|
69
85
|
object.updatedAt = new Date().toISOString();
|
|
70
|
-
return await
|
|
86
|
+
return await ValkeyInstances[`${options.host}${options.path}`].set(key, JSON.stringify({ ...object, ...payload }));
|
|
71
87
|
};
|
|
72
88
|
|
|
73
|
-
const valkeyObjectFactory = async (
|
|
89
|
+
const valkeyObjectFactory = async (options = { host: 'localhost', object: {} }, module = '') => {
|
|
74
90
|
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
75
91
|
const idoDate = new Date().toISOString();
|
|
76
92
|
options.object = options.object || {};
|
|
@@ -110,10 +126,9 @@ const ValkeyAPI = {
|
|
|
110
126
|
setValkeyObject,
|
|
111
127
|
valkeyObjectFactory,
|
|
112
128
|
updateValkeyObject,
|
|
129
|
+
createValkeyConnection,
|
|
113
130
|
};
|
|
114
131
|
|
|
115
|
-
const valkey = await ValkeyAPI.valkeyClientFactory();
|
|
116
|
-
|
|
117
132
|
export {
|
|
118
133
|
valkeyClientFactory,
|
|
119
134
|
selectDtoFactory,
|
|
@@ -122,5 +137,6 @@ export {
|
|
|
122
137
|
valkeyObjectFactory,
|
|
123
138
|
updateValkeyObject,
|
|
124
139
|
isValkeyEnable,
|
|
140
|
+
createValkeyConnection,
|
|
125
141
|
ValkeyAPI,
|
|
126
142
|
};
|
package/test/api.test.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import dotenv from 'dotenv';
|
|
5
|
-
import https from 'https';
|
|
6
5
|
|
|
7
6
|
import { expect } from 'chai';
|
|
8
7
|
import { loggerFactory } from '../src/server/logger.js';
|
|
@@ -20,13 +19,6 @@ const BASE_URL =
|
|
|
20
19
|
? `http://localhost:${PORT}/${process.env.BASE_API}`
|
|
21
20
|
: `https://www.nexodev.org/api`;
|
|
22
21
|
|
|
23
|
-
axios.defaults.baseURL = BASE_URL;
|
|
24
|
-
|
|
25
|
-
const httpsAgent = new https.Agent({
|
|
26
|
-
rejectUnauthorized: false,
|
|
27
|
-
});
|
|
28
|
-
axios.defaults.httpsAgent = httpsAgent;
|
|
29
|
-
|
|
30
22
|
describe(`GET 'Test' API Request `, async () => {
|
|
31
23
|
{
|
|
32
24
|
const url = `${BASE_URL}/test/youtube-id/?url=https://www.youtube.com/watch?v=o4f42SbyDMk`;
|
package/src/dns.js
DELETED
|
@@ -1,22 +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 { Dns } from './server/dns.js';
|
|
9
|
-
import { ProcessController } from './server/process.js';
|
|
10
|
-
import { Config } from './server/conf.js';
|
|
11
|
-
|
|
12
|
-
dotenv.config();
|
|
13
|
-
|
|
14
|
-
await Config.build();
|
|
15
|
-
|
|
16
|
-
const logger = loggerFactory(import.meta);
|
|
17
|
-
|
|
18
|
-
await logger.setUpInfo();
|
|
19
|
-
|
|
20
|
-
await Dns.InitIpDaemon();
|
|
21
|
-
|
|
22
|
-
ProcessController.init(logger);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// https://github.com/xenova/transformers.js/blob/f43d3dd348fd7b293008802590bb3a1afa218dc7/src/models.js#L10
|
|
2
|
-
|
|
3
|
-
import { AutoModelForSeq2SeqLM, AutoTokenizer } from '@xenova/transformers';
|
|
4
|
-
import { loggerFactory } from './logger.js';
|
|
5
|
-
import dotenv from 'dotenv';
|
|
6
|
-
|
|
7
|
-
dotenv.config();
|
|
8
|
-
|
|
9
|
-
const logger = loggerFactory(import.meta);
|
|
10
|
-
|
|
11
|
-
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/t5-small');
|
|
12
|
-
|
|
13
|
-
const model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small');
|
|
14
|
-
|
|
15
|
-
const prompt = 'translate English to German: I love transformers!';
|
|
16
|
-
|
|
17
|
-
logger.info('input', { prompt });
|
|
18
|
-
|
|
19
|
-
const tokenizerData = await tokenizer(prompt);
|
|
20
|
-
|
|
21
|
-
const { input_ids } = tokenizerData;
|
|
22
|
-
|
|
23
|
-
const outputs = await model.generate(input_ids);
|
|
24
|
-
|
|
25
|
-
for (const output of outputs) {
|
|
26
|
-
const decoded = tokenizer.decode(output, { skip_special_tokens: true });
|
|
27
|
-
logger.info('decoded', { decoded });
|
|
28
|
-
}
|
package/startup.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { shellExec } from './src/server/process.js';
|
|
2
|
-
|
|
3
|
-
// /usr/bin/supervisord -n
|
|
4
|
-
// /usr/sbin/sshd -D
|
|
5
|
-
shellExec(`/usr/bin/supervisord -n`, { async: true });
|
|
6
|
-
|
|
7
|
-
shellExec(`sudo /opt/lampp/lampp start`, { async: true });
|
|
8
|
-
|
|
9
|
-
shellExec(`/usr/bin/mongod -f /etc/mongod.conf`, { async: true });
|
|
10
|
-
|
|
11
|
-
shellExec(`underpost new app server`);
|