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.
@@ -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
- 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
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.482';
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;
@@ -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;
@@ -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 = { buildSingleReplica: false, deployGroupId: '', deployId: '', disableSyncEnvPort: false },
592
+ options = {
593
+ buildSingleReplica: false,
594
+ deployGroupId: '',
595
+ deployId: '',
596
+ disableSyncEnvPort: false,
597
+ deployIdConcat: [],
598
+ },
594
599
  ) => {
595
- let dataDeploy = JSON.parse(fs.readFileSync(`./engine-private/deploy/${options.deployGroupId}.json`, 'utf8'));
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
- if (process.argv.includes('manual')) await read({ prompt: 'Press enter to retry failed processes\n' });
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: (deployId) => `node bin/deploy run ${deployId}`,
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: (deployId, job, expression) => {
982
- shellExec(Cmd.delete(`${deployId}-${job}`));
983
- return `env-cmd -f .env.production pm2 start bin/cron.js --no-autorestart --instances 1 --cron "${expression}" --name ${deployId}-${job} -- ${job} ${deployId}`;
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(`node bin/deploy run ${proxyDeployId} maintenance`);
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 { 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
 
18
11
  const logger = loggerFactory(import.meta);
19
12
 
20
- const Dns = {
21
- repoUrl: `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${process.env.GITHUB_DNS_REPO}.git`,
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
- if (testIp && typeof testIp === 'string' && validator.isIP(testIp) && Dns.ip !== testIp) {
51
- logger.info(`New ip`, testIp);
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 + ' IP', verifyIp);
59
+ logger.info(ipUrlTest + ' verify ip', verifyIp);
70
60
  if (verifyIp === testIp) {
71
- await this.saveIp(confCronPath, confCronData, testIp);
72
- } else logger.error('ip not updated');
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), 'ip not updated';
65
+ logger.error(error, error.stack);
66
+ logger.error('ip not updated', testIp);
75
67
  }
76
68
  }
77
- };
78
- await callback();
79
- this.callback = callback;
80
- return callback;
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
- saveIp: async (confCronPath, confCronData, ip) => {
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 { Dns };
96
+ export default Dns;
@@ -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
@@ -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