@underpostnet/underpost 2.8.4 → 2.8.6
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 +12 -45
- package/.github/workflows/npmpkg.yml +67 -0
- package/.github/workflows/publish.yml +5 -5
- package/.github/workflows/pwa-microservices-template.page.yml +2 -1
- package/.github/workflows/pwa-microservices-template.test.yml +2 -2
- package/.vscode/settings.json +10 -1
- package/CHANGELOG.md +40 -0
- package/Dockerfile +6 -27
- package/bin/build.js +73 -165
- package/bin/deploy.js +76 -101
- package/bin/file.js +29 -15
- package/bin/hwt.js +0 -10
- package/bin/index.js +191 -32
- package/bin/util.js +0 -15
- package/bin/vs.js +1 -0
- package/conf.js +0 -2
- package/docker-compose.yml +1 -1
- package/manifests/kind-config-dev.yaml +12 -0
- package/manifests/{core/underpost-engine-mongodb-backup-cronjob.yaml → mongodb/backup-cronjob.yaml} +14 -12
- package/manifests/mongodb/kustomization.yaml +11 -0
- package/manifests/mongodb/pv-pvc.yaml +23 -0
- package/manifests/{core/underpost-engine-statefulset.yaml → mongodb/statefulset.yaml} +34 -0
- package/manifests/mongodb-4.4/kustomization.yaml +7 -0
- package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
- package/manifests/valkey/kustomization.yaml +2 -2
- package/package.json +22 -4
- package/src/api/core/core.service.js +1 -1
- package/src/cli/cluster.js +202 -0
- package/src/cli/cron.js +90 -0
- package/src/cli/db.js +212 -0
- package/src/cli/deploy.js +318 -0
- package/src/cli/env.js +52 -0
- package/src/cli/fs.js +149 -0
- package/src/cli/image.js +148 -0
- package/src/cli/repository.js +125 -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/Auth.js +22 -4
- package/src/client/components/core/CalendarCore.js +12 -1
- package/src/client/components/core/CommonJs.js +134 -2
- package/src/client/components/core/Css.js +1 -0
- package/src/client/components/core/CssCore.js +2 -4
- package/src/client/components/core/Docs.js +1 -2
- package/src/client/components/core/Input.js +5 -3
- package/src/client/components/core/LoadingAnimation.js +8 -1
- package/src/client/components/core/Modal.js +30 -7
- package/src/client/components/core/Panel.js +8 -6
- package/src/client/components/core/PanelForm.js +23 -7
- package/src/client/components/core/Scroll.js +1 -0
- package/src/client/components/core/Translate.js +4 -0
- package/src/client/components/core/VanillaJs.js +0 -9
- package/src/client/components/core/Worker.js +34 -31
- package/src/client/services/core/core.service.js +15 -10
- package/src/client/ssr/Render.js +4 -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 +85 -26
- package/src/server/backup.js +49 -93
- package/src/server/client-build.js +33 -33
- package/src/server/client-formatted.js +6 -3
- package/src/server/conf.js +82 -199
- package/src/server/dns.js +29 -53
- package/src/server/downloader.js +0 -8
- package/src/server/logger.js +7 -7
- package/src/server/network.js +17 -7
- package/src/server/runtime.js +24 -23
- package/test/api.test.js +0 -8
- package/manifests/core/kustomization.yaml +0 -11
- package/src/dns.js +0 -22
- package/src/server/project.js +0 -39
- package/startup.cjs +0 -12
- /package/manifests/deployment/{mongo-express.yaml → mongo-express/deployment.yaml} +0 -0
- /package/manifests/deployment/{phpmyadmin.yaml → phpmyadmin/deployment.yaml} +0 -0
- /package/manifests/{core/underpost-engine-backup-access.yaml → mongodb/backup-access.yaml} +0 -0
- /package/manifests/{core/underpost-engine-backup-pv-pvc.yaml → mongodb/backup-pv-pvc.yaml} +0 -0
- /package/manifests/{core/underpost-engine-mongodb-configmap.yaml → mongodb/configmap.yaml} +0 -0
- /package/manifests/{core/underpost-engine-headless-service.yaml → mongodb/headless-service.yaml} +0 -0
- /package/manifests/{core/underpost-engine-pv-pvc.yaml → mongodb-4.4/pv-pvc.yaml} +0 -0
- /package/manifests/valkey/{underpost-engine-valkey-service.yaml → service.yaml} +0 -0
- /package/manifests/valkey/{underpost-engine-valkey-statefulset.yaml → statefulset.yaml} +0 -0
|
@@ -4,13 +4,24 @@ import { getProxyPath } from '../../components/core/VanillaJs.js';
|
|
|
4
4
|
|
|
5
5
|
const logger = loggerFactory(import.meta);
|
|
6
6
|
|
|
7
|
+
logger.info('Load service');
|
|
8
|
+
|
|
9
|
+
const endpoint = 'core';
|
|
10
|
+
|
|
7
11
|
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController
|
|
8
|
-
const getBaseHost = () => location.host;
|
|
12
|
+
const getBaseHost = () => (window.renderPayload?.apiBaseHost ? window.renderPayload.apiBaseHost : location.host);
|
|
9
13
|
|
|
10
|
-
const getApiBasePath = () =>
|
|
14
|
+
const getApiBasePath = (options) =>
|
|
15
|
+
`${
|
|
16
|
+
options?.proxyPath
|
|
17
|
+
? `/${options.proxyPath}/`
|
|
18
|
+
: window.renderPayload?.apiBaseProxyPath
|
|
19
|
+
? window.renderPayload.apiBaseProxyPath
|
|
20
|
+
: getProxyPath()
|
|
21
|
+
}${window.renderPayload?.apiBasePath ? window.renderPayload.apiBasePath : 'api'}/`;
|
|
11
22
|
|
|
12
|
-
const getApiBaseUrl = (options = { id: '', endpoint: '' }) =>
|
|
13
|
-
`${location.protocol}//${getBaseHost()}${getApiBasePath()}${options?.endpoint ? options.endpoint : ''}${
|
|
23
|
+
const getApiBaseUrl = (options = { id: '', endpoint: '', proxyPath: '' }) =>
|
|
24
|
+
`${location.protocol}//${getBaseHost()}${getApiBasePath(options)}${options?.endpoint ? options.endpoint : ''}${
|
|
14
25
|
options?.id ? `/${options.id}` : ''
|
|
15
26
|
}`;
|
|
16
27
|
|
|
@@ -38,11 +49,6 @@ const payloadFactory = (body) => {
|
|
|
38
49
|
return JSON.stringify(body);
|
|
39
50
|
};
|
|
40
51
|
|
|
41
|
-
logger.info('Load service');
|
|
42
|
-
|
|
43
|
-
const endpoint = 'core';
|
|
44
|
-
const _VERSION = window._VERSION;
|
|
45
|
-
|
|
46
52
|
const CoreService = {
|
|
47
53
|
getRaw: (options = { url: '' }) =>
|
|
48
54
|
new Promise((resolve, reject) =>
|
|
@@ -159,7 +165,6 @@ const CoreService = {
|
|
|
159
165
|
const ApiBase = getApiBaseUrl;
|
|
160
166
|
|
|
161
167
|
export {
|
|
162
|
-
_VERSION,
|
|
163
168
|
CoreService,
|
|
164
169
|
headersFactory,
|
|
165
170
|
payloadFactory,
|
package/src/client/ssr/Render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
SrrComponent = ({ title, ssrPath, buildId, ssrHeadComponents, ssrBodyComponents }) => html`
|
|
1
|
+
SrrComponent = ({ title, ssrPath, buildId, ssrHeadComponents, ssrBodyComponents, renderPayload, renderApi }) => html`
|
|
2
2
|
<!DOCTYPE html>
|
|
3
3
|
<html dir="ltr" lang="en">
|
|
4
4
|
<head>
|
|
@@ -6,6 +6,9 @@ SrrComponent = ({ title, ssrPath, buildId, ssrHeadComponents, ssrBodyComponents
|
|
|
6
6
|
<link rel="icon" type="image/x-icon" href="${ssrPath}favicon.ico" />
|
|
7
7
|
<meta charset="UTF-8" />
|
|
8
8
|
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
|
9
|
+
<script>
|
|
10
|
+
window.renderPayload = ${renderApi.JSONweb(renderPayload)};
|
|
11
|
+
</script>
|
|
9
12
|
${ssrHeadComponents}
|
|
10
13
|
</head>
|
|
11
14
|
<body>
|
|
@@ -70,7 +70,7 @@ const CacheControl = function ({ ttiLoadTimeLimit }) {
|
|
|
70
70
|
setTimeout(window.cacheControlCallBack, ttiLoadTimeLimit); // 70s limit);
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
SrrComponent = ({ ttiLoadTimeLimit }) => {
|
|
73
|
+
SrrComponent = ({ ttiLoadTimeLimit, version }) => {
|
|
74
74
|
const borderChar = (px, color, selectors) => {
|
|
75
75
|
if (selectors) {
|
|
76
76
|
return selectors
|
|
@@ -106,10 +106,9 @@ SrrComponent = ({ ttiLoadTimeLimit }) => {
|
|
|
106
106
|
</style>
|
|
107
107
|
${borderChar(1, 'black', ['.clean-cache-container'])}
|
|
108
108
|
<script>
|
|
109
|
-
window._VERSION = '${process.env.npm_package_version}';
|
|
110
109
|
const CacheControl = ${CacheControl};
|
|
111
110
|
CacheControl({ ttiLoadTimeLimit: ${ttiLoadTimeLimit ? ttiLoadTimeLimit : 1000 * 70 * 1} });
|
|
112
111
|
</script>
|
|
113
|
-
<div class="clean-cache-container">${
|
|
112
|
+
<div class="clean-cache-container">${version}</div>
|
|
114
113
|
`;
|
|
115
114
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const PRE_CACHED_RESOURCES = [];
|
|
2
|
-
const CACHE_NAME = 'app-cache';
|
|
3
|
-
const PROXY_PATH = '/';
|
|
1
|
+
const PRE_CACHED_RESOURCES = self.renderPayload?.PRE_CACHED_RESOURCES ? self.renderPayload.PRE_CACHED_RESOURCES : [];
|
|
2
|
+
const CACHE_NAME = self.renderPayload?.CACHE_NAME ? self.renderPayload.CACHE_NAME : 'app-cache';
|
|
3
|
+
const PROXY_PATH = self.renderPayload?.PROXY_PATH ? self.renderPayload.PROXY_PATH : '/';
|
|
4
4
|
self.addEventListener('install', (event) => {
|
|
5
5
|
// Activate right away
|
|
6
6
|
self.skipWaiting();
|
|
@@ -79,7 +79,19 @@ const MongooseDB = {
|
|
|
79
79
|
if (process.argv.includes('rocky')) {
|
|
80
80
|
// https://github.com/mongodb/mongodb-selinux
|
|
81
81
|
// https://www.mongodb.com/docs/v7.0/tutorial/install-mongodb-enterprise-on-red-hat/
|
|
82
|
-
|
|
82
|
+
// https://www.mongodb.com/docs/v6.0/tutorial/install-mongodb-on-red-hat/
|
|
83
|
+
// https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-red-hat/
|
|
84
|
+
// dnf install selinux-policy-devel
|
|
85
|
+
// git clone https://github.com/mongodb/mongodb-selinux
|
|
86
|
+
// cd mongodb-selinux
|
|
87
|
+
// make
|
|
88
|
+
// sudo make install
|
|
89
|
+
// yum list installed | grep mongo
|
|
90
|
+
// sudo yum erase $(rpm -qa | grep mongodb)
|
|
91
|
+
// remove service
|
|
92
|
+
// sudo systemctl reset-failed
|
|
93
|
+
// MongoDB 5.0+ requires a CPU with AVX support
|
|
94
|
+
// check: grep avx /proc/cpuinfo
|
|
83
95
|
}
|
|
84
96
|
logger.info('install legacy 4.4');
|
|
85
97
|
shellExec(`wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -`);
|
|
@@ -112,9 +124,13 @@ const MongooseDB = {
|
|
|
112
124
|
shellExec(`sudo systemctl unmask mongod`);
|
|
113
125
|
shellExec(`sudo pkill -f mongod`);
|
|
114
126
|
shellExec(`sudo systemctl enable mongod.service`);
|
|
127
|
+
|
|
115
128
|
shellExec(`sudo chown -R mongodb:mongodb /var/lib/mongodb`);
|
|
116
129
|
shellExec(`sudo chown mongodb:mongodb /tmp/mongodb-27017.sock`);
|
|
117
130
|
|
|
131
|
+
shellExec(`sudo chown -R mongod:mongod /var/lib/mongodb`);
|
|
132
|
+
shellExec(`sudo chown mongod:mongod /tmp/mongodb-27017.sock`);
|
|
133
|
+
|
|
118
134
|
logger.info('run server');
|
|
119
135
|
shellExec(`sudo service mongod restart`);
|
|
120
136
|
|
package/src/index.js
CHANGED
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
* @namespace Underpost
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import UnderpostCluster from './cli/cluster.js';
|
|
8
|
+
import UnderpostCron from './cli/cron.js';
|
|
9
|
+
import UnderpostDB from './cli/db.js';
|
|
10
|
+
import UnderpostDeploy from './cli/deploy.js';
|
|
11
|
+
import UnderpostRootEnv from './cli/env.js';
|
|
12
|
+
import UnderpostFileStorage from './cli/fs.js';
|
|
13
|
+
import UnderpostImage from './cli/image.js';
|
|
14
|
+
import UnderpostRepository from './cli/repository.js';
|
|
15
|
+
import UnderpostScript from './cli/script.js';
|
|
16
|
+
import UnderpostSecret from './cli/secrets.js';
|
|
17
|
+
import UnderpostTest from './cli/test.js';
|
|
12
18
|
|
|
13
19
|
/**
|
|
14
20
|
* Underpost main module methods
|
|
@@ -22,31 +28,84 @@ class Underpost {
|
|
|
22
28
|
* @type {String}
|
|
23
29
|
* @memberof Underpost
|
|
24
30
|
*/
|
|
25
|
-
static version = 'v2.8.
|
|
26
|
-
static project = Project;
|
|
27
|
-
|
|
28
|
-
constructor() {}
|
|
29
|
-
|
|
31
|
+
static version = 'v2.8.6';
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* This function is used to log details about
|
|
34
|
-
* the execution context, such as command-line arguments,
|
|
35
|
-
* environment variables, the process's administrative privileges,
|
|
36
|
-
* and the maximum available heap space size.
|
|
37
|
-
*
|
|
33
|
+
* Repository cli API
|
|
38
34
|
* @static
|
|
39
|
-
* @
|
|
40
|
-
* @returns {Promise<void>}
|
|
35
|
+
* @type {UnderpostRepository.API}
|
|
41
36
|
* @memberof Underpost
|
|
42
37
|
*/
|
|
43
|
-
static
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
static repo = UnderpostRepository.API;
|
|
39
|
+
/**
|
|
40
|
+
* Root Env cli API
|
|
41
|
+
* @static
|
|
42
|
+
* @type {UnderpostRootEnv.API}
|
|
43
|
+
* @memberof Underpost
|
|
44
|
+
*/
|
|
45
|
+
static env = UnderpostRootEnv.API;
|
|
46
|
+
/**
|
|
47
|
+
* Test cli API
|
|
48
|
+
* @static
|
|
49
|
+
* @type {UnderpostTest.API}
|
|
50
|
+
* @memberof Underpost
|
|
51
|
+
*/
|
|
52
|
+
static test = UnderpostTest.API;
|
|
53
|
+
/**
|
|
54
|
+
* Cluster cli API
|
|
55
|
+
* @static
|
|
56
|
+
* @type {UnderpostCluster.API}
|
|
57
|
+
* @memberof Underpost
|
|
58
|
+
*/
|
|
59
|
+
static cluster = UnderpostCluster.API;
|
|
60
|
+
/**
|
|
61
|
+
* Image cli API
|
|
62
|
+
* @static
|
|
63
|
+
* @type {UnderpostImage.API}
|
|
64
|
+
* @memberof Underpost
|
|
65
|
+
*/
|
|
66
|
+
static image = UnderpostImage.API;
|
|
67
|
+
/**
|
|
68
|
+
* Secrets cli API
|
|
69
|
+
* @static
|
|
70
|
+
* @type {UnderpostSecret.API}
|
|
71
|
+
* @memberof Underpost
|
|
72
|
+
*/
|
|
73
|
+
static secret = UnderpostSecret.API;
|
|
74
|
+
/**
|
|
75
|
+
* Scripts cli API
|
|
76
|
+
* @static
|
|
77
|
+
* @type {UnderpostScript.API}
|
|
78
|
+
* @memberof Underpost
|
|
79
|
+
*/
|
|
80
|
+
static script = UnderpostScript.API;
|
|
81
|
+
/**
|
|
82
|
+
* Database cli API
|
|
83
|
+
* @static
|
|
84
|
+
* @type {UnderpostDB.API}
|
|
85
|
+
* @memberof Underpost
|
|
86
|
+
*/
|
|
87
|
+
static db = UnderpostDB.API;
|
|
88
|
+
/**
|
|
89
|
+
* Deployment cli API
|
|
90
|
+
* @static
|
|
91
|
+
* @type {UnderpostDeploy.API}
|
|
92
|
+
* @memberof Underpost
|
|
93
|
+
*/
|
|
94
|
+
static deploy = UnderpostDeploy.API;
|
|
95
|
+
/**
|
|
96
|
+
* Cron cli API
|
|
97
|
+
* @static
|
|
98
|
+
* @type {UnderpostCron.API}
|
|
99
|
+
* @memberof Underpost
|
|
100
|
+
*/
|
|
101
|
+
static cron = UnderpostCron.API;
|
|
102
|
+
/**
|
|
103
|
+
* File Storage cli API
|
|
104
|
+
* @static
|
|
105
|
+
* @type {UnderpostFileStorage.API}
|
|
106
|
+
* @memberof UnderpostFileStorage
|
|
107
|
+
*/
|
|
108
|
+
static fs = UnderpostFileStorage.API;
|
|
50
109
|
}
|
|
51
110
|
|
|
52
111
|
const up = Underpost;
|
package/src/server/backup.js
CHANGED
|
@@ -1,120 +1,76 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import { loggerFactory } from './logger.js';
|
|
3
|
-
import {
|
|
4
|
-
import { getCronBackUpFolder
|
|
3
|
+
import { shellExec } from './process.js';
|
|
4
|
+
import { getCronBackUpFolder } from './conf.js';
|
|
5
5
|
import dotenv from 'dotenv';
|
|
6
6
|
|
|
7
7
|
dotenv.config();
|
|
8
8
|
|
|
9
9
|
const logger = loggerFactory(import.meta);
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
|
|
11
|
+
class BackUp {
|
|
12
|
+
static callback = async function (deployList, options = { itc: false, git: false }) {
|
|
13
|
+
if ((!deployList || deployList === 'dd') && fs.existsSync(`./engine-private/deploy/dd.router`))
|
|
14
|
+
deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
logger.info('init backups callback', deployList);
|
|
17
|
+
await logger.setUpInfo();
|
|
18
|
+
const currentDate = new Date().getTime();
|
|
19
|
+
const maxBackupRetention = 5;
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
if (!fs.existsSync('./engine-private/cron-backups'))
|
|
22
|
+
fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
for (const _deployId of deployList.split(',')) {
|
|
25
|
+
const deployId = _deployId.trim();
|
|
26
|
+
if (!deployId) continue;
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!fs.existsSync('./engine-private/cron-backups'))
|
|
29
|
-
fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
|
|
30
|
-
|
|
31
|
-
for (const deployGroupData of backups) {
|
|
32
|
-
const { deployGroupId } = deployGroupData;
|
|
33
|
-
const dataDeploy = getDataDeploy({ deployGroupId });
|
|
34
|
-
|
|
35
|
-
for (const deployObj of dataDeploy) {
|
|
36
|
-
const { deployId, replicaHost } = deployObj;
|
|
37
|
-
|
|
38
|
-
if (replicaHost) continue;
|
|
39
|
-
|
|
40
|
-
const confServer = JSON.parse(
|
|
41
|
-
fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
|
|
42
|
-
? fs.readFileSync(`./engine-private/replica/${deployId}/conf.server.json`, 'utf8')
|
|
43
|
-
: fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
for (const host of Object.keys(confServer))
|
|
47
|
-
for (const path of Object.keys(confServer[host])) {
|
|
48
|
-
// retention policy
|
|
49
|
-
let { db, backupFrequency, maxBackupRetention, singleReplica, wp, git, directory } =
|
|
50
|
-
confServer[host][path];
|
|
51
|
-
|
|
52
|
-
if (!db || singleReplica) continue;
|
|
53
|
-
|
|
54
|
-
if (!backupFrequency) backupFrequency = 'daily';
|
|
55
|
-
if (!maxBackupRetention) maxBackupRetention = 5;
|
|
56
|
-
|
|
57
|
-
const backUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
|
|
58
|
-
if (!fs.existsSync(backUpPath)) fs.mkdirSync(`${backUpPath}`, { recursive: true });
|
|
59
|
-
// .isDirectory()
|
|
60
|
-
const files = await fs.readdir(backUpPath, { withFileTypes: true });
|
|
61
|
-
|
|
62
|
-
const currentBackupsDirs = files
|
|
63
|
-
.map((fileObj) => parseInt(fileObj.name))
|
|
64
|
-
.sort((a, b) => a - b)
|
|
65
|
-
.reverse();
|
|
28
|
+
if (!(options.itc === true)) {
|
|
29
|
+
shellExec(`node bin db ${options.git ? '--git ' : ''}--export ${deployId}`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
66
32
|
|
|
67
|
-
|
|
68
|
-
case 'daily':
|
|
33
|
+
const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
|
|
69
34
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
35
|
+
for (const host of Object.keys(confServer))
|
|
36
|
+
for (const path of Object.keys(confServer[host])) {
|
|
37
|
+
// retention policy
|
|
38
|
+
const { db } = confServer[host][path];
|
|
39
|
+
if (!db) continue;
|
|
40
|
+
logger.info('Init backup', { host, path, db });
|
|
74
41
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
42
|
+
const backUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
|
|
43
|
+
if (!fs.existsSync(backUpPath)) fs.mkdirSync(`${backUpPath}`, { recursive: true });
|
|
44
|
+
// .isDirectory()
|
|
45
|
+
const files = await fs.readdir(backUpPath, { withFileTypes: true });
|
|
80
46
|
|
|
81
|
-
|
|
47
|
+
const currentBackupsDirs = files
|
|
48
|
+
.map((fileObj) => parseInt(fileObj.name))
|
|
49
|
+
.sort((a, b) => a - b)
|
|
50
|
+
.reverse();
|
|
82
51
|
|
|
83
|
-
|
|
52
|
+
for (const retentionPath of currentBackupsDirs.filter((t, i) => i >= maxBackupRetention - 1)) {
|
|
53
|
+
const removePathRetention = `${backUpPath}/${retentionPath}`;
|
|
54
|
+
logger.info('Remove backup folder', removePathRetention);
|
|
55
|
+
fs.removeSync(removePathRetention);
|
|
56
|
+
}
|
|
84
57
|
|
|
85
|
-
|
|
86
|
-
const repoUrl = `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${git
|
|
87
|
-
.split('/')
|
|
88
|
-
.pop()}.git`;
|
|
58
|
+
fs.mkdirSync(`${backUpPath}/${currentDate}`, { recursive: true });
|
|
89
59
|
|
|
90
|
-
|
|
91
|
-
`cd ${directory}` +
|
|
92
|
-
` && git pull ${repoUrl}` +
|
|
93
|
-
` && git add . && git commit -m "backup ${new Date().toLocaleDateString()}"` +
|
|
94
|
-
` && git push ${repoUrl}`,
|
|
95
|
-
{
|
|
96
|
-
disableLog: true,
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
60
|
+
shellExec(`node bin/db ${host}${path} export ${deployId} ${backUpPath}/${currentDate}`);
|
|
101
61
|
}
|
|
102
|
-
}
|
|
103
62
|
shellExec(
|
|
104
63
|
`cd ./engine-private/cron-backups` +
|
|
105
|
-
` &&
|
|
106
|
-
` && git add
|
|
107
|
-
` &&
|
|
64
|
+
` && underpost pull . underpostnet/cron-backups` +
|
|
65
|
+
` && git add .` +
|
|
66
|
+
` && underpost cmt . backup cron-job '${new Date().toLocaleDateString()}'` +
|
|
67
|
+
` && underpost push . underpostnet/cron-backups`,
|
|
108
68
|
{
|
|
109
69
|
disableLog: true,
|
|
110
70
|
},
|
|
111
71
|
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return Callback;
|
|
116
|
-
},
|
|
117
|
-
Callback: async function (params) {},
|
|
118
|
-
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
119
75
|
|
|
120
|
-
export
|
|
76
|
+
export default BackUp;
|
|
@@ -21,6 +21,7 @@ import swaggerAutoGen from 'swagger-autogen';
|
|
|
21
21
|
import { SitemapStream, streamToPromise } from 'sitemap';
|
|
22
22
|
import { Readable } from 'stream';
|
|
23
23
|
import { buildIcons, buildTextImg, getBufferPngText } from './client-icons.js';
|
|
24
|
+
import Underpost from '../index.js';
|
|
24
25
|
|
|
25
26
|
dotenv.config();
|
|
26
27
|
|
|
@@ -191,8 +192,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
191
192
|
|
|
192
193
|
if (redirect || disabledRebuild) continue;
|
|
193
194
|
|
|
194
|
-
if (fullBuildEnabled)
|
|
195
|
-
// !(confServer[host]['/'] && confServer[host]['/'].liteBuild)
|
|
195
|
+
if (fullBuildEnabled)
|
|
196
196
|
await fullBuild({
|
|
197
197
|
path,
|
|
198
198
|
logger,
|
|
@@ -205,14 +205,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
205
205
|
iconsBuild,
|
|
206
206
|
metadata,
|
|
207
207
|
});
|
|
208
|
-
if (apis && false)
|
|
209
|
-
for (const apiBuildScript of apis) {
|
|
210
|
-
const scriptPath = `src/api/${apiBuildScript}/${apiBuildScript}.build.js`;
|
|
211
|
-
if (fs.existsSync(`./${scriptPath}`)) {
|
|
212
|
-
shellExec(`node ${scriptPath}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
208
|
|
|
217
209
|
if (components)
|
|
218
210
|
for (const module of Object.keys(components)) {
|
|
@@ -259,20 +251,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
259
251
|
'services',
|
|
260
252
|
baseHost,
|
|
261
253
|
);
|
|
262
|
-
if (module === 'core' && (process.env.NODE_ENV === 'production' || process.argv.includes('static'))) {
|
|
263
|
-
if (apiBaseHost)
|
|
264
|
-
jsSrc = jsSrc.replace(
|
|
265
|
-
'const getBaseHost = () => location.host;',
|
|
266
|
-
`const getBaseHost = () => '${apiBaseHost}';`,
|
|
267
|
-
);
|
|
268
|
-
if (apiBaseProxyPath) {
|
|
269
|
-
jsSrc = jsSrc.replace('${getProxyPath()}api/', `${apiBaseProxyPath}${process.env.BASE_API}/`);
|
|
270
|
-
jsSrc = jsSrc.replace(
|
|
271
|
-
"const getWsBasePath = () => (getProxyPath() !== '/' ? `${getProxyPath()}socket.io/` : undefined);",
|
|
272
|
-
`const getWsBasePath = () => '${apiBaseProxyPath}socket.io/';`,
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
254
|
fs.writeFileSync(
|
|
277
255
|
jsPublicPath,
|
|
278
256
|
minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
|
|
@@ -496,7 +474,13 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
496
474
|
}
|
|
497
475
|
|
|
498
476
|
default:
|
|
499
|
-
ssrBodyComponents += SrrComponent({
|
|
477
|
+
ssrBodyComponents += SrrComponent({
|
|
478
|
+
ssrPath,
|
|
479
|
+
host,
|
|
480
|
+
path,
|
|
481
|
+
ttiLoadTimeLimit,
|
|
482
|
+
version: Underpost.version,
|
|
483
|
+
});
|
|
500
484
|
break;
|
|
501
485
|
}
|
|
502
486
|
}
|
|
@@ -516,6 +500,15 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
516
500
|
ssrPath,
|
|
517
501
|
ssrHeadComponents,
|
|
518
502
|
ssrBodyComponents,
|
|
503
|
+
renderPayload: {
|
|
504
|
+
apiBaseProxyPath,
|
|
505
|
+
apiBaseHost,
|
|
506
|
+
apiBasePath: process.env.BASE_API,
|
|
507
|
+
version: Underpost.version,
|
|
508
|
+
},
|
|
509
|
+
renderApi: {
|
|
510
|
+
JSONweb,
|
|
511
|
+
},
|
|
519
512
|
});
|
|
520
513
|
|
|
521
514
|
fs.writeFileSync(
|
|
@@ -716,6 +709,15 @@ root file where the route starts, such as index.js, app.js, routes.js, etc ... *
|
|
|
716
709
|
ssrPath,
|
|
717
710
|
ssrHeadComponents: '',
|
|
718
711
|
ssrBodyComponents: SsrComponent(),
|
|
712
|
+
renderPayload: {
|
|
713
|
+
apiBaseProxyPath,
|
|
714
|
+
apiBaseHost,
|
|
715
|
+
apiBasePath: process.env.BASE_API,
|
|
716
|
+
version: Underpost.version,
|
|
717
|
+
},
|
|
718
|
+
renderApi: {
|
|
719
|
+
JSONweb,
|
|
720
|
+
},
|
|
719
721
|
});
|
|
720
722
|
|
|
721
723
|
const buildPath = `${
|
|
@@ -748,16 +750,14 @@ root file where the route starts, such as index.js, app.js, routes.js, etc ... *
|
|
|
748
750
|
}
|
|
749
751
|
|
|
750
752
|
{
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
+
const renderPayload = {
|
|
754
|
+
PRE_CACHED_RESOURCES: uniqueArray(PRE_CACHED_RESOURCES),
|
|
755
|
+
PROXY_PATH: path,
|
|
756
|
+
};
|
|
753
757
|
fs.writeFileSync(
|
|
754
758
|
`${rootClientPath}/sw.js`,
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
.replaceAll(`PRE_CACHED_RESOURCES = []`, PRE_CACHED_JSON)
|
|
758
|
-
.replaceAll(`PRE_CACHED_RESOURCES=[]`, PRE_CACHED_JSON)
|
|
759
|
-
.replaceAll(`PROXY_PATH = '/'`, PROXY_PATH)
|
|
760
|
-
.replaceAll(`PROXY_PATH='/'`, PROXY_PATH),
|
|
759
|
+
`self.renderPayload = ${JSONweb(renderPayload)};
|
|
760
|
+
${fs.readFileSync(`${rootClientPath}/sw.js`, 'utf8')}`,
|
|
761
761
|
'utf8',
|
|
762
762
|
);
|
|
763
763
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
|
+
import vm from 'node:vm';
|
|
5
|
+
import Underpost from '../index.js';
|
|
4
6
|
|
|
5
7
|
const srcFormatted = (src) =>
|
|
6
8
|
src
|
|
@@ -48,9 +50,10 @@ const viewFormatted = (src, dists, proxyPath, baseHost = '') => {
|
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
const ssrFactory = async (componentPath = `./src/client/ssr/Render.js`) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const context = { SrrComponent: () => {}, npm_package_version: Underpost.version };
|
|
54
|
+
vm.createContext(context);
|
|
55
|
+
vm.runInContext(await srcFormatted(fs.readFileSync(componentPath, 'utf8')), context);
|
|
56
|
+
return context.SrrComponent;
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
export { srcFormatted, JSONweb, componentFormatted, viewFormatted, ssrFactory };
|