underpost 2.8.51 → 2.8.55

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/src/cli/deploy.js CHANGED
@@ -180,70 +180,90 @@ spec:
180
180
  async callback(
181
181
  deployList = 'default',
182
182
  env = 'development',
183
- options = { remove: false, infoRouter: false, sync: false, buildManifest: false },
183
+ options = { remove: false, infoRouter: false, sync: false, buildManifest: false, infoUtil: false, expose: false },
184
184
  ) {
185
+ if (options.infoUtil === true)
186
+ return logger.info(`
187
+ kubectl rollout restart deployment/deployment-name
188
+ kubectl rollout undo deployment/deployment-name
189
+ kubectl scale statefulsets <stateful-set-name> --replicas=<new-replicas>
190
+ `);
185
191
  if (deployList === 'dd' && fs.existsSync(`./engine-private/deploy/dd.router`))
186
192
  deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
187
193
  if (options.sync) UnderpostDeploy.API.sync(deployList);
188
194
  if (options.buildManifest === true) await UnderpostDeploy.API.buildManifest(deployList, env);
189
195
  if (options.infoRouter === true)
190
196
  return logger.info('router', await UnderpostDeploy.API.routerFactory(deployList, env));
197
+ const etcHost = (
198
+ concat,
199
+ ) => `127.0.0.1 ${concat} localhost localhost.localdomain localhost4 localhost4.localdomain4
200
+ ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6`;
201
+ let concatHots = '';
191
202
 
192
203
  for (const _deployId of deployList.split(',')) {
193
204
  const deployId = _deployId.trim();
194
205
  if (!deployId) continue;
195
-
206
+ if (options.expose === true) {
207
+ const svc = UnderpostDeploy.API.get(deployId, 'svc')[0];
208
+ const port = parseInt(svc[`PORT(S)`].split('/TCP')[0]);
209
+ logger.info(deployId, {
210
+ svc,
211
+ port,
212
+ });
213
+ shellExec(`sudo kubectl port-forward -n default svc/${svc.NAME} ${port}:${port}`, { async: true });
214
+ continue;
215
+ }
196
216
  shellExec(`sudo kubectl delete svc ${deployId}-${env}-service`);
197
217
  shellExec(`sudo kubectl delete deployment ${deployId}-${env}`);
198
218
 
199
- const etcHost = (
200
- concat,
201
- ) => `127.0.0.1 ${concat} localhost localhost.localdomain localhost4 localhost4.localdomain4
202
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6`;
203
- let concatHots = '';
204
-
205
219
  const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
206
220
  for (const host of Object.keys(confServer)) {
207
221
  shellExec(`sudo kubectl delete HTTPProxy ${host}`);
222
+ if (env === 'production') shellExec(`sudo kubectl delete Certificate ${host}`);
208
223
  if (!options.remove === true && env === 'development') concatHots += ` ${host}`;
209
224
  }
210
225
 
226
+ const manifestsPath =
227
+ env === 'production'
228
+ ? `engine-private/conf/${deployId}/build/production`
229
+ : `manifests/deployment/${deployId}-${env}`;
230
+
211
231
  if (!options.remove === true) {
212
- shellExec(`sudo kubectl apply -f ./manifests/deployment/${deployId}-${env}/deployment.yaml`);
213
- shellExec(`sudo kubectl apply -f ./manifests/deployment/${deployId}-${env}/proxy.yaml`);
232
+ shellExec(`sudo kubectl apply -f ./${manifestsPath}/deployment.yaml`);
233
+ shellExec(`sudo kubectl apply -f ./${manifestsPath}/proxy.yaml`);
234
+ if (env === 'production') shellExec(`sudo kubectl apply -f ./${manifestsPath}/secret.yaml`);
214
235
  }
236
+ }
237
+ let renderHosts;
238
+ switch (process.platform) {
239
+ case 'linux':
240
+ {
241
+ switch (env) {
242
+ case 'development':
243
+ renderHosts = etcHost(concatHots);
244
+ fs.writeFileSync(`/etc/hosts`, renderHosts, 'utf8');
215
245
 
216
- let renderHosts;
217
-
218
- switch (process.platform) {
219
- case 'linux':
220
- {
221
- switch (env) {
222
- case 'development':
223
- renderHosts = etcHost(concatHots);
224
- fs.writeFileSync(`/etc/hosts`, renderHosts, 'utf8');
225
-
226
- break;
246
+ break;
227
247
 
228
- default:
229
- break;
230
- }
248
+ default:
249
+ break;
231
250
  }
232
- break;
251
+ }
252
+ break;
233
253
 
234
- default:
235
- break;
236
- }
254
+ default:
255
+ break;
256
+ }
257
+ if (renderHosts)
237
258
  logger.info(
238
259
  `
239
260
  ` + renderHosts,
240
261
  );
241
- }
242
262
  },
243
- getPods(deployId) {
244
- const raw = shellExec(`sudo kubectl get pods --all-namespaces -o wide`, {
263
+ get(deployId, kindType = 'pods') {
264
+ const raw = shellExec(`sudo kubectl get ${kindType} --all-namespaces -o wide`, {
245
265
  stdout: true,
246
- disableLog: false,
266
+ disableLog: true,
247
267
  silent: true,
248
268
  });
249
269
 
package/src/cli/image.js CHANGED
@@ -13,11 +13,18 @@ class UnderpostImage {
13
13
  pullBaseImages() {
14
14
  shellExec(`sudo podman pull docker.io/library/debian:buster`);
15
15
  },
16
- build(deployId = 'default', env = 'development', path = '.', options = { imageArchive: false }) {
16
+ build(
17
+ deployId = 'default',
18
+ env = 'development',
19
+ path = '.',
20
+ options = { imageArchive: false, podmanSave: false },
21
+ ) {
17
22
  const imgName = `${deployId}-${env}:${Underpost.version}`;
18
23
  const podManImg = `localhost/${imgName}`;
19
- const imagesStoragePath = `./images`;
20
- const tarFile = `${imagesStoragePath}/${imgName.replace(':', '_')}.tar`;
24
+ const imagesStoragePath = `/images`;
25
+ if (!fs.existsSync(`${path}${imagesStoragePath}`))
26
+ fs.mkdirSync(`${path}${imagesStoragePath}`, { recursive: true });
27
+ const tarFile = `.${imagesStoragePath}/${imgName.replace(':', '_')}.tar`;
21
28
 
22
29
  let secrets = ' ';
23
30
  let secretDockerInput = '';
@@ -36,8 +43,9 @@ class UnderpostImage {
36
43
  `cd ${path}${secrets}&& sudo podman build -f ./Dockerfile -t ${imgName} --pull=never --cap-add=CAP_AUDIT_WRITE${secretDockerInput}`,
37
44
  );
38
45
  fs.removeSync(`${path}/.env.underpost`);
39
- shellExec(`cd ${path} && podman save -o ${tarFile} ${podManImg}`);
40
46
  }
47
+ if (options.imageArchive !== true || options.podmanSave === true)
48
+ shellExec(`cd ${path} && podman save -o ${tarFile} ${podManImg}`);
41
49
  shellExec(`cd ${path} && sudo kind load image-archive ${tarFile}`);
42
50
  },
43
51
  async script(deployId = 'default', env = 'development', options = { run: false }) {
@@ -46,23 +54,6 @@ class UnderpostImage {
46
54
  {
47
55
  const lamppPublicPath = '/xampp/htdocs/online';
48
56
  shellExec(`sudo mkdir -p ${lamppPublicPath}`);
49
-
50
- {
51
- shellExec(
52
- `cd ${lamppPublicPath} && git clone https://${process.env.GITHUB_TOKEN}@github.com/${process.env.DD_LAMPP_REPO_0}`,
53
- );
54
-
55
- shellExec(`cd ${lamppPublicPath} && sudo ${process.env.DD_LAMPP_SCRIPT_0}`);
56
-
57
- shellExec(
58
- `sudo sed -i -e "s@define( 'DB_HOST', 'localhost' );@define( 'DB_HOST', '${process.env.MARIADB_HOST}' );@g" ${lamppPublicPath}/${process.env.DD_LAMPP_REPO_0_FOLDER}/wp-config.php`,
59
- );
60
- }
61
- {
62
- shellExec(
63
- `cd ${lamppPublicPath} && git clone https://${process.env.GITHUB_TOKEN}@github.com/${process.env.DD_LAMPP_REPO_1}`,
64
- );
65
- }
66
57
  }
67
58
  break;
68
59
 
@@ -101,12 +92,12 @@ class UnderpostImage {
101
92
  shellExec(`node bin/deploy conf ${deployId} ${env}`);
102
93
  shellExec(`node bin/deploy build-full-client ${deployId}`);
103
94
  if (options.run === true) {
104
- const runCmd = env === 'production' ? 'prod-img' : 'dev-img';
95
+ const runCmd = env === 'production' ? 'run prod-img' : 'run dev-img';
105
96
  if (fs.existsSync(`./engine-private/replica`)) {
106
97
  const replicas = await fs.readdir(`./engine-private/replica`);
107
98
  for (const replica of replicas) {
108
99
  shellExec(`node bin/deploy conf ${replica} ${env}`);
109
- shellExec(`npm run ${runCmd} ${replica} deploy`, { async: true });
100
+ shellExec(`npm ${runCmd} ${replica} deploy`, { async: true });
110
101
  fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
111
102
  const monitor = async () => {
112
103
  await timer(1000);
@@ -116,7 +107,7 @@ class UnderpostImage {
116
107
  }
117
108
  shellExec(`node bin/deploy conf ${deployId} ${env}`);
118
109
  }
119
- shellExec(`npm run ${runCmd} ${deployId} deploy`);
110
+ shellExec(`npm ${runCmd} ${deployId} deploy`);
120
111
  }
121
112
  },
122
113
  },
package/src/cli/script.js CHANGED
@@ -2,6 +2,7 @@ import { getNpmRootPath } 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
 
@@ -13,8 +14,31 @@ class UnderpostScript {
13
14
  packageJson.scripts[key] = value;
14
15
  fs.writeFileSync(`${npmRoot}/package.json`, JSON.stringify(packageJson, null, 4));
15
16
  },
16
- run(key) {
17
+ run(key, value, options) {
17
18
  const npmRoot = `${getNpmRootPath()}/underpost`;
19
+ const packageJson = JSON.parse(fs.readFileSync(`${npmRoot}/package.json`, 'utf8'));
20
+ if (options.itc === true) {
21
+ value = packageJson.scripts[key];
22
+ const podScriptPath = `${options.itcPath && typeof options.itcPath === 'string' ? options.itcPath : '/'}${value
23
+ .split('/')
24
+ .pop()}`;
25
+ const nameSpace = options.ns && typeof options.ns === 'string' ? options.ns : 'default';
26
+ const podMatch = options.podName && typeof options.podName === 'string' ? options.podName : key;
27
+
28
+ if (fs.existsSync(`${value}`)) {
29
+ for (const pod of UnderpostDeploy.API.get(podMatch)) {
30
+ shellExec(`sudo kubectl cp ${value} ${nameSpace}/${pod.NAME}:${podScriptPath}`);
31
+ const cmd = `node ${podScriptPath}`;
32
+ shellExec(`sudo kubectl exec -i ${pod.NAME} -- sh -c "${cmd}"`);
33
+ }
34
+ } else {
35
+ for (const pod of UnderpostDeploy.API.get(podMatch)) {
36
+ shellExec(`sudo kubectl exec -i ${pod.NAME} -- sh -c "${value}"`);
37
+ }
38
+ }
39
+
40
+ return;
41
+ }
18
42
  shellExec(`cd ${npmRoot} && npm run ${key}`);
19
43
  },
20
44
  get(key) {
package/src/cli/test.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { timer } from '../client/components/core/CommonJs.js';
1
2
  import { MariaDB } from '../db/mariadb/MariaDB.js';
2
3
  import { getNpmRootPath } from '../server/conf.js';
3
4
  import { actionInitLog, loggerFactory, setUpInfo } from '../server/logger.js';
@@ -28,9 +29,17 @@ class UnderpostTest {
28
29
  actionInitLog();
29
30
  shellExec(`cd ${getNpmRootPath()}/underpost && npm run test`);
30
31
  },
31
- async callback(deployList = '', options = { insideContainer: false, sh: false, logs: false }) {
32
+ async callback(deployList = '', options = { itc: false, sh: false, logs: false }) {
33
+ if (
34
+ options.podName &&
35
+ typeof options.podName === 'string' &&
36
+ options.podStatus &&
37
+ typeof options.podStatus === 'string'
38
+ )
39
+ return await UnderpostTest.API.podStatusMonitor(options.podName, options.podStatus);
40
+
32
41
  if (options.sh === true || options.logs === true) {
33
- const [pod] = UnderpostDeploy.API.getPods(deployList);
42
+ const [pod] = UnderpostDeploy.API.get(deployList);
34
43
  if (pod) {
35
44
  if (options.sh) return pbcopy(`sudo kubectl exec -it ${pod.NAME} -- sh`);
36
45
  if (options.logs) return shellExec(`sudo kubectl logs -f ${pod.NAME}`);
@@ -41,7 +50,7 @@ class UnderpostTest {
41
50
  for (const _deployId of deployList.split(',')) {
42
51
  const deployId = _deployId.trim();
43
52
  if (!deployId) continue;
44
- if (options.insideContainer === true)
53
+ if (options.itc === true)
45
54
  switch (deployId) {
46
55
  case 'dd-lampp':
47
56
  {
@@ -64,7 +73,7 @@ class UnderpostTest {
64
73
  break;
65
74
  }
66
75
  else {
67
- const pods = UnderpostDeploy.API.getPods(deployId);
76
+ const pods = UnderpostDeploy.API.get(deployId);
68
77
  if (pods.length > 0)
69
78
  for (const deployData of pods) {
70
79
  const { NAME } = deployData;
@@ -77,6 +86,21 @@ class UnderpostTest {
77
86
  }
78
87
  } else return UnderpostTest.API.run();
79
88
  },
89
+ podStatusMonitor(podName, status = 'Running', deltaMs = 1000) {
90
+ return new Promise(async (resolve) => {
91
+ let index = 0;
92
+ logger.info(`Loading ${podName} instance`, { status, deltaMs });
93
+ const _monitor = async () => {
94
+ await timer(deltaMs);
95
+ const result = UnderpostDeploy.API.get(podName).find((p) => p.STATUS === status);
96
+ logger.info(`Testing pod ${podName}... ${result ? 1 : 0}/1 - elapsed time ${deltaMs * (index + 1)}ms`);
97
+ if (result) return resolve();
98
+ index++;
99
+ return _monitor();
100
+ };
101
+ await _monitor();
102
+ });
103
+ },
80
104
  };
81
105
  }
82
106
 
@@ -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
- shellExec(`sudo chown -R mongod:mongod /var/lib/mongo`);
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
@@ -27,7 +27,7 @@ class Underpost {
27
27
  * @type {String}
28
28
  * @memberof Underpost
29
29
  */
30
- static version = 'v2.8.51';
30
+ static version = 'v2.8.55';
31
31
  /**
32
32
  * Repository cli API
33
33
  * @static
@@ -9,7 +9,7 @@ dotenv.config();
9
9
  const logger = loggerFactory(import.meta);
10
10
 
11
11
  class BackUp {
12
- static callback = async function (deployList, options = { disableKindCluster: false }) {
12
+ static callback = async function (deployList, options = { itc: false }) {
13
13
  if ((!deployList || deployList === 'dd') && fs.existsSync(`./engine-private/deploy/dd.router`))
14
14
  deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
15
15
 
@@ -25,7 +25,7 @@ class BackUp {
25
25
  const deployId = _deployId.trim();
26
26
  if (!deployId) continue;
27
27
 
28
- if (options.disableKindCluster !== true) {
28
+ if (!(options.itc === true)) {
29
29
  shellExec(`underpost db --export ${deployId}`);
30
30
  continue;
31
31
  }
@@ -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();
@@ -1004,7 +995,7 @@ const Cmd = {
1004
995
  syncPorts: (deployGroupId) => `node bin/deploy sync-env-port ${deployGroupId}`,
1005
996
  cron: (deployList, jobList, name, expression, options) =>
1006
997
  `pm2 start ./bin/index.js --no-autorestart --instances 1 --cron "${expression}" --name ${name} -- cron ${
1007
- options?.disableKindCluster ? `--disable-kind-cluster ` : ''
998
+ options?.itc ? `--itc ` : ''
1008
999
  }${deployList} ${jobList}`,
1009
1000
  };
1010
1001
 
@@ -1082,6 +1073,8 @@ const getNpmRootPath = () =>
1082
1073
  silent: true,
1083
1074
  }).trim();
1084
1075
 
1076
+ const getUnderpostRootPath = () => `${getNpmRootPath()}/underpost`;
1077
+
1085
1078
  const writeEnv = (envPath, envObj) =>
1086
1079
  fs.writeFileSync(
1087
1080
  envPath,
@@ -1127,5 +1120,6 @@ export {
1127
1120
  buildPortProxyRouter,
1128
1121
  splitFileFactory,
1129
1122
  getNpmRootPath,
1123
+ getUnderpostRootPath,
1130
1124
  writeEnv,
1131
1125
  };
package/src/server/dns.js CHANGED
@@ -1,17 +1,10 @@
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 { shellExec } from './process.js';
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
 
@@ -30,47 +23,47 @@ class Dns {
30
23
  // Forward the router's TCP/UDP ports to the LAN device's IP address
31
24
  for (const _deployId of deployList.split(',')) {
32
25
  const deployId = _deployId.trim();
33
- const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
34
- const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
35
- const confCronData = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
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'));
36
29
 
37
- let testIp;
30
+ let testIp;
38
31
 
39
- try {
40
- testIp = await ip.public.ipv4();
41
- } catch (error) {
42
- logger.error(error, { testIp, stack: error.stack });
43
- }
44
- const ipFileName = `${deployId}.ip`;
45
- const currentIp = fs.existsSync(`./engine-private/deploy/${ipFileName}`)
46
- ? fs.readFileSync(`./engine-private/deploy/${ipFileName}`, 'utf8')
47
- : undefined;
32
+ try {
33
+ testIp = await ip.public.ipv4();
34
+ } catch (error) {
35
+ logger.error(error, { testIp, stack: error.stack });
36
+ }
37
+
38
+ const currentIp = UnderpostRootEnv.API.get('ip');
48
39
 
49
- if (testIp && typeof testIp === 'string' && validator.isIP(testIp) && currentIp !== testIp) {
50
- logger.info(`new ip`, testIp);
51
- for (const recordType of Object.keys(confCronData.records)) {
52
- switch (recordType) {
53
- case 'A':
54
- for (const dnsProvider of confCronData.records[recordType]) {
55
- if (typeof Dns.services.updateIp[dnsProvider.dns] === 'function')
56
- await Dns.services.updateIp[dnsProvider.dns]({ ...dnsProvider, ip: testIp });
57
- }
58
- break;
40
+ if (testIp && typeof testIp === 'string' && validator.isIP(testIp) && currentIp !== testIp) {
41
+ logger.info(`new ip`, testIp);
42
+ for (const recordType of Object.keys(confCronData.records)) {
43
+ switch (recordType) {
44
+ case 'A':
45
+ for (const dnsProvider of confCronData.records[recordType]) {
46
+ if (typeof Dns.services.updateIp[dnsProvider.dns] === 'function')
47
+ await Dns.services.updateIp[dnsProvider.dns]({ ...dnsProvider, ip: testIp });
48
+ }
49
+ break;
59
50
 
60
- default:
61
- break;
51
+ default:
52
+ break;
53
+ }
62
54
  }
63
- }
64
- try {
65
- const ipUrlTest = `https://${process.env.DEFAULT_DEPLOY_HOST}`;
66
- const response = await axios.get(ipUrlTest);
67
- const verifyIp = response.request.socket.remoteAddress;
68
- logger.info(ipUrlTest + ' IP', verifyIp);
69
- if (verifyIp === testIp) {
70
- fs.writeFileSync(`./engine-private/deploy/${ipFileName}`, testIp, 'utf8');
71
- } else logger.error('ip not updated');
72
- } catch (error) {
73
- logger.error(error), 'ip not updated';
55
+ try {
56
+ const ipUrlTest = `https://${process.env.DEFAULT_DEPLOY_HOST}`;
57
+ const response = await axios.get(ipUrlTest);
58
+ const verifyIp = response.request.socket.remoteAddress;
59
+ logger.info(ipUrlTest + ' verify ip', verifyIp);
60
+ if (verifyIp === testIp) {
61
+ logger.info('ip updated successfully', testIp);
62
+ UnderpostRootEnv.API.set('ip', testIp);
63
+ } else logger.error('ip not updated', testIp);
64
+ } catch (error) {
65
+ logger.error(error, error.stack);
66
+ logger.error('ip not updated', testIp);
74
67
  }
75
68
  }
76
69
  }
@@ -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,10 +0,0 @@
1
- apiVersion: v1
2
- kind: Service
3
- metadata:
4
- name: mongodb-service
5
- spec:
6
- clusterIP: None
7
- selector:
8
- app: mongodb
9
- ports:
10
- - port: 27017
@@ -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