@underpostnet/underpost 2.8.5 → 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.
Files changed (109) hide show
  1. package/.github/workflows/ghpkg.yml +1 -1
  2. package/.github/workflows/npmpkg.yml +1 -1
  3. package/.github/workflows/pwa-microservices-template.page.yml +1 -1
  4. package/.vscode/extensions.json +3 -2
  5. package/.vscode/settings.json +6 -0
  6. package/CHANGELOG.md +44 -0
  7. package/Dockerfile +9 -10
  8. package/README.md +39 -2
  9. package/bin/build.js +31 -6
  10. package/bin/deploy.js +1404 -202
  11. package/bin/file.js +8 -0
  12. package/bin/hwt.js +0 -10
  13. package/bin/index.js +1 -187
  14. package/bin/util.js +0 -7
  15. package/bin/vs.js +1 -0
  16. package/cli.md +451 -0
  17. package/conf.js +0 -2
  18. package/docker-compose.yml +1 -1
  19. package/jsdoc.json +1 -1
  20. package/manifests/calico-custom-resources.yaml +25 -0
  21. package/manifests/deployment/adminer/deployment.yaml +32 -0
  22. package/manifests/deployment/adminer/kustomization.yaml +7 -0
  23. package/manifests/deployment/adminer/service.yaml +13 -0
  24. package/manifests/deployment/fastapi/backend-deployment.yml +120 -0
  25. package/manifests/deployment/fastapi/backend-service.yml +19 -0
  26. package/manifests/deployment/fastapi/frontend-deployment.yml +54 -0
  27. package/manifests/deployment/fastapi/frontend-service.yml +15 -0
  28. package/manifests/deployment/kafka/deployment.yaml +69 -0
  29. package/manifests/kind-config-dev.yaml +12 -0
  30. package/manifests/kubeadm-calico-config.yaml +119 -0
  31. package/manifests/mongodb/kustomization.yaml +2 -2
  32. package/manifests/mongodb-4.4/kustomization.yaml +7 -0
  33. package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
  34. package/manifests/postgresql/configmap.yaml +9 -0
  35. package/manifests/postgresql/kustomization.yaml +10 -0
  36. package/manifests/postgresql/pv.yaml +15 -0
  37. package/manifests/postgresql/pvc.yaml +13 -0
  38. package/manifests/{core/underpost-engine-headless-service.yaml → postgresql/service.yaml} +3 -3
  39. package/manifests/postgresql/statefulset.yaml +37 -0
  40. package/manifests/valkey/statefulset.yaml +6 -4
  41. package/package.json +10 -14
  42. package/src/api/default/default.service.js +1 -1
  43. package/src/api/user/user.service.js +14 -11
  44. package/src/cli/cluster.js +298 -63
  45. package/src/cli/cron.js +39 -8
  46. package/src/cli/db.js +118 -44
  47. package/src/cli/deploy.js +312 -102
  48. package/src/cli/env.js +9 -3
  49. package/src/cli/fs.js +161 -0
  50. package/src/cli/image.js +45 -104
  51. package/src/cli/index.js +312 -0
  52. package/src/cli/monitor.js +236 -0
  53. package/src/cli/repository.js +26 -2
  54. package/src/cli/script.js +25 -1
  55. package/src/cli/test.js +39 -4
  56. package/src/client/components/core/Account.js +28 -24
  57. package/src/client/components/core/Blockchain.js +1 -1
  58. package/src/client/components/core/CalendarCore.js +14 -73
  59. package/src/client/components/core/CommonJs.js +54 -2
  60. package/src/client/components/core/Css.js +0 -1
  61. package/src/client/components/core/CssCore.js +10 -4
  62. package/src/client/components/core/Docs.js +1 -2
  63. package/src/client/components/core/EventsUI.js +3 -3
  64. package/src/client/components/core/FileExplorer.js +86 -78
  65. package/src/client/components/core/Input.js +4 -2
  66. package/src/client/components/core/JoyStick.js +2 -2
  67. package/src/client/components/core/LoadingAnimation.js +3 -12
  68. package/src/client/components/core/LogIn.js +3 -3
  69. package/src/client/components/core/LogOut.js +1 -1
  70. package/src/client/components/core/Modal.js +44 -14
  71. package/src/client/components/core/Panel.js +26 -66
  72. package/src/client/components/core/PanelForm.js +22 -15
  73. package/src/client/components/core/Recover.js +3 -3
  74. package/src/client/components/core/RichText.js +1 -11
  75. package/src/client/components/core/Router.js +3 -1
  76. package/src/client/components/core/SignUp.js +2 -2
  77. package/src/client/components/default/RoutesDefault.js +3 -2
  78. package/src/client/services/core/core.service.js +15 -10
  79. package/src/client/services/default/default.management.js +45 -38
  80. package/src/client/ssr/Render.js +6 -1
  81. package/src/client/ssr/body/CacheControl.js +2 -3
  82. package/src/client/sw/default.sw.js +3 -3
  83. package/src/db/mongo/MongooseDB.js +17 -1
  84. package/src/index.js +25 -1
  85. package/src/mailer/MailerProvider.js +3 -0
  86. package/src/runtime/lampp/Dockerfile +65 -0
  87. package/src/server/backup.js +3 -3
  88. package/src/server/client-build.js +45 -23
  89. package/src/server/client-formatted.js +2 -1
  90. package/src/server/conf.js +110 -16
  91. package/src/server/dns.js +74 -43
  92. package/src/server/downloader.js +0 -8
  93. package/src/server/json-schema.js +77 -0
  94. package/src/server/network.js +7 -122
  95. package/src/server/peer.js +2 -2
  96. package/src/server/proxy.js +4 -4
  97. package/src/server/runtime.js +40 -12
  98. package/src/server/start.js +122 -0
  99. package/src/server/valkey.js +25 -11
  100. package/test/api.test.js +0 -8
  101. package/manifests/core/kustomization.yaml +0 -11
  102. package/manifests/core/underpost-engine-backup-access.yaml +0 -16
  103. package/manifests/core/underpost-engine-backup-pv-pvc.yaml +0 -22
  104. package/manifests/core/underpost-engine-mongodb-backup-cronjob.yaml +0 -40
  105. package/manifests/core/underpost-engine-mongodb-configmap.yaml +0 -26
  106. package/manifests/core/underpost-engine-statefulset.yaml +0 -91
  107. package/manifests/valkey/underpost-engine-valkey-service.yaml +0 -17
  108. package/manifests/valkey/underpost-engine-valkey-statefulset.yaml +0 -39
  109. /package/manifests/{core/underpost-engine-pv-pvc.yaml → mongodb-4.4/pv-pvc.yaml} +0 -0
package/src/cli/db.js CHANGED
@@ -2,14 +2,30 @@ import { mergeFile, splitFileFactory } from '../server/conf.js';
2
2
  import { loggerFactory } from '../server/logger.js';
3
3
  import { shellExec } from '../server/process.js';
4
4
  import fs from 'fs-extra';
5
+ import UnderpostDeploy from './deploy.js';
5
6
 
6
7
  const logger = loggerFactory(import.meta);
7
8
 
8
9
  class UnderpostDB {
9
10
  static API = {
10
- async callback(deployList = 'default', options = { import: false, export: false }) {
11
+ async callback(
12
+ deployList = 'default',
13
+ options = {
14
+ import: false,
15
+ export: false,
16
+ podName: false,
17
+ ns: false,
18
+ collections: '',
19
+ outPath: '',
20
+ drop: false,
21
+ preserveUUID: false,
22
+ git: false,
23
+ hosts: '',
24
+ paths: '',
25
+ },
26
+ ) {
11
27
  const newBackupTimestamp = new Date().getTime();
12
- const nameSpace = 'default';
28
+ const nameSpace = options.ns && typeof options.ns === 'string' ? options.ns : 'default';
13
29
  for (const _deployId of deployList.split(',')) {
14
30
  const deployId = _deployId.trim();
15
31
  if (!deployId) continue;
@@ -25,28 +41,38 @@ class UnderpostDB {
25
41
  if (!dbs[provider]) dbs[provider] = {};
26
42
 
27
43
  if (!(name in dbs[provider]))
28
- dbs[provider][name] = { user, password, hostFolder: host + path.replaceAll('/', '-') };
44
+ dbs[provider][name] = { user, password, hostFolder: host + path.replaceAll('/', '-'), host, path };
29
45
  }
30
46
  }
31
47
  }
32
48
 
33
- if (!fs.existsSync(`../${repoName}`)) {
34
- shellExec(`cd .. && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}`);
35
- } else {
36
- shellExec(`cd ../${repoName} && underpost pull . ${process.env.GITHUB_USERNAME}/${repoName}`);
49
+ if (options.git === true) {
50
+ if (!fs.existsSync(`../${repoName}`)) {
51
+ shellExec(`cd .. && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}`);
52
+ } else {
53
+ shellExec(`cd ../${repoName} && git checkout . && git clean -f -d`);
54
+ shellExec(`cd ../${repoName} && underpost pull . ${process.env.GITHUB_USERNAME}/${repoName}`);
55
+ }
37
56
  }
38
57
 
39
58
  for (const provider of Object.keys(dbs)) {
40
59
  for (const dbName of Object.keys(dbs[provider])) {
41
- const { hostFolder, user, password } = dbs[provider][dbName];
60
+ const { hostFolder, user, password, host, path } = dbs[provider][dbName];
61
+ if (
62
+ (options.hosts && !options.hosts.split(',').includes(host)) ||
63
+ (options.paths && !options.paths.split(',').includes(path))
64
+ )
65
+ continue;
42
66
  if (hostFolder) {
43
67
  logger.info('', { hostFolder, provider, dbName });
44
68
 
45
69
  const backUpPath = `../${repoName}/${hostFolder}`;
70
+ if (!fs.existsSync(backUpPath)) fs.mkdirSync(backUpPath, { recursive: true });
71
+ shellExec(`cd ${backUpPath} && find . -type d -empty -delete`); // delete empty folders
46
72
  const times = await fs.readdir(backUpPath);
47
- const currentBackupTimestamp = Math.max(...times.map((t) => parseInt(t)));
73
+ const currentBackupTimestamp = Math.max(...times.map((t) => parseInt(t)).filter((t) => !isNaN(t)));
48
74
  dbs[provider][dbName].currentBackupTimestamp = currentBackupTimestamp;
49
- const removeBackupTimestamp = Math.min(...times.map((t) => parseInt(t)));
75
+ const removeBackupTimestamp = Math.min(...times.map((t) => parseInt(t)).filter((t) => !isNaN(t)));
50
76
 
51
77
  const sqlContainerPath = `/home/${dbName}.sql`;
52
78
  const _fromPartsParts = `../${repoName}/${hostFolder}/${currentBackupTimestamp}/${dbName}-parths.json`;
@@ -68,57 +94,105 @@ class UnderpostDB {
68
94
  }
69
95
 
70
96
  if (options.export === true && times.length >= 5) {
97
+ logger.info('remove', `../${repoName}/${hostFolder}/${removeBackupTimestamp}`);
71
98
  fs.removeSync(`../${repoName}/${hostFolder}/${removeBackupTimestamp}`);
99
+ logger.info('create', `../${repoName}/${hostFolder}/${newBackupTimestamp}`);
72
100
  fs.mkdirSync(`../${repoName}/${hostFolder}/${newBackupTimestamp}`, { recursive: true });
73
101
  }
74
102
 
75
103
  switch (provider) {
76
104
  case 'mariadb': {
77
- const podName = `mariadb-statefulset-0`;
105
+ const podNames =
106
+ options.podName && typeof options.podName === 'string'
107
+ ? options.podName.split(',')
108
+ : UnderpostDeploy.API.get('mariadb'); // `mariadb-statefulset-0`;
78
109
  const serviceName = 'mariadb';
79
- if (options.import === true) {
80
- shellExec(`sudo kubectl cp ${_toSqlPath} ${nameSpace}/${podName}:/${dbName}.sql`);
81
- const cmd = `mariadb -u ${user} -p${password} ${dbName} < /${dbName}.sql`;
82
- shellExec(
83
- `kubectl exec -i ${podName} -- ${serviceName} -p${password} -e 'CREATE DATABASE ${dbName};'`,
84
- );
85
- shellExec(`sudo kubectl exec -i ${podName} -- sh -c "${cmd}"`);
86
- }
87
- if (options.export === true) {
88
- const cmd = `mariadb-dump --user=${user} --password=${password} --lock-tables ${dbName} > ${sqlContainerPath}`;
89
- shellExec(`sudo kubectl exec -i ${podName} -- sh -c "${cmd}"`);
90
- shellExec(`sudo kubectl cp ${nameSpace}/${podName}:${sqlContainerPath} ${_toNewSqlPath}`);
91
- await splitFileFactory(dbName, _toNewSqlPath);
110
+ for (const podNameData of [podNames[0]]) {
111
+ const podName = podNameData.NAME;
112
+ if (options.import === true) {
113
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "rm -rf /${dbName}.sql"`);
114
+ shellExec(`sudo kubectl cp ${_toSqlPath} ${nameSpace}/${podName}:/${dbName}.sql`);
115
+ const cmd = `mariadb -u ${user} -p${password} ${dbName} < /${dbName}.sql`;
116
+ shellExec(
117
+ `kubectl exec -i ${podName} -- ${serviceName} -p${password} -e 'CREATE DATABASE ${dbName};'`,
118
+ );
119
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "${cmd}"`);
120
+ }
121
+ if (options.export === true) {
122
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "rm -rf ${sqlContainerPath}"`);
123
+ const cmd = `mariadb-dump --user=${user} --password=${password} --lock-tables ${dbName} > ${sqlContainerPath}`;
124
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "${cmd}"`);
125
+ shellExec(
126
+ `sudo kubectl cp ${nameSpace}/${podName}:${sqlContainerPath} ${
127
+ options.outPath ? options.outPath : _toNewSqlPath
128
+ }`,
129
+ );
130
+ await splitFileFactory(dbName, options.outPath ? options.outPath : _toNewSqlPath);
131
+ }
92
132
  }
93
133
  break;
94
134
  }
95
135
 
96
136
  case 'mongoose': {
97
137
  if (options.import === true) {
98
- const podName = `mongodb-0`;
99
- shellExec(`sudo kubectl cp ${_toBsonPath} ${nameSpace}/${podName}:/${dbName}`);
100
- const cmd = `mongorestore -d ${dbName} /${dbName}`;
101
- shellExec(`sudo kubectl exec -i ${podName} -- sh -c "${cmd}"`);
138
+ const podNames =
139
+ options.podName && typeof options.podName === 'string'
140
+ ? options.podName.split(',')
141
+ : UnderpostDeploy.API.get('mongo');
142
+ // `mongodb-0`;
143
+ for (const podNameData of [podNames[0]]) {
144
+ const podName = podNameData.NAME;
145
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "rm -rf /${dbName}"`);
146
+ shellExec(
147
+ `sudo kubectl cp ${
148
+ options.outPath ? options.outPath : _toBsonPath
149
+ } ${nameSpace}/${podName}:/${dbName}`,
150
+ );
151
+ const cmd = `mongorestore -d ${dbName} /${dbName}${options.drop ? ' --drop' : ''}${
152
+ options.preserveUUID ? ' --preserveUUID' : ''
153
+ }`;
154
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "${cmd}"`);
155
+ }
102
156
  }
103
157
  if (options.export === true) {
104
- const podName = `backup-access`;
105
- const containerBaseBackupPath = '/backup';
106
- let timeFolder = shellExec(
107
- `sudo kubectl exec -i ${podName} -- sh -c "cd ${containerBaseBackupPath} && ls -a"`,
108
- {
109
- stdout: true,
110
- disableLog: false,
111
- silent: true,
112
- },
113
- ).split(`\n`);
114
- timeFolder = timeFolder[timeFolder.length - 2];
115
- if (timeFolder === '..') {
116
- logger.warn(`Cannot backup available`, { timeFolder });
117
- } else {
158
+ const podNames =
159
+ options.podName && typeof options.podName === 'string'
160
+ ? options.podName.split(',')
161
+ : UnderpostDeploy.API.get('mongo'); // `backup-access`;
162
+ for (const podNameData of [podNames[0]]) {
163
+ const podName = podNameData.NAME;
164
+ shellExec(`sudo kubectl exec -i ${podName} -- sh -c "rm -rf /${dbName}"`);
165
+ if (options.collections)
166
+ for (const collection of options.collections.split(','))
167
+ shellExec(
168
+ `sudo kubectl exec -i ${podName} -- sh -c "mongodump -d ${dbName} --collection ${collection} -o /"`,
169
+ );
170
+ else shellExec(`sudo kubectl exec -i ${podName} -- sh -c "mongodump -d ${dbName} -o /"`);
118
171
  shellExec(
119
- `sudo kubectl cp ${nameSpace}/${podName}:${containerBaseBackupPath}/${timeFolder}/${dbName} ${_toNewBsonPath}`,
172
+ `sudo kubectl cp ${nameSpace}/${podName}:/${dbName} ${
173
+ options.outPath ? options.outPath : _toNewBsonPath
174
+ }`,
120
175
  );
121
176
  }
177
+ if (false) {
178
+ const containerBaseBackupPath = '/backup';
179
+ let timeFolder = shellExec(
180
+ `sudo kubectl exec -i ${podName} -- sh -c "cd ${containerBaseBackupPath} && ls -a"`,
181
+ {
182
+ stdout: true,
183
+ disableLog: false,
184
+ silent: true,
185
+ },
186
+ ).split(`\n`);
187
+ timeFolder = timeFolder[timeFolder.length - 2];
188
+ if (timeFolder === '..') {
189
+ logger.warn(`Cannot backup available`, { timeFolder });
190
+ } else {
191
+ shellExec(
192
+ `sudo kubectl cp ${nameSpace}/${podName}:${containerBaseBackupPath}/${timeFolder}/${dbName} ${_toNewBsonPath}`,
193
+ );
194
+ }
195
+ }
122
196
  }
123
197
  break;
124
198
  }
@@ -129,7 +203,7 @@ class UnderpostDB {
129
203
  }
130
204
  }
131
205
  }
132
- if (options.export === true) {
206
+ if (options.export === true && options.git === true) {
133
207
  shellExec(`cd ../${repoName} && git add .`);
134
208
  shellExec(
135
209
  `underpost cmt ../${repoName} backup '' '${new Date(newBackupTimestamp).toLocaleDateString()} ${new Date(