@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.
- package/.github/workflows/ghpkg.yml +1 -1
- package/.github/workflows/npmpkg.yml +1 -1
- package/.github/workflows/pwa-microservices-template.page.yml +1 -1
- package/.vscode/extensions.json +3 -2
- package/.vscode/settings.json +6 -0
- package/CHANGELOG.md +44 -0
- package/Dockerfile +9 -10
- package/README.md +39 -2
- package/bin/build.js +31 -6
- package/bin/deploy.js +1404 -202
- package/bin/file.js +8 -0
- package/bin/hwt.js +0 -10
- package/bin/index.js +1 -187
- package/bin/util.js +0 -7
- package/bin/vs.js +1 -0
- package/cli.md +451 -0
- package/conf.js +0 -2
- 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/kind-config-dev.yaml +12 -0
- package/manifests/kubeadm-calico-config.yaml +119 -0
- package/manifests/mongodb/kustomization.yaml +2 -2
- package/manifests/mongodb-4.4/kustomization.yaml +7 -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/{core/underpost-engine-headless-service.yaml → postgresql/service.yaml} +3 -3
- package/manifests/postgresql/statefulset.yaml +37 -0
- package/manifests/valkey/statefulset.yaml +6 -4
- package/package.json +10 -14
- package/src/api/default/default.service.js +1 -1
- package/src/api/user/user.service.js +14 -11
- package/src/cli/cluster.js +298 -63
- package/src/cli/cron.js +39 -8
- package/src/cli/db.js +118 -44
- package/src/cli/deploy.js +312 -102
- package/src/cli/env.js +9 -3
- package/src/cli/fs.js +161 -0
- package/src/cli/image.js +45 -104
- package/src/cli/index.js +312 -0
- package/src/cli/monitor.js +236 -0
- package/src/cli/repository.js +26 -2
- package/src/cli/script.js +25 -1
- package/src/cli/test.js +39 -4
- package/src/client/components/core/Account.js +28 -24
- package/src/client/components/core/Blockchain.js +1 -1
- package/src/client/components/core/CalendarCore.js +14 -73
- package/src/client/components/core/CommonJs.js +54 -2
- package/src/client/components/core/Css.js +0 -1
- package/src/client/components/core/CssCore.js +10 -4
- package/src/client/components/core/Docs.js +1 -2
- 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 +4 -2
- 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 +44 -14
- package/src/client/components/core/Panel.js +26 -66
- package/src/client/components/core/PanelForm.js +22 -15
- 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/SignUp.js +2 -2
- 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 +45 -38
- 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 +17 -1
- package/src/index.js +25 -1
- package/src/mailer/MailerProvider.js +3 -0
- package/src/runtime/lampp/Dockerfile +65 -0
- package/src/server/backup.js +3 -3
- package/src/server/client-build.js +45 -23
- package/src/server/client-formatted.js +2 -1
- package/src/server/conf.js +110 -16
- package/src/server/dns.js +74 -43
- package/src/server/downloader.js +0 -8
- package/src/server/json-schema.js +77 -0
- package/src/server/network.js +7 -122
- package/src/server/peer.js +2 -2
- package/src/server/proxy.js +4 -4
- package/src/server/runtime.js +40 -12
- package/src/server/start.js +122 -0
- package/src/server/valkey.js +25 -11
- package/test/api.test.js +0 -8
- package/manifests/core/kustomization.yaml +0 -11
- package/manifests/core/underpost-engine-backup-access.yaml +0 -16
- package/manifests/core/underpost-engine-backup-pv-pvc.yaml +0 -22
- package/manifests/core/underpost-engine-mongodb-backup-cronjob.yaml +0 -40
- package/manifests/core/underpost-engine-mongodb-configmap.yaml +0 -26
- package/manifests/core/underpost-engine-statefulset.yaml +0 -91
- package/manifests/valkey/underpost-engine-valkey-service.yaml +0 -17
- package/manifests/valkey/underpost-engine-valkey-statefulset.yaml +0 -39
- /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(
|
|
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 (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
`kubectl
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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}
|
|
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(
|