underpost 2.8.482 → 2.8.522
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/.vscode/settings.json +1 -0
- package/CHANGELOG.md +24 -0
- package/bin/build.js +1 -1
- package/bin/deploy.js +18 -22
- package/bin/hwt.js +0 -10
- package/bin/index.js +19 -7
- package/bin/util.js +0 -15
- package/docker-compose.yml +1 -1
- package/package.json +2 -1
- package/src/api/core/core.service.js +1 -1
- package/src/cli/cluster.js +38 -20
- package/src/cli/cron.js +90 -0
- package/src/cli/deploy.js +18 -10
- package/src/cli/image.js +15 -7
- package/src/cli/test.js +25 -1
- package/src/client/components/core/Css.js +1 -0
- package/src/db/mongo/MongooseDB.js +15 -1
- package/src/index.js +9 -1
- package/src/server/backup.js +49 -93
- package/src/server/conf.js +33 -18
- package/src/server/dns.js +27 -51
- package/src/server/downloader.js +0 -8
- 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-headless-service.yaml +0 -10
- 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-pv-pvc.yaml +0 -23
- package/manifests/core/underpost-engine-statefulset.yaml +0 -91
- package/src/dns.js +0 -22
|
@@ -79,7 +79,17 @@ 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
|
|
83
93
|
}
|
|
84
94
|
logger.info('install legacy 4.4');
|
|
85
95
|
shellExec(`wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -`);
|
|
@@ -112,9 +122,13 @@ const MongooseDB = {
|
|
|
112
122
|
shellExec(`sudo systemctl unmask mongod`);
|
|
113
123
|
shellExec(`sudo pkill -f mongod`);
|
|
114
124
|
shellExec(`sudo systemctl enable mongod.service`);
|
|
125
|
+
|
|
115
126
|
shellExec(`sudo chown -R mongodb:mongodb /var/lib/mongodb`);
|
|
116
127
|
shellExec(`sudo chown mongodb:mongodb /tmp/mongodb-27017.sock`);
|
|
117
128
|
|
|
129
|
+
shellExec(`sudo chown -R mongod:mongod /var/lib/mongodb`);
|
|
130
|
+
shellExec(`sudo chown mongod:mongod /tmp/mongodb-27017.sock`);
|
|
131
|
+
|
|
118
132
|
logger.info('run server');
|
|
119
133
|
shellExec(`sudo service mongod restart`);
|
|
120
134
|
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import UnderpostCluster from './cli/cluster.js';
|
|
8
|
+
import UnderpostCron from './cli/cron.js';
|
|
8
9
|
import UnderpostDB from './cli/db.js';
|
|
9
10
|
import UnderpostDeploy from './cli/deploy.js';
|
|
10
11
|
import UnderpostRootEnv from './cli/env.js';
|
|
@@ -26,7 +27,7 @@ class Underpost {
|
|
|
26
27
|
* @type {String}
|
|
27
28
|
* @memberof Underpost
|
|
28
29
|
*/
|
|
29
|
-
static version = 'v2.8.
|
|
30
|
+
static version = 'v2.8.522';
|
|
30
31
|
/**
|
|
31
32
|
* Repository cli API
|
|
32
33
|
* @static
|
|
@@ -90,6 +91,13 @@ class Underpost {
|
|
|
90
91
|
* @memberof Underpost
|
|
91
92
|
*/
|
|
92
93
|
static deploy = UnderpostDeploy.API;
|
|
94
|
+
/**
|
|
95
|
+
* Cron cli API
|
|
96
|
+
* @static
|
|
97
|
+
* @type {UnderpostCron.API}
|
|
98
|
+
* @memberof Underpost
|
|
99
|
+
*/
|
|
100
|
+
static cron = UnderpostCron.API;
|
|
93
101
|
}
|
|
94
102
|
|
|
95
103
|
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 = { disableKindCluster: 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.disableKindCluster !== true) {
|
|
29
|
+
shellExec(`underpost db --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;
|
package/src/server/conf.js
CHANGED
|
@@ -19,17 +19,8 @@ import { DefaultConf } from '../../conf.js';
|
|
|
19
19
|
import read from 'read';
|
|
20
20
|
import splitFile from 'split-file';
|
|
21
21
|
import axios from 'axios';
|
|
22
|
-
import https from 'https';
|
|
23
22
|
import { ssrFactory } from './client-formatted.js';
|
|
24
23
|
|
|
25
|
-
// axios.defaults.baseURL = BASE_URL;
|
|
26
|
-
|
|
27
|
-
// const httpsAgent = new https.Agent({
|
|
28
|
-
// rejectUnauthorized: false,
|
|
29
|
-
// });
|
|
30
|
-
|
|
31
|
-
// axios.defaults.httpsAgent = httpsAgent;
|
|
32
|
-
|
|
33
24
|
colors.enable();
|
|
34
25
|
|
|
35
26
|
dotenv.config();
|
|
@@ -98,6 +89,14 @@ const Config = {
|
|
|
98
89
|
};
|
|
99
90
|
|
|
100
91
|
const loadConf = (deployId, envInput, subConf) => {
|
|
92
|
+
if (deployId === 'clean') {
|
|
93
|
+
shellExec(`git checkout package.json`);
|
|
94
|
+
shellExec(`git checkout .env.production`);
|
|
95
|
+
shellExec(`git checkout .env.development`);
|
|
96
|
+
shellExec(`git checkout .env.test`);
|
|
97
|
+
shellExec(`git checkout jsdoc.json`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
101
100
|
const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
|
|
102
101
|
? `./engine-private/replica/${deployId}`
|
|
103
102
|
: `./engine-private/conf/${deployId}`;
|
|
@@ -590,9 +589,25 @@ const cliSpinner = async (time = 5000, message0, message1, color, type = 'dots')
|
|
|
590
589
|
const buildReplicaId = ({ deployId, replica }) => `${deployId}-${replica.slice(1)}`;
|
|
591
590
|
|
|
592
591
|
const getDataDeploy = (
|
|
593
|
-
options = {
|
|
592
|
+
options = {
|
|
593
|
+
buildSingleReplica: false,
|
|
594
|
+
deployGroupId: '',
|
|
595
|
+
deployId: '',
|
|
596
|
+
disableSyncEnvPort: false,
|
|
597
|
+
deployIdConcat: [],
|
|
598
|
+
},
|
|
594
599
|
) => {
|
|
595
|
-
let dataDeploy =
|
|
600
|
+
let dataDeploy =
|
|
601
|
+
options.deployGroupId === 'dd'
|
|
602
|
+
? fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}.router`, 'utf8')
|
|
603
|
+
: fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}`, 'utf8');
|
|
604
|
+
|
|
605
|
+
dataDeploy = dataDeploy
|
|
606
|
+
.split(',')
|
|
607
|
+
.map((deployId) => deployId.trim())
|
|
608
|
+
.filter((deployId) => deployId);
|
|
609
|
+
|
|
610
|
+
if (options.deployIdConcat) dataDeploy = dataDeploy.concat(options.deployIdConcat);
|
|
596
611
|
|
|
597
612
|
if (options.deployId) dataDeploy = dataDeploy.filter((d) => d === options.deployId);
|
|
598
613
|
|
|
@@ -827,7 +842,7 @@ const deployRun = async (dataDeploy, currentAttempt = 1) => {
|
|
|
827
842
|
if (failed.length > 0) {
|
|
828
843
|
for (const deploy of failed) logger.error(deploy.deployId, Cmd.run(deploy.deployId));
|
|
829
844
|
if (currentAttempt === maxAttempts) return logger.error(`max deploy attempts exceeded`);
|
|
830
|
-
|
|
845
|
+
await read({ prompt: 'Press enter to retry failed processes\n' });
|
|
831
846
|
currentAttempt++;
|
|
832
847
|
await deployRun(failed, currentAttempt);
|
|
833
848
|
} else logger.info(`Deploy process successfully`);
|
|
@@ -973,15 +988,15 @@ const getPathsSSR = (conf) => {
|
|
|
973
988
|
|
|
974
989
|
const Cmd = {
|
|
975
990
|
delete: (deployId) => `pm2 delete ${deployId}`,
|
|
976
|
-
run: (
|
|
991
|
+
run: () => `npm start`,
|
|
977
992
|
build: (deployId) => `node bin/deploy build-full-client ${deployId}${process.argv.includes('l') ? ' l' : ''}`,
|
|
978
993
|
conf: (deployId, env) => `node bin/deploy conf ${deployId} ${env ? env : 'production'}`,
|
|
979
994
|
replica: (deployId, host, path) => `node bin/deploy build-single-replica ${deployId} ${host} ${path}`,
|
|
980
995
|
syncPorts: (deployGroupId) => `node bin/deploy sync-env-port ${deployGroupId}`,
|
|
981
|
-
cron: (
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
996
|
+
cron: (deployList, jobList, name, expression, options) =>
|
|
997
|
+
`pm2 start ./bin/index.js --no-autorestart --instances 1 --cron "${expression}" --name ${name} -- cron ${
|
|
998
|
+
options?.disableKindCluster ? `--disable-kind-cluster ` : ''
|
|
999
|
+
}${deployList} ${jobList}`,
|
|
985
1000
|
};
|
|
986
1001
|
|
|
987
1002
|
const fixDependencies = async () => {
|
|
@@ -1048,7 +1063,7 @@ const setUpProxyMaintenanceServer = ({ deployGroupId }) => {
|
|
|
1048
1063
|
shellExec(`node bin/deploy valkey-service`);
|
|
1049
1064
|
const proxyDeployId = fs.readFileSync(`./engine-private/deploy/${deployGroupId}.proxy`, 'utf8').trim();
|
|
1050
1065
|
shellExec(`node bin/deploy conf ${proxyDeployId} production`);
|
|
1051
|
-
shellExec(`
|
|
1066
|
+
shellExec(`npm start ${proxyDeployId} maintenance`);
|
|
1052
1067
|
};
|
|
1053
1068
|
|
|
1054
1069
|
const getNpmRootPath = () =>
|
package/src/server/dns.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import dotenv from 'dotenv';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
-
import https from 'https';
|
|
5
4
|
import validator from 'validator';
|
|
6
5
|
import { ip } from './network.js';
|
|
7
6
|
import { loggerFactory } from './logger.js';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
const httpsAgent = new https.Agent({
|
|
11
|
-
rejectUnauthorized: false,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
axios.defaults.httpsAgent = httpsAgent;
|
|
7
|
+
import UnderpostRootEnv from '../cli/env.js';
|
|
15
8
|
|
|
16
9
|
dotenv.config();
|
|
17
10
|
|
|
18
11
|
const logger = loggerFactory(import.meta);
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
callback: () => null,
|
|
23
|
-
InitIpDaemon: async function ({ deployId }) {
|
|
13
|
+
class Dns {
|
|
14
|
+
static callback = async function (deployList) {
|
|
24
15
|
// NAT-VPS modem/router device configuration:
|
|
25
16
|
// LAN --> [NAT-VPS] --> WAN
|
|
26
17
|
// enabled DMZ Host to proxy IP 80-443 (79-444) sometimes router block first port
|
|
@@ -30,25 +21,24 @@ const Dns = {
|
|
|
30
21
|
// LAN server or device's local servers port -> 3000-3100 (2999-3101)
|
|
31
22
|
// DNS Records: [ANAME](Address Dynamic) -> [A](ipv4) host | [AAAA](ipv6) host -> [public-ip]
|
|
32
23
|
// Forward the router's TCP/UDP ports to the LAN device's IP address
|
|
24
|
+
for (const _deployId of deployList.split(',')) {
|
|
25
|
+
const deployId = _deployId.trim();
|
|
26
|
+
const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
|
|
27
|
+
const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
|
|
28
|
+
const confCronData = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
|
|
33
29
|
|
|
34
|
-
const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
|
|
35
|
-
|
|
36
|
-
const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
|
|
37
|
-
let confCronData = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
|
|
38
|
-
if (confCronData.ipDaemon.disabled) return;
|
|
39
|
-
Dns.ip = confCronData.ipDaemon.ip;
|
|
40
|
-
logger.info(`Current ip`, Dns.ip);
|
|
41
|
-
const callback = async () => {
|
|
42
|
-
logger.info('init dns ip callback');
|
|
43
|
-
await logger.setUpInfo();
|
|
44
30
|
let testIp;
|
|
31
|
+
|
|
45
32
|
try {
|
|
46
33
|
testIp = await ip.public.ipv4();
|
|
47
34
|
} catch (error) {
|
|
48
35
|
logger.error(error, { testIp, stack: error.stack });
|
|
49
36
|
}
|
|
50
|
-
|
|
51
|
-
|
|
37
|
+
|
|
38
|
+
const currentIp = UnderpostRootEnv.API.get('ip');
|
|
39
|
+
|
|
40
|
+
if (testIp && typeof testIp === 'string' && validator.isIP(testIp) && currentIp !== testIp) {
|
|
41
|
+
logger.info(`new ip`, testIp);
|
|
52
42
|
for (const recordType of Object.keys(confCronData.records)) {
|
|
53
43
|
switch (recordType) {
|
|
54
44
|
case 'A':
|
|
@@ -66,20 +56,20 @@ const Dns = {
|
|
|
66
56
|
const ipUrlTest = `https://${process.env.DEFAULT_DEPLOY_HOST}`;
|
|
67
57
|
const response = await axios.get(ipUrlTest);
|
|
68
58
|
const verifyIp = response.request.socket.remoteAddress;
|
|
69
|
-
logger.info(ipUrlTest + '
|
|
59
|
+
logger.info(ipUrlTest + ' verify ip', verifyIp);
|
|
70
60
|
if (verifyIp === testIp) {
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
logger.info('ip updated successfully', testIp);
|
|
62
|
+
UnderpostRootEnv.API.set('ip', testIp);
|
|
63
|
+
} else logger.error('ip not updated', testIp);
|
|
73
64
|
} catch (error) {
|
|
74
|
-
logger.error(error
|
|
65
|
+
logger.error(error, error.stack);
|
|
66
|
+
logger.error('ip not updated', testIp);
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
services: {
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
static services = {
|
|
83
73
|
updateIp: {
|
|
84
74
|
dondominio: (options) => {
|
|
85
75
|
const { user, api_key, host, dns, ip } = options;
|
|
@@ -100,21 +90,7 @@ const Dns = {
|
|
|
100
90
|
});
|
|
101
91
|
},
|
|
102
92
|
},
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
Dns.ip = ip;
|
|
106
|
-
confCronData.ipDaemon.ip = ip;
|
|
107
|
-
fs.writeFileSync(confCronPath, JSON.stringify(confCronData, null, 4), 'utf8');
|
|
108
|
-
shellExec(
|
|
109
|
-
`cd ./engine-private` +
|
|
110
|
-
` && git pull ${Dns.repoUrl}` +
|
|
111
|
-
` && git add . && git commit -m "update ip ${new Date().toLocaleDateString()}"` +
|
|
112
|
-
` && git push ${Dns.repoUrl}`,
|
|
113
|
-
{
|
|
114
|
-
disableLog: true,
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
119
95
|
|
|
120
|
-
export
|
|
96
|
+
export default Dns;
|
package/src/server/downloader.js
CHANGED
|
@@ -2,16 +2,8 @@ import axios from 'axios';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { loggerFactory } from './logger.js';
|
|
4
4
|
import dotenv from 'dotenv';
|
|
5
|
-
import https from 'https';
|
|
6
|
-
|
|
7
5
|
dotenv.config();
|
|
8
6
|
|
|
9
|
-
const httpsAgent = new https.Agent({
|
|
10
|
-
rejectUnauthorized: false,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
axios.defaults.httpsAgent = httpsAgent;
|
|
14
|
-
|
|
15
7
|
const logger = loggerFactory(import.meta);
|
|
16
8
|
|
|
17
9
|
const Downloader = (url, fullPath, options = { method: 'get', responseType: 'stream' }) =>
|
package/test/api.test.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import dotenv from 'dotenv';
|
|
5
|
-
import https from 'https';
|
|
6
5
|
|
|
7
6
|
import { expect } from 'chai';
|
|
8
7
|
import { loggerFactory } from '../src/server/logger.js';
|
|
@@ -20,13 +19,6 @@ const BASE_URL =
|
|
|
20
19
|
? `http://localhost:${PORT}/${process.env.BASE_API}`
|
|
21
20
|
: `https://www.nexodev.org/api`;
|
|
22
21
|
|
|
23
|
-
axios.defaults.baseURL = BASE_URL;
|
|
24
|
-
|
|
25
|
-
const httpsAgent = new https.Agent({
|
|
26
|
-
rejectUnauthorized: false,
|
|
27
|
-
});
|
|
28
|
-
axios.defaults.httpsAgent = httpsAgent;
|
|
29
|
-
|
|
30
22
|
describe(`GET 'Test' API Request `, async () => {
|
|
31
23
|
{
|
|
32
24
|
const url = `${BASE_URL}/test/youtube-id/?url=https://www.youtube.com/watch?v=o4f42SbyDMk`;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
# kubectl apply -k core/.
|
|
3
|
-
apiVersion: kustomize.config.k8s.io/v1beta1
|
|
4
|
-
kind: Kustomization
|
|
5
|
-
resources:
|
|
6
|
-
- underpost-engine-pv-pvc.yaml
|
|
7
|
-
- underpost-engine-headless-service.yaml
|
|
8
|
-
- underpost-engine-statefulset.yaml
|
|
9
|
-
- underpost-engine-backup-pv-pvc.yaml
|
|
10
|
-
- underpost-engine-mongodb-backup-cronjob.yaml
|
|
11
|
-
- underpost-engine-backup-access.yaml
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
apiVersion: v1
|
|
2
|
-
kind: Pod
|
|
3
|
-
metadata:
|
|
4
|
-
name: backup-access
|
|
5
|
-
spec:
|
|
6
|
-
containers:
|
|
7
|
-
- name: busybox
|
|
8
|
-
image: busybox
|
|
9
|
-
command: ['sh', '-c', 'sleep 3600']
|
|
10
|
-
volumeMounts:
|
|
11
|
-
- name: backup-storage
|
|
12
|
-
mountPath: /backup
|
|
13
|
-
volumes:
|
|
14
|
-
- name: backup-storage
|
|
15
|
-
persistentVolumeClaim:
|
|
16
|
-
claimName: backup-pvc
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
apiVersion: v1
|
|
2
|
-
kind: PersistentVolume
|
|
3
|
-
metadata:
|
|
4
|
-
name: backup-pv
|
|
5
|
-
spec:
|
|
6
|
-
capacity:
|
|
7
|
-
storage: 5Gi
|
|
8
|
-
accessModes:
|
|
9
|
-
- ReadWriteOnce
|
|
10
|
-
hostPath:
|
|
11
|
-
path: /mnt/backup
|
|
12
|
-
---
|
|
13
|
-
apiVersion: v1
|
|
14
|
-
kind: PersistentVolumeClaim
|
|
15
|
-
metadata:
|
|
16
|
-
name: backup-pvc
|
|
17
|
-
spec:
|
|
18
|
-
accessModes:
|
|
19
|
-
- ReadWriteOnce
|
|
20
|
-
resources:
|
|
21
|
-
requests:
|
|
22
|
-
storage: 5Gi
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
apiVersion: batch/v1
|
|
2
|
-
kind: CronJob
|
|
3
|
-
metadata:
|
|
4
|
-
name: mongodb-backup
|
|
5
|
-
spec:
|
|
6
|
-
schedule: '*/5 * * * *' # Runs backup every five minutes
|
|
7
|
-
jobTemplate:
|
|
8
|
-
spec:
|
|
9
|
-
template:
|
|
10
|
-
spec:
|
|
11
|
-
containers:
|
|
12
|
-
- name: mongodump
|
|
13
|
-
image: docker.io/library/mongo:latest
|
|
14
|
-
command:
|
|
15
|
-
- sh
|
|
16
|
-
- -c
|
|
17
|
-
- |
|
|
18
|
-
# Perform backup
|
|
19
|
-
mongodump -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --host=mongodb-service --port=27017 --out=/backup/$(date +\%Y-\%m-\%dT\%H-\%M-\%S)
|
|
20
|
-
# Remove backups older than 7 days
|
|
21
|
-
find /backup -type d -mtime +7 -exec rm -rf {} +
|
|
22
|
-
volumeMounts:
|
|
23
|
-
- name: backup-storage
|
|
24
|
-
mountPath: /backup
|
|
25
|
-
env:
|
|
26
|
-
- name: MONGO_INITDB_ROOT_USERNAME
|
|
27
|
-
valueFrom:
|
|
28
|
-
secretKeyRef:
|
|
29
|
-
name: mongodb-secret
|
|
30
|
-
key: username
|
|
31
|
-
- name: MONGO_INITDB_ROOT_PASSWORD
|
|
32
|
-
valueFrom:
|
|
33
|
-
secretKeyRef:
|
|
34
|
-
name: mongodb-secret
|
|
35
|
-
key: password
|
|
36
|
-
restartPolicy: Never
|
|
37
|
-
volumes:
|
|
38
|
-
- name: backup-storage
|
|
39
|
-
persistentVolumeClaim:
|
|
40
|
-
claimName: backup-pvc
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# origin conf: /etc/mongod.conf
|
|
2
|
-
apiVersion: v1
|
|
3
|
-
kind: ConfigMap
|
|
4
|
-
metadata:
|
|
5
|
-
name: mongodb-config-file
|
|
6
|
-
namespace: default
|
|
7
|
-
data:
|
|
8
|
-
mongod.conf: |
|
|
9
|
-
storage:
|
|
10
|
-
dbPath: /data/db
|
|
11
|
-
systemLog:
|
|
12
|
-
destination: file
|
|
13
|
-
logAppend: true
|
|
14
|
-
path: /var/log/mongodb/mongod.log
|
|
15
|
-
replication:
|
|
16
|
-
replSetName: rs0
|
|
17
|
-
net:
|
|
18
|
-
bindIp: 127.0.0.1
|
|
19
|
-
port: 27017
|
|
20
|
-
processManagement:
|
|
21
|
-
fork: true
|
|
22
|
-
setParameter:
|
|
23
|
-
enableLocalhostAuthBypass: false
|
|
24
|
-
security:
|
|
25
|
-
authorization: enabled
|
|
26
|
-
keyFile: /etc/mongodb-keyfile
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
apiVersion: v1
|
|
2
|
-
kind: PersistentVolume
|
|
3
|
-
metadata:
|
|
4
|
-
name: mongodb-pv
|
|
5
|
-
spec:
|
|
6
|
-
capacity:
|
|
7
|
-
storage: 5Gi
|
|
8
|
-
accessModes:
|
|
9
|
-
- ReadWriteOnce
|
|
10
|
-
hostPath:
|
|
11
|
-
path: /data/mongodb
|
|
12
|
-
---
|
|
13
|
-
apiVersion: v1
|
|
14
|
-
kind: PersistentVolumeClaim
|
|
15
|
-
metadata:
|
|
16
|
-
name: mongodb-pvc
|
|
17
|
-
spec:
|
|
18
|
-
storageClassName: ''
|
|
19
|
-
accessModes:
|
|
20
|
-
- ReadWriteOnce
|
|
21
|
-
resources:
|
|
22
|
-
requests:
|
|
23
|
-
storage: 5Gi
|