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.
Files changed (145) hide show
  1. package/.dockerignore +1 -0
  2. package/.github/workflows/ghpkg.yml +19 -49
  3. package/.github/workflows/npmpkg.yml +67 -0
  4. package/.github/workflows/publish.yml +5 -5
  5. package/.github/workflows/pwa-microservices-template.page.yml +12 -4
  6. package/.github/workflows/pwa-microservices-template.test.yml +2 -2
  7. package/.vscode/extensions.json +18 -71
  8. package/.vscode/settings.json +20 -3
  9. package/AUTHORS.md +16 -5
  10. package/CHANGELOG.md +123 -3
  11. package/Dockerfile +27 -70
  12. package/README.md +39 -29
  13. package/bin/build.js +186 -0
  14. package/bin/db.js +2 -24
  15. package/bin/deploy.js +1467 -236
  16. package/bin/file.js +67 -16
  17. package/bin/hwt.js +0 -10
  18. package/bin/index.js +1 -77
  19. package/bin/ssl.js +19 -11
  20. package/bin/util.js +9 -104
  21. package/bin/vs.js +26 -2
  22. package/cli.md +451 -0
  23. package/conf.js +29 -138
  24. package/docker-compose.yml +1 -1
  25. package/jsdoc.json +1 -1
  26. package/manifests/calico-custom-resources.yaml +25 -0
  27. package/manifests/deployment/adminer/deployment.yaml +32 -0
  28. package/manifests/deployment/adminer/kustomization.yaml +7 -0
  29. package/manifests/deployment/adminer/service.yaml +13 -0
  30. package/manifests/deployment/fastapi/backend-deployment.yml +120 -0
  31. package/manifests/deployment/fastapi/backend-service.yml +19 -0
  32. package/manifests/deployment/fastapi/frontend-deployment.yml +54 -0
  33. package/manifests/deployment/fastapi/frontend-service.yml +15 -0
  34. package/manifests/deployment/kafka/deployment.yaml +69 -0
  35. package/manifests/deployment/mongo-express/deployment.yaml +60 -0
  36. package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
  37. package/manifests/kind-config-dev.yaml +12 -0
  38. package/manifests/kind-config.yaml +12 -0
  39. package/manifests/kubeadm-calico-config.yaml +119 -0
  40. package/manifests/letsencrypt-prod.yaml +15 -0
  41. package/manifests/mariadb/config.yaml +10 -0
  42. package/manifests/mariadb/kustomization.yaml +9 -0
  43. package/manifests/mariadb/pv.yaml +12 -0
  44. package/manifests/mariadb/pvc.yaml +10 -0
  45. package/manifests/mariadb/secret.yaml +8 -0
  46. package/manifests/mariadb/service.yaml +10 -0
  47. package/manifests/mariadb/statefulset.yaml +55 -0
  48. package/manifests/mongodb/backup-access.yaml +16 -0
  49. package/manifests/mongodb/backup-cronjob.yaml +42 -0
  50. package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
  51. package/manifests/mongodb/configmap.yaml +26 -0
  52. package/manifests/mongodb/headless-service.yaml +10 -0
  53. package/manifests/mongodb/kustomization.yaml +11 -0
  54. package/manifests/mongodb/pv-pvc.yaml +23 -0
  55. package/manifests/mongodb/statefulset.yaml +125 -0
  56. package/manifests/mongodb-4.4/kustomization.yaml +7 -0
  57. package/manifests/mongodb-4.4/pv-pvc.yaml +23 -0
  58. package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
  59. package/manifests/postgresql/configmap.yaml +9 -0
  60. package/manifests/postgresql/kustomization.yaml +10 -0
  61. package/manifests/postgresql/pv.yaml +15 -0
  62. package/manifests/postgresql/pvc.yaml +13 -0
  63. package/manifests/postgresql/service.yaml +10 -0
  64. package/manifests/postgresql/statefulset.yaml +37 -0
  65. package/manifests/valkey/kustomization.yaml +7 -0
  66. package/manifests/valkey/service.yaml +17 -0
  67. package/manifests/valkey/statefulset.yaml +41 -0
  68. package/package.json +127 -136
  69. package/src/api/core/core.service.js +1 -1
  70. package/src/api/default/default.service.js +1 -1
  71. package/src/api/user/user.model.js +16 -3
  72. package/src/api/user/user.service.js +15 -12
  73. package/src/cli/cluster.js +389 -0
  74. package/src/cli/cron.js +121 -0
  75. package/src/cli/db.js +222 -0
  76. package/src/cli/deploy.js +487 -0
  77. package/src/cli/env.js +58 -0
  78. package/src/cli/fs.js +161 -0
  79. package/src/cli/image.js +66 -0
  80. package/src/cli/index.js +312 -0
  81. package/src/cli/monitor.js +236 -0
  82. package/src/cli/repository.js +128 -0
  83. package/src/cli/script.js +53 -0
  84. package/src/cli/secrets.js +37 -0
  85. package/src/cli/test.js +118 -0
  86. package/src/client/components/core/Account.js +28 -24
  87. package/src/client/components/core/Auth.js +22 -4
  88. package/src/client/components/core/Blockchain.js +1 -1
  89. package/src/client/components/core/CalendarCore.js +128 -121
  90. package/src/client/components/core/CommonJs.js +283 -19
  91. package/src/client/components/core/CssCore.js +16 -4
  92. package/src/client/components/core/Docs.js +1 -2
  93. package/src/client/components/core/DropDown.js +5 -1
  94. package/src/client/components/core/EventsUI.js +3 -3
  95. package/src/client/components/core/FileExplorer.js +86 -78
  96. package/src/client/components/core/Input.js +22 -6
  97. package/src/client/components/core/JoyStick.js +2 -2
  98. package/src/client/components/core/LoadingAnimation.js +3 -12
  99. package/src/client/components/core/LogIn.js +3 -3
  100. package/src/client/components/core/LogOut.js +1 -1
  101. package/src/client/components/core/Modal.js +54 -20
  102. package/src/client/components/core/Panel.js +109 -90
  103. package/src/client/components/core/PanelForm.js +23 -30
  104. package/src/client/components/core/Recover.js +3 -3
  105. package/src/client/components/core/RichText.js +1 -11
  106. package/src/client/components/core/Router.js +3 -1
  107. package/src/client/components/core/Scroll.js +1 -0
  108. package/src/client/components/core/SignUp.js +2 -2
  109. package/src/client/components/core/Translate.js +47 -9
  110. package/src/client/components/core/Validator.js +9 -1
  111. package/src/client/components/core/VanillaJs.js +0 -9
  112. package/src/client/components/core/Worker.js +34 -31
  113. package/src/client/components/default/RoutesDefault.js +3 -2
  114. package/src/client/services/core/core.service.js +15 -10
  115. package/src/client/services/default/default.management.js +46 -37
  116. package/src/client/ssr/Render.js +6 -1
  117. package/src/client/ssr/body/CacheControl.js +2 -3
  118. package/src/client/sw/default.sw.js +3 -3
  119. package/src/db/mongo/MongooseDB.js +29 -1
  120. package/src/index.js +101 -19
  121. package/src/mailer/MailerProvider.js +3 -0
  122. package/src/runtime/lampp/Dockerfile +65 -0
  123. package/src/runtime/lampp/Lampp.js +1 -13
  124. package/src/runtime/xampp/Xampp.js +0 -13
  125. package/src/server/auth.js +3 -3
  126. package/src/server/backup.js +49 -93
  127. package/src/server/client-build.js +49 -46
  128. package/src/server/client-formatted.js +6 -3
  129. package/src/server/conf.js +297 -55
  130. package/src/server/dns.js +75 -62
  131. package/src/server/downloader.js +0 -8
  132. package/src/server/json-schema.js +77 -0
  133. package/src/server/logger.js +15 -10
  134. package/src/server/network.js +20 -161
  135. package/src/server/peer.js +2 -2
  136. package/src/server/process.js +25 -2
  137. package/src/server/proxy.js +7 -29
  138. package/src/server/runtime.js +53 -40
  139. package/src/server/ssl.js +1 -1
  140. package/src/server/start.js +122 -0
  141. package/src/server/valkey.js +27 -11
  142. package/test/api.test.js +0 -8
  143. package/src/dns.js +0 -22
  144. package/src/server/prompt-optimizer.js +0 -28
  145. package/startup.js +0 -11
package/src/cli/db.js ADDED
@@ -0,0 +1,222 @@
1
+ import { mergeFile, splitFileFactory } from '../server/conf.js';
2
+ import { loggerFactory } from '../server/logger.js';
3
+ import { shellExec } from '../server/process.js';
4
+ import fs from 'fs-extra';
5
+ import UnderpostDeploy from './deploy.js';
6
+
7
+ const logger = loggerFactory(import.meta);
8
+
9
+ class UnderpostDB {
10
+ static API = {
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
+ ) {
27
+ const newBackupTimestamp = new Date().getTime();
28
+ const nameSpace = options.ns && typeof options.ns === 'string' ? options.ns : 'default';
29
+ for (const _deployId of deployList.split(',')) {
30
+ const deployId = _deployId.trim();
31
+ if (!deployId) continue;
32
+ const dbs = {};
33
+ const repoName = `engine-${deployId.split('dd-')[1]}-cron-backups`;
34
+
35
+ const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
36
+ for (const host of Object.keys(confServer)) {
37
+ for (const path of Object.keys(confServer[host])) {
38
+ const { db } = confServer[host][path];
39
+ if (db) {
40
+ const { provider, name, user, password } = db;
41
+ if (!dbs[provider]) dbs[provider] = {};
42
+
43
+ if (!(name in dbs[provider]))
44
+ dbs[provider][name] = { user, password, hostFolder: host + path.replaceAll('/', '-'), host, path };
45
+ }
46
+ }
47
+ }
48
+
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
+ }
56
+ }
57
+
58
+ for (const provider of Object.keys(dbs)) {
59
+ for (const dbName of Object.keys(dbs[provider])) {
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;
66
+ if (hostFolder) {
67
+ logger.info('', { hostFolder, provider, dbName });
68
+
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
72
+ const times = await fs.readdir(backUpPath);
73
+ const currentBackupTimestamp = Math.max(...times.map((t) => parseInt(t)).filter((t) => !isNaN(t)));
74
+ dbs[provider][dbName].currentBackupTimestamp = currentBackupTimestamp;
75
+ const removeBackupTimestamp = Math.min(...times.map((t) => parseInt(t)).filter((t) => !isNaN(t)));
76
+
77
+ const sqlContainerPath = `/home/${dbName}.sql`;
78
+ const _fromPartsParts = `../${repoName}/${hostFolder}/${currentBackupTimestamp}/${dbName}-parths.json`;
79
+ const _toSqlPath = `../${repoName}/${hostFolder}/${currentBackupTimestamp}/${dbName}.sql`;
80
+ const _toNewSqlPath = `../${repoName}/${hostFolder}/${newBackupTimestamp}/${dbName}.sql`;
81
+ const _toBsonPath = `../${repoName}/${hostFolder}/${currentBackupTimestamp}/${dbName}`;
82
+ const _toNewBsonPath = `../${repoName}/${hostFolder}/${newBackupTimestamp}/${dbName}`;
83
+
84
+ if (options.import === true && fs.existsSync(_fromPartsParts) && !fs.existsSync(_toSqlPath)) {
85
+ const names = JSON.parse(fs.readFileSync(_fromPartsParts, 'utf8')).map((_path) => {
86
+ return `../${repoName}/${hostFolder}/${currentBackupTimestamp}/${_path.split('/').pop()}`;
87
+ });
88
+ logger.info('merge Back Up paths', {
89
+ _fromPartsParts,
90
+ _toSqlPath,
91
+ names,
92
+ });
93
+ await mergeFile(names, _toSqlPath);
94
+ }
95
+
96
+ if (options.export === true && times.length >= 5) {
97
+ logger.info('remove', `../${repoName}/${hostFolder}/${removeBackupTimestamp}`);
98
+ fs.removeSync(`../${repoName}/${hostFolder}/${removeBackupTimestamp}`);
99
+ logger.info('create', `../${repoName}/${hostFolder}/${newBackupTimestamp}`);
100
+ fs.mkdirSync(`../${repoName}/${hostFolder}/${newBackupTimestamp}`, { recursive: true });
101
+ }
102
+
103
+ switch (provider) {
104
+ case 'mariadb': {
105
+ const podNames =
106
+ options.podName && typeof options.podName === 'string'
107
+ ? options.podName.split(',')
108
+ : UnderpostDeploy.API.get('mariadb'); // `mariadb-statefulset-0`;
109
+ const serviceName = 'mariadb';
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
+ }
132
+ }
133
+ break;
134
+ }
135
+
136
+ case 'mongoose': {
137
+ if (options.import === true) {
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
+ }
156
+ }
157
+ if (options.export === true) {
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 /"`);
171
+ shellExec(
172
+ `sudo kubectl cp ${nameSpace}/${podName}:/${dbName} ${
173
+ options.outPath ? options.outPath : _toNewBsonPath
174
+ }`,
175
+ );
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
+ }
196
+ }
197
+ break;
198
+ }
199
+
200
+ default:
201
+ break;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ if (options.export === true && options.git === true) {
207
+ shellExec(`cd ../${repoName} && git add .`);
208
+ shellExec(
209
+ `underpost cmt ../${repoName} backup '' '${new Date(newBackupTimestamp).toLocaleDateString()} ${new Date(
210
+ newBackupTimestamp,
211
+ ).toLocaleTimeString()}'`,
212
+ );
213
+ shellExec(`cd ../${repoName} && underpost push . ${process.env.GITHUB_USERNAME}/${repoName}`, {
214
+ disableLog: true,
215
+ });
216
+ }
217
+ }
218
+ },
219
+ };
220
+ }
221
+
222
+ export default UnderpostDB;