underpost 2.8.65 → 2.8.71

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.
Files changed (44) hide show
  1. package/.vscode/extensions.json +3 -2
  2. package/.vscode/settings.json +2 -0
  3. package/CHANGELOG.md +24 -4
  4. package/README.md +39 -2
  5. package/bin/deploy.js +1351 -145
  6. package/bin/file.js +8 -0
  7. package/bin/index.js +1 -240
  8. package/cli.md +451 -0
  9. package/docker-compose.yml +1 -1
  10. package/jsdoc.json +1 -1
  11. package/manifests/calico-custom-resources.yaml +25 -0
  12. package/manifests/deployment/adminer/deployment.yaml +32 -0
  13. package/manifests/deployment/adminer/kustomization.yaml +7 -0
  14. package/manifests/deployment/adminer/service.yaml +13 -0
  15. package/manifests/deployment/fastapi/backend-deployment.yml +120 -0
  16. package/manifests/deployment/fastapi/backend-service.yml +19 -0
  17. package/manifests/deployment/fastapi/frontend-deployment.yml +54 -0
  18. package/manifests/deployment/fastapi/frontend-service.yml +15 -0
  19. package/manifests/deployment/fastapi/initial_data.sh +56 -0
  20. package/manifests/deployment/kafka/deployment.yaml +69 -0
  21. package/manifests/kubeadm-calico-config.yaml +119 -0
  22. package/manifests/mongodb-4.4/service-deployment.yaml +1 -1
  23. package/manifests/postgresql/configmap.yaml +9 -0
  24. package/manifests/postgresql/kustomization.yaml +10 -0
  25. package/manifests/postgresql/pv.yaml +15 -0
  26. package/manifests/postgresql/pvc.yaml +13 -0
  27. package/manifests/postgresql/service.yaml +10 -0
  28. package/manifests/postgresql/statefulset.yaml +37 -0
  29. package/manifests/valkey/statefulset.yaml +6 -4
  30. package/package.json +2 -1
  31. package/src/cli/cluster.js +163 -18
  32. package/src/cli/deploy.js +68 -8
  33. package/src/cli/fs.js +14 -3
  34. package/src/cli/image.js +1 -1
  35. package/src/cli/index.js +312 -0
  36. package/src/cli/monitor.js +93 -39
  37. package/src/client/components/core/JoyStick.js +2 -2
  38. package/src/client/components/core/Modal.js +1 -0
  39. package/src/index.js +1 -1
  40. package/src/server/client-build.js +13 -0
  41. package/src/server/conf.js +5 -1
  42. package/src/server/dns.js +47 -17
  43. package/src/server/runtime.js +2 -0
  44. package/src/server/start.js +0 -1
package/src/server/dns.js CHANGED
@@ -5,6 +5,9 @@ import validator from 'validator';
5
5
  import { publicIp, publicIpv4, publicIpv6 } from 'public-ip';
6
6
  import { loggerFactory } from './logger.js';
7
7
  import UnderpostRootEnv from '../cli/env.js';
8
+ import dns from 'node:dns';
9
+ import os from 'node:os';
10
+ import { shellExec } from './process.js';
8
11
 
9
12
  dotenv.config();
10
13
 
@@ -18,35 +21,59 @@ const ip = {
18
21
  },
19
22
  };
20
23
 
24
+ const isInternetConnection = (domain = 'google.com') =>
25
+ new Promise((resolve) => dns.lookup(domain, {}, (err) => resolve(err ? false : true)));
26
+
27
+ // export INTERFACE=$(ip route | grep default | cut -d ' ' -f 5)
28
+ // export IP_ADDRESS=$(ip -4 addr show dev $INTERFACE | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
29
+ const getLocalIPv4Address = () =>
30
+ os.networkInterfaces()[
31
+ shellExec(`ip route | grep default | cut -d ' ' -f 5`, {
32
+ stdout: true,
33
+ silent: true,
34
+ disableLog: true,
35
+ }).trim()
36
+ ].find((i) => i.family === 'IPv4').address;
37
+
21
38
  class Dns {
22
39
  static callback = async function (deployList) {
23
40
  // Network topology configuration:
24
41
  // LAN -> [NAT-VPS](modem/router device) -> WAN
25
42
  // enabled DMZ Host to proxy IP 80-443 (79-444) sometimes router block first port
26
- // disabled local red DHCP
43
+
44
+ // Enabling DHCP
45
+ // Navigate to Subnets > VLAN > Configure DHCP.
46
+ // Select the appropriate DHCP options (Managed or Relay).
47
+ // Save and apply changes.
48
+
27
49
  // verify inet ip proxy server address
28
50
  // DHCP (Dynamic Host Configuration Protocol) LAN reserver IP -> MAC ID
29
51
  // LAN server or device's local servers port -> 3000-3100 (2999-3101)
30
52
  // DNS Records: [ANAME](Address Dynamic) -> [A](ipv4) host | [AAAA](ipv6) host -> [public-ip]
31
53
  // Forward the router's TCP/UDP ports to the LAN device's IP address
32
- for (const _deployId of deployList.split(',')) {
33
- const deployId = _deployId.trim();
34
- const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
35
- const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
36
- const confCronData = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
37
-
38
- let testIp;
39
-
40
- try {
41
- testIp = await ip.public.ipv4();
42
- } catch (error) {
43
- logger.error(error, { testIp, stack: error.stack });
44
- }
54
+ const isOnline = await isInternetConnection();
55
+
56
+ if (!isOnline) return;
45
57
 
46
- const currentIp = UnderpostRootEnv.API.get('ip');
58
+ let testIp;
47
59
 
48
- if (testIp && typeof testIp === 'string' && validator.isIP(testIp) && currentIp !== testIp) {
49
- logger.info(`new ip`, testIp);
60
+ try {
61
+ testIp = await ip.public.ipv4();
62
+ } catch (error) {
63
+ logger.error(error, { testIp, stack: error.stack });
64
+ }
65
+
66
+ const currentIp = UnderpostRootEnv.API.get('ip');
67
+
68
+ if (validator.isIP(testIp) && currentIp !== testIp) {
69
+ logger.info(`new ip`, testIp);
70
+ UnderpostRootEnv.API.set('monitor-input', 'pause');
71
+
72
+ for (const _deployId of deployList.split(',')) {
73
+ const deployId = _deployId.trim();
74
+ const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
75
+ const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
76
+ const confCronData = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
50
77
  for (const recordType of Object.keys(confCronData.records)) {
51
78
  switch (recordType) {
52
79
  case 'A':
@@ -68,6 +95,7 @@ class Dns {
68
95
  if (verifyIp === testIp) {
69
96
  logger.info('ip updated successfully', testIp);
70
97
  UnderpostRootEnv.API.set('ip', testIp);
98
+ UnderpostRootEnv.API.delete('monitor-input');
71
99
  } else logger.error('ip not updated', testIp);
72
100
  } catch (error) {
73
101
  logger.error(error, error.stack);
@@ -102,3 +130,5 @@ class Dns {
102
130
  }
103
131
 
104
132
  export default Dns;
133
+
134
+ export { Dns, ip, isInternetConnection, getLocalIPv4Address };
@@ -142,6 +142,8 @@ const buildRuntime = async () => {
142
142
  // if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
143
143
  // $_SERVER['HTTPS'] = 'on';
144
144
  // }
145
+ // For plugins:
146
+ // define( 'FS_METHOD', 'direct' );
145
147
 
146
148
  // ErrorDocument 404 /custom_404.html
147
149
  // ErrorDocument 500 /custom_50x.html
@@ -1,5 +1,4 @@
1
1
  import UnderpostDeploy from '../cli/deploy.js';
2
- import UnderpostMonitor from '../cli/monitor.js';
3
2
  import fs from 'fs-extra';
4
3
  import { awaitDeployMonitor } from './conf.js';
5
4
  import { actionInitLog, loggerFactory } from './logger.js';