underpost 2.8.47 → 2.8.51

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
@@ -1,12 +1,194 @@
1
+ import {
2
+ buildKindPorts,
3
+ buildPortProxyRouter,
4
+ buildProxyRouter,
5
+ Config,
6
+ getDataDeploy,
7
+ loadReplicas,
8
+ } from '../server/conf.js';
1
9
  import { loggerFactory } from '../server/logger.js';
2
10
  import { shellExec } from '../server/process.js';
3
11
  import fs from 'fs-extra';
12
+ import dotenv from 'dotenv';
13
+ import Underpost from '../index.js';
4
14
 
5
15
  const logger = loggerFactory(import.meta);
6
16
 
7
17
  class UnderpostDeploy {
8
18
  static API = {
9
- callback: (deployList = 'default', env = 'development', options = { remove: false }) => {
19
+ sync(deployList) {
20
+ const deployGroupId = 'dd.tmp';
21
+ fs.writeFileSync(`./engine-private/deploy/${deployGroupId}`, deployList, 'utf8');
22
+ return getDataDeploy({
23
+ buildSingleReplica: true,
24
+ deployGroupId,
25
+ });
26
+ },
27
+ async routerFactory(deployList, env) {
28
+ const initEnvPath = `./engine-private/conf/${deployList.split(',')[0]}/.env.${env}`;
29
+ const initEnvObj = dotenv.parse(fs.readFileSync(initEnvPath, 'utf8'));
30
+ process.env.PORT = initEnvObj.PORT;
31
+ process.env.NODE_ENV = env;
32
+ await Config.build(undefined, 'proxy', deployList);
33
+ return buildPortProxyRouter(env === 'development' ? 80 : 443, buildProxyRouter());
34
+ },
35
+ async buildManifest(deployList, env) {
36
+ for (const _deployId of deployList.split(',')) {
37
+ const deployId = _deployId.trim();
38
+ if (!deployId) continue;
39
+
40
+ const router = await UnderpostDeploy.API.routerFactory(deployId, env);
41
+ const ports = Object.values(router).map((p) => parseInt(p.split(':')[2]));
42
+ const fromPort = Math.min(...ports);
43
+ const toPort = Math.max(...ports);
44
+ const confServer = loadReplicas(
45
+ JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8')),
46
+ 'proxy',
47
+ );
48
+
49
+ fs.mkdirSync(`./engine-private/conf/${deployId}/build/${env}`, { recursive: true });
50
+ if (env === 'development') fs.mkdirSync(`./manifests/deployment/${deployId}-${env}`, { recursive: true });
51
+
52
+ logger.info('port range', { deployId, fromPort, toPort });
53
+
54
+ const deploymentYamlParts = `apiVersion: apps/v1
55
+ kind: Deployment
56
+ metadata:
57
+ name: ${deployId}-${env}
58
+ labels:
59
+ app: ${deployId}-${env}
60
+ spec:
61
+ replicas: 2
62
+ selector:
63
+ matchLabels:
64
+ app: ${deployId}-${env}
65
+ template:
66
+ metadata:
67
+ labels:
68
+ app: ${deployId}-${env}
69
+ spec:
70
+ containers:
71
+ - name: ${deployId}-${env}
72
+ image: localhost/${deployId}-${env}:${Underpost.version}
73
+ ---
74
+ apiVersion: v1
75
+ kind: Service
76
+ metadata:
77
+ name: ${deployId}-${env}-service
78
+ spec:
79
+ selector:
80
+ app: ${deployId}-${env}
81
+ ports:
82
+ type: LoadBalancer`.split('ports:');
83
+ deploymentYamlParts[1] =
84
+ buildKindPorts(fromPort, toPort) +
85
+ ` type: LoadBalancer
86
+ `;
87
+
88
+ fs.writeFileSync(
89
+ `./engine-private/conf/${deployId}/build/${env}/deployment.yaml`,
90
+ deploymentYamlParts.join(`ports:
91
+ `),
92
+ );
93
+
94
+ let proxyYaml = '';
95
+ let secretYaml = '';
96
+
97
+ for (const host of Object.keys(confServer)) {
98
+ if (env === 'production')
99
+ secretYaml += `
100
+ ---
101
+ apiVersion: cert-manager.io/v1
102
+ kind: Certificate
103
+ metadata:
104
+ name: ${host}
105
+ spec:
106
+ commonName: ${host}
107
+ dnsNames:
108
+ - ${host}
109
+ issuerRef:
110
+ name: letsencrypt-prod
111
+ kind: ClusterIssuer
112
+ secretName: ${host}`;
113
+
114
+ const pathPortConditions = [];
115
+ for (const path of Object.keys(confServer[host])) {
116
+ const { peer } = confServer[host][path];
117
+ if (!router[`${host}${path === '/' ? '' : path}`]) continue;
118
+ const port = parseInt(router[`${host}${path === '/' ? '' : path}`].split(':')[2]);
119
+ // logger.info('', { host, port, path });
120
+ pathPortConditions.push({
121
+ port,
122
+ path,
123
+ });
124
+
125
+ if (peer) {
126
+ // logger.info('', { host, port: port + 1, path: '/peer' });
127
+ pathPortConditions.push({
128
+ port: port + 1,
129
+ path: '/peer',
130
+ });
131
+ }
132
+ }
133
+
134
+ // logger.info('', { host, pathPortConditions });
135
+ proxyYaml += `
136
+ ---
137
+ apiVersion: projectcontour.io/v1
138
+ kind: HTTPProxy
139
+ metadata:
140
+ name: ${host}
141
+ spec:
142
+ virtualhost:
143
+ fqdn: ${host}${
144
+ env === 'development'
145
+ ? ''
146
+ : `
147
+ tls:
148
+ secretName: ${host}`
149
+ }
150
+ routes:`;
151
+ for (const conditionObj of pathPortConditions) {
152
+ const { path, port } = conditionObj;
153
+ proxyYaml += `
154
+ - conditions:
155
+ - prefix: ${path}
156
+ enableWebsockets: true
157
+ services:
158
+ - name: ${deployId}-${env}-service
159
+ port: ${port}`;
160
+ }
161
+ }
162
+ const yamlPath = `./engine-private/conf/${deployId}/build/${env}/proxy.yaml`;
163
+ fs.writeFileSync(yamlPath, proxyYaml, 'utf8');
164
+ if (env === 'production') {
165
+ const yamlPath = `./engine-private/conf/${deployId}/build/${env}/secret.yaml`;
166
+ fs.writeFileSync(yamlPath, secretYaml, 'utf8');
167
+ } else {
168
+ const deploymentsFiles = ['Dockerfile', 'proxy.yaml', 'deployment.yaml'];
169
+ for (const file of deploymentsFiles) {
170
+ if (fs.existsSync(`./engine-private/conf/${deployId}/build/${env}/${file}`)) {
171
+ fs.copyFileSync(
172
+ `./engine-private/conf/${deployId}/build/${env}/${file}`,
173
+ `./manifests/deployment/${deployId}-${env}/${file}`,
174
+ );
175
+ }
176
+ }
177
+ }
178
+ }
179
+ },
180
+ async callback(
181
+ deployList = 'default',
182
+ env = 'development',
183
+ options = { remove: false, infoRouter: false, sync: false, buildManifest: false },
184
+ ) {
185
+ if (deployList === 'dd' && fs.existsSync(`./engine-private/deploy/dd.router`))
186
+ deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
187
+ if (options.sync) UnderpostDeploy.API.sync(deployList);
188
+ if (options.buildManifest === true) await UnderpostDeploy.API.buildManifest(deployList, env);
189
+ if (options.infoRouter === true)
190
+ return logger.info('router', await UnderpostDeploy.API.routerFactory(deployList, env));
191
+
10
192
  for (const _deployId of deployList.split(',')) {
11
193
  const deployId = _deployId.trim();
12
194
  if (!deployId) continue;
package/src/cli/image.js CHANGED
@@ -3,6 +3,7 @@ import Underpost from '../index.js';
3
3
  import { shellExec } from '../server/process.js';
4
4
  import dotenv from 'dotenv';
5
5
  import { getNpmRootPath } from '../server/conf.js';
6
+ import { timer } from '../client/components/core/CommonJs.js';
6
7
 
7
8
  dotenv.config();
8
9
 
@@ -12,7 +13,7 @@ class UnderpostImage {
12
13
  pullBaseImages() {
13
14
  shellExec(`sudo podman pull docker.io/library/debian:buster`);
14
15
  },
15
- build(deployId = 'default', env = 'development', path = '.', imageArchive = false) {
16
+ build(deployId = 'default', env = 'development', path = '.', options = { imageArchive: false }) {
16
17
  const imgName = `${deployId}-${env}:${Underpost.version}`;
17
18
  const podManImg = `localhost/${imgName}`;
18
19
  const imagesStoragePath = `./images`;
@@ -29,7 +30,7 @@ class UnderpostImage {
29
30
  secretDockerInput += ` --secret id=${key},env=${key} \ `;
30
31
  }
31
32
  // --rm --no-cache
32
- if (imageArchive !== true) {
33
+ if (options.imageArchive !== true) {
33
34
  fs.copyFile(`${getNpmRootPath()}/underpost/.env`, `${path}/.env.underpost`);
34
35
  shellExec(
35
36
  `cd ${path}${secrets}&& sudo podman build -f ./Dockerfile -t ${imgName} --pull=never --cap-add=CAP_AUDIT_WRITE${secretDockerInput}`,
@@ -39,7 +40,7 @@ class UnderpostImage {
39
40
  }
40
41
  shellExec(`cd ${path} && sudo kind load image-archive ${tarFile}`);
41
42
  },
42
- async script(deployId = 'default', env = 'development') {
43
+ async script(deployId = 'default', env = 'development', options = { run: false }) {
43
44
  switch (deployId) {
44
45
  case 'dd-lampp':
45
46
  {
@@ -99,6 +100,24 @@ class UnderpostImage {
99
100
  }
100
101
  shellExec(`node bin/deploy conf ${deployId} ${env}`);
101
102
  shellExec(`node bin/deploy build-full-client ${deployId}`);
103
+ if (options.run === true) {
104
+ const runCmd = env === 'production' ? 'prod-img' : 'dev-img';
105
+ if (fs.existsSync(`./engine-private/replica`)) {
106
+ const replicas = await fs.readdir(`./engine-private/replica`);
107
+ for (const replica of replicas) {
108
+ shellExec(`node bin/deploy conf ${replica} ${env}`);
109
+ shellExec(`npm run ${runCmd} ${replica} deploy`, { async: true });
110
+ fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
111
+ const monitor = async () => {
112
+ await timer(1000);
113
+ if (fs.existsSync(`./tmp/await-deploy`)) return await monitor();
114
+ };
115
+ await monitor();
116
+ }
117
+ shellExec(`node bin/deploy conf ${deployId} ${env}`);
118
+ }
119
+ shellExec(`npm run ${runCmd} ${deployId} deploy`);
120
+ }
102
121
  },
103
122
  },
104
123
  };
@@ -4,6 +4,7 @@ import { pbcopy, shellExec } from '../server/process.js';
4
4
  import { actionInitLog, loggerFactory } from '../server/logger.js';
5
5
  import fs from 'fs-extra';
6
6
  import { getNpmRootPath } from '../server/conf.js';
7
+ import { listenPortController, listenServerFactory } from '../server/network.js';
7
8
 
8
9
  dotenv.config();
9
10
 
@@ -14,7 +15,7 @@ class UnderpostRepository {
14
15
  clone(gitUri = 'underpostnet/pwa-microservices-template', options = { bare: false }) {
15
16
  const repoName = gitUri.split('/').pop();
16
17
  if (fs.existsSync(`./${repoName}`)) fs.removeSync(`./${repoName}`);
17
- return shellExec(
18
+ shellExec(
18
19
  `git clone ${options?.bare === true ? ` --bare ` : ''}https://${
19
20
  process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''
20
21
  }github.com/${gitUri}.git`,
@@ -22,16 +23,6 @@ class UnderpostRepository {
22
23
  disableLog: true,
23
24
  },
24
25
  );
25
- if (process.env.GITHUB_TOKEN) {
26
- shellExec(
27
- `git clone https://${
28
- process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''
29
- }github.com/${gitUri}-private.git`,
30
- );
31
- fs.moveSync(`./${repoName}-private`, `./${repoName}/engine-private`, {
32
- overwrite: true,
33
- });
34
- }
35
26
  },
36
27
  pull(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') {
37
28
  shellExec(
@@ -86,9 +77,10 @@ class UnderpostRepository {
86
77
  new(repositoryName) {
87
78
  return new Promise(async (resolve, reject) => {
88
79
  try {
89
- const exeRootPath = `${getNpmRootPath()}/underpost`;
90
- actionInitLog();
91
80
  await logger.setUpInfo();
81
+ if (repositoryName === 'service') return resolve(await listenPortController(listenServerFactory(), ':'));
82
+ else actionInitLog();
83
+ const exeRootPath = `${getNpmRootPath()}/underpost`;
92
84
  const destFolder = `./${repositoryName}`;
93
85
  logger.info('Note: This process may take several minutes to complete');
94
86
  logger.info('build app', { destFolder });
package/src/cli/test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MariaDB } from '../db/mariadb/MariaDB.js';
2
2
  import { getNpmRootPath } from '../server/conf.js';
3
- import { actionInitLog, loggerFactory } from '../server/logger.js';
3
+ import { actionInitLog, loggerFactory, setUpInfo } from '../server/logger.js';
4
4
  import { pbcopy, shellExec } from '../server/process.js';
5
5
  import UnderpostDeploy from './deploy.js';
6
6
 
@@ -28,10 +28,13 @@ class UnderpostTest {
28
28
  actionInitLog();
29
29
  shellExec(`cd ${getNpmRootPath()}/underpost && npm run test`);
30
30
  },
31
- async callback(deployList = '', options = { insideContainer: false, sh: false }) {
32
- if (options.sh === true) {
31
+ async callback(deployList = '', options = { insideContainer: false, sh: false, logs: false }) {
32
+ if (options.sh === true || options.logs === true) {
33
33
  const [pod] = UnderpostDeploy.API.getPods(deployList);
34
- if (pod) return pbcopy(`sudo kubectl exec -it ${pod.NAME} -- sh`);
34
+ if (pod) {
35
+ if (options.sh) return pbcopy(`sudo kubectl exec -it ${pod.NAME} -- sh`);
36
+ if (options.logs) return shellExec(`sudo kubectl logs -f ${pod.NAME}`);
37
+ }
35
38
  return logger.warn(`Couldn't find pods in deployment`, deployList);
36
39
  }
37
40
  if (deployList) {
@@ -573,6 +573,14 @@ const isValidFormat = (value, format) => {
573
573
  }
574
574
  };
575
575
 
576
+ const getCurrentTrace = () => {
577
+ try {
578
+ _stack;
579
+ } catch (error) {
580
+ return error.stack.split('is not defined')[1];
581
+ }
582
+ };
583
+
576
584
  /**
577
585
  * Returns the time difference between UTC time and local time, in minutes.
578
586
  * @memberof CommonJS
@@ -943,6 +951,7 @@ export {
943
951
  commonAdminGuard,
944
952
  commonModeratorGuard,
945
953
  isChileanIdentityDocument,
954
+ getCurrentTrace,
946
955
  userRoleEnum,
947
956
  commitData,
948
957
  };
@@ -761,6 +761,7 @@ const renderWave = ({ id }) => {
761
761
  const cssTokensEffect = {};
762
762
  const cssTokensContainer = {};
763
763
  const cssEffect = async (containerSelector, event) => {
764
+ return;
764
765
  // Array.from(event.target.classList)
765
766
  let offsetX, offsetY;
766
767
  if (Array.from(event.srcElement.classList).includes('ripple') && cssTokensContainer[containerSelector]) {
@@ -9,7 +9,6 @@ import {
9
9
  htmls,
10
10
  sa,
11
11
  getAllChildNodes,
12
- getCurrentTrace,
13
12
  isActiveElement,
14
13
  } from './VanillaJs.js';
15
14
  import { BtnIcon } from './BtnIcon.js';
@@ -419,14 +419,6 @@ const isActiveTab = () => document.hasFocus();
419
419
  const isActiveElement = (classSearch = '') =>
420
420
  document.activeElement?.classList?.value?.match(classSearch) ? true : false;
421
421
 
422
- const getCurrentTrace = () => {
423
- try {
424
- _stack;
425
- } catch (error) {
426
- return error.stack.split('is not defined')[1];
427
- }
428
- };
429
-
430
422
  const isDevInstance = () => location.origin.match('localhost') && location.port;
431
423
 
432
424
  const getDataFromInputFile = async (file) => Array.from(new Uint8Array(await file.arrayBuffer()));
@@ -460,7 +452,6 @@ export {
460
452
  isNavigator,
461
453
  getTimeZone,
462
454
  getAllChildNodes,
463
- getCurrentTrace,
464
455
  isActiveTab,
465
456
  isActiveElement,
466
457
  isDevInstance,
@@ -22,41 +22,44 @@ const Worker = {
22
22
  setTimeout(() => {
23
23
  if ('onLine' in navigator && navigator.onLine) window.ononline();
24
24
  });
25
- navigator.serviceWorker.addEventListener('controllerchange', () => {
26
- logger.info('The controller of current browsing context has changed.');
27
- });
28
- navigator.serviceWorker.ready.then((worker) => {
29
- logger.info('Ready', worker);
30
- // event message
31
- navigator.serviceWorker.addEventListener('message', (event) => {
32
- logger.info('Received event message', event.data);
33
- const { status } = event.data;
25
+ if ('serviceWorker' in navigator) {
26
+ navigator.serviceWorker.addEventListener('controllerchange', () => {
27
+ logger.info('The controller of current browsing context has changed.');
28
+ });
29
+ navigator.serviceWorker.ready.then((worker) => {
30
+ logger.info('Ready', worker);
31
+ // event message
32
+ navigator.serviceWorker.addEventListener('message', (event) => {
33
+ logger.info('Received event message', event.data);
34
+ const { status } = event.data;
34
35
 
35
- switch (status) {
36
- case 'loader':
37
- {
38
- LoadingAnimation.RenderCurrentSrcLoad(event);
39
- }
40
- break;
36
+ switch (status) {
37
+ case 'loader':
38
+ {
39
+ LoadingAnimation.RenderCurrentSrcLoad(event);
40
+ }
41
+ break;
41
42
 
42
- default:
43
- break;
44
- }
45
- });
43
+ default:
44
+ break;
45
+ }
46
+ });
46
47
 
47
- // if (navigator.serviceWorker.controller)
48
- // navigator.serviceWorker.controller.postMessage({
49
- // title: 'Hello from Client event message',
50
- // });
48
+ // if (navigator.serviceWorker.controller)
49
+ // navigator.serviceWorker.controller.postMessage({
50
+ // title: 'Hello from Client event message',
51
+ // });
52
+
53
+ // broadcast message
54
+ // const channel = new BroadcastChannel('sw-messages');
55
+ // channel.addEventListener('message', (event) => {
56
+ // logger.info('Received broadcast message', event.data);
57
+ // });
58
+ // channel.postMessage({ title: 'Hello from Client broadcast message' });
59
+ // channel.close();
60
+ });
61
+ }
51
62
 
52
- // broadcast message
53
- // const channel = new BroadcastChannel('sw-messages');
54
- // channel.addEventListener('message', (event) => {
55
- // logger.info('Received broadcast message', event.data);
56
- // });
57
- // channel.postMessage({ title: 'Hello from Client broadcast message' });
58
- // channel.close();
59
- });
60
63
  this.RouterInstance = router();
61
64
  const isInstall = await this.status();
62
65
  if (!isInstall) await this.install();
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.47';
30
+ static version = 'v2.8.51';
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;
@@ -1,120 +1,76 @@
1
1
  import fs from 'fs-extra';
2
2
  import { loggerFactory } from './logger.js';
3
- import { shellCd, shellExec } from './process.js';
4
- import { getCronBackUpFolder, getDataDeploy } from './conf.js';
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
- const BackUpManagement = {
12
- repoUrl: `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${process.env.GITHUB_BACKUP_REPO}.git`,
13
- Init: async function ({ deployId }) {
14
- const Callback = async function () {
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
- const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
16
+ logger.info('init backups callback', deployList);
17
+ await logger.setUpInfo();
18
+ const currentDate = new Date().getTime();
19
+ const maxBackupRetention = 5;
18
20
 
19
- const { backups } = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
21
+ if (!fs.existsSync('./engine-private/cron-backups'))
22
+ fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
20
23
 
21
- if (!backups) return;
24
+ for (const _deployId of deployList.split(',')) {
25
+ const deployId = _deployId.trim();
26
+ if (!deployId) continue;
22
27
 
23
- logger.info('init backups callback');
24
- await logger.setUpInfo();
25
-
26
- const currentDate = new Date().getTime();
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
- switch (backupFrequency) {
68
- case 'daily':
33
+ const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
69
34
 
70
- default:
71
- // if (currentBackupsDirs[0] && currentDate - currentBackupsDirs[0] < 1000 * 60 * 60 * 24) continue;
72
- break;
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
- for (const retentionPath of currentBackupsDirs.filter((t, i) => i >= maxBackupRetention - 1)) {
76
- const removePathRetention = `${backUpPath}/${retentionPath}`;
77
- logger.info('Remove backup folder', removePathRetention);
78
- fs.removeSync(removePathRetention);
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
- fs.mkdirSync(`${backUpPath}/${currentDate}`, { recursive: true });
47
+ const currentBackupsDirs = files
48
+ .map((fileObj) => parseInt(fileObj.name))
49
+ .sort((a, b) => a - b)
50
+ .reverse();
82
51
 
83
- shellExec(`node bin/db ${host}${path} export ${deployId} ${backUpPath}/${currentDate}`);
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
- if (wp) {
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
- shellExec(
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
- ` && git pull ${BackUpManagement.repoUrl}` +
106
- ` && git add . && git commit -m "backup ${new Date().toLocaleDateString()}"` +
107
- ` && git push ${BackUpManagement.repoUrl}`,
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
- await Callback();
114
- BackUpManagement.Callback = Callback;
115
- return Callback;
116
- },
117
- Callback: async function (params) {},
118
- };
72
+ }
73
+ };
74
+ }
119
75
 
120
- export { BackUpManagement };
76
+ export default BackUp;