@underpostnet/underpost 2.8.4 → 2.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ghpkg.yml +13 -46
- package/.github/workflows/npmpkg.yml +67 -0
- package/.github/workflows/publish.yml +5 -5
- package/.github/workflows/pwa-microservices-template.page.yml +3 -2
- package/.github/workflows/pwa-microservices-template.test.yml +2 -2
- package/.vscode/settings.json +6 -1
- package/CHANGELOG.md +16 -0
- package/Dockerfile +6 -27
- package/bin/build.js +52 -169
- package/bin/deploy.js +6 -27
- package/bin/file.js +29 -15
- package/bin/index.js +158 -30
- package/bin/util.js +0 -8
- package/docker-compose.yml +1 -1
- package/manifests/mongodb/backup-access.yaml +16 -0
- package/manifests/mongodb/backup-cronjob.yaml +42 -0
- package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
- package/manifests/mongodb/configmap.yaml +26 -0
- package/manifests/mongodb/headless-service.yaml +10 -0
- package/manifests/mongodb/kustomization.yaml +11 -0
- package/manifests/mongodb/pv-pvc.yaml +23 -0
- package/manifests/mongodb/statefulset.yaml +125 -0
- package/manifests/valkey/kustomization.yaml +2 -2
- package/manifests/valkey/service.yaml +17 -0
- package/manifests/valkey/statefulset.yaml +39 -0
- package/package.json +21 -5
- package/src/api/core/core.service.js +1 -1
- package/src/cli/cluster.js +154 -0
- package/src/cli/cron.js +90 -0
- package/src/cli/db.js +148 -0
- package/src/cli/deploy.js +277 -0
- package/src/cli/env.js +52 -0
- package/src/cli/image.js +125 -0
- package/src/cli/repository.js +104 -0
- package/src/cli/script.js +29 -0
- package/src/cli/secrets.js +37 -0
- package/src/cli/test.js +83 -0
- package/src/client/components/core/Auth.js +22 -4
- package/src/client/components/core/CommonJs.js +82 -1
- package/src/client/components/core/Css.js +1 -0
- package/src/client/components/core/Input.js +1 -1
- package/src/client/components/core/Modal.js +0 -1
- package/src/client/components/core/Scroll.js +1 -0
- package/src/client/components/core/Translate.js +4 -0
- package/src/client/components/core/VanillaJs.js +0 -9
- package/src/client/components/core/Worker.js +34 -31
- package/src/client/ssr/body/CacheControl.js +2 -2
- package/src/index.js +77 -26
- package/src/server/backup.js +49 -93
- package/src/server/client-build.js +1 -10
- package/src/server/client-formatted.js +5 -3
- package/src/server/conf.js +68 -187
- package/src/server/dns.js +48 -65
- package/src/server/logger.js +7 -7
- package/src/server/network.js +17 -7
- package/src/server/runtime.js +8 -22
- package/src/dns.js +0 -22
- package/src/server/project.js +0 -39
- package/startup.cjs +0 -12
- /package/manifests/deployment/{mongo-express.yaml → mongo-express/deployment.yaml} +0 -0
- /package/manifests/deployment/{phpmyadmin.yaml → phpmyadmin/deployment.yaml} +0 -0
package/bin/file.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
|
|
3
3
|
import { loggerFactory } from '../src/server/logger.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cap,
|
|
6
|
+
getCapVariableName,
|
|
7
|
+
getDirname,
|
|
8
|
+
newInstance,
|
|
9
|
+
uniqueArray,
|
|
10
|
+
} from '../src/client/components/core/CommonJs.js';
|
|
5
11
|
import { shellCd, shellExec } from '../src/server/process.js';
|
|
6
12
|
import walk from 'ignore-walk';
|
|
7
13
|
import { validateTemplatePath } from '../src/server/conf.js';
|
|
@@ -25,16 +31,8 @@ let name = getCapVariableName(file.split('.')[0]);
|
|
|
25
31
|
logger.info('File metadata', { path, file, ext, name });
|
|
26
32
|
|
|
27
33
|
try {
|
|
28
|
-
// throw '';
|
|
29
|
-
// let cmd;
|
|
30
34
|
let content = '';
|
|
31
35
|
switch (type) {
|
|
32
|
-
case 'create-js-module':
|
|
33
|
-
// node bin/file './src/client/components/core/progress bar.js'
|
|
34
|
-
content = `const ${name} = {}; export { ${name} }`;
|
|
35
|
-
setTimeout(() => shellExec(`prettier --write ${buildPath}`));
|
|
36
|
-
break;
|
|
37
|
-
|
|
38
36
|
case 'update-template':
|
|
39
37
|
case 'copy-src':
|
|
40
38
|
console.log({ rawPath, toPath });
|
|
@@ -77,10 +75,9 @@ try {
|
|
|
77
75
|
fs.copySync(`./.github`, `../pwa-microservices-template/.github`);
|
|
78
76
|
fs.copySync(`./src/client/public/default`, `../pwa-microservices-template/src/client/public/default`);
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
78
|
+
for (const checkoutPath of ['README.md', 'package-lock.json', 'package.json'])
|
|
79
|
+
shellExec(`cd ../pwa-microservices-template && git checkout ${checkoutPath}`);
|
|
80
|
+
|
|
84
81
|
for (const deletePath of [
|
|
85
82
|
'.github/workflows/coverall.yml',
|
|
86
83
|
'.github/workflows/docker-image.yml',
|
|
@@ -89,17 +86,34 @@ try {
|
|
|
89
86
|
'.github/workflows/engine.lampp.ci.yml',
|
|
90
87
|
'.github/workflows/engine.core.ci.yml',
|
|
91
88
|
'.github/workflows/engine.cyberia.ci.yml',
|
|
89
|
+
'./manifests/deployment/dd-lampp-development',
|
|
90
|
+
'./manifests/deployment/dd-cyberia-development',
|
|
91
|
+
'./manifests/deployment/dd-core-development',
|
|
92
92
|
'bin/web3.js',
|
|
93
93
|
'bin/cyberia.js',
|
|
94
94
|
]) {
|
|
95
|
-
fs.removeSync('../pwa-microservices-template/' + deletePath);
|
|
95
|
+
if (fs.existsSync(deletePath)) fs.removeSync('../pwa-microservices-template/' + deletePath);
|
|
96
96
|
}
|
|
97
|
-
shellCd('../engine');
|
|
98
97
|
const originPackageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
99
98
|
const templatePackageJson = JSON.parse(fs.readFileSync('../pwa-microservices-template/package.json', 'utf8'));
|
|
99
|
+
|
|
100
|
+
const name = templatePackageJson.name;
|
|
101
|
+
const description = templatePackageJson.description;
|
|
102
|
+
const dev = templatePackageJson.scripts.dev;
|
|
103
|
+
const build = templatePackageJson.scripts.build;
|
|
104
|
+
|
|
100
105
|
templatePackageJson.dependencies = originPackageJson.dependencies;
|
|
101
106
|
templatePackageJson.devDependencies = originPackageJson.devDependencies;
|
|
102
107
|
templatePackageJson.version = originPackageJson.version;
|
|
108
|
+
templatePackageJson.scripts = originPackageJson.scripts;
|
|
109
|
+
templatePackageJson.name = name;
|
|
110
|
+
templatePackageJson.description = description;
|
|
111
|
+
templatePackageJson.scripts.dev = dev;
|
|
112
|
+
templatePackageJson.scripts.build = build;
|
|
113
|
+
templatePackageJson.keywords = uniqueArray(
|
|
114
|
+
['pwa', 'microservices', 'template', 'builder'].concat(templatePackageJson.keywords),
|
|
115
|
+
);
|
|
116
|
+
delete templatePackageJson.scripts['update-template'];
|
|
103
117
|
fs.writeFileSync(
|
|
104
118
|
'../pwa-microservices-template/package.json',
|
|
105
119
|
JSON.stringify(templatePackageJson, null, 4),
|
package/bin/index.js
CHANGED
|
@@ -1,63 +1,191 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import dotenv from 'dotenv';
|
|
4
|
-
import { shellCd, shellExec } from '../src/server/process.js';
|
|
5
4
|
import { Command } from 'commander';
|
|
6
|
-
import {
|
|
5
|
+
import { loggerFactory } from '../src/server/logger.js';
|
|
7
6
|
import Underpost from '../src/index.js';
|
|
7
|
+
import { getNpmRootPath, loadConf } from '../src/server/conf.js';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import { commitData } from '../src/client/components/core/CommonJs.js';
|
|
10
|
+
import UnderpostScript from '../src/cli/script.js';
|
|
11
|
+
import UnderpostDB from '../src/cli/db.js';
|
|
12
|
+
import UnderpostCron from '../src/cli/cron.js';
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
const npmRoot = getNpmRootPath();
|
|
15
|
+
const underpostRoot = `${npmRoot}/underpost/.env`;
|
|
16
|
+
fs.existsSync(underpostRoot) ? dotenv.config({ path: underpostRoot, override: true }) : dotenv.config();
|
|
10
17
|
|
|
11
18
|
const logger = loggerFactory(import.meta);
|
|
12
19
|
|
|
13
20
|
const program = new Command();
|
|
14
21
|
|
|
15
|
-
program.name('underpost').description(`underpost
|
|
22
|
+
program.name('underpost').description(`underpost ci/cd cli ${Underpost.version}`).version(Underpost.version);
|
|
16
23
|
|
|
17
24
|
program
|
|
18
|
-
.command('new
|
|
25
|
+
.command('new')
|
|
26
|
+
.argument('<app-name>', 'Application name')
|
|
19
27
|
.description('Create a new project')
|
|
20
|
-
.action(
|
|
28
|
+
.action(Underpost.repo.new);
|
|
21
29
|
|
|
22
30
|
program
|
|
23
|
-
.command('clone
|
|
24
|
-
.
|
|
25
|
-
.
|
|
31
|
+
.command('clone')
|
|
32
|
+
.argument(`<uri>`, 'e.g. username/repository')
|
|
33
|
+
.option('--bare', 'Clone only .git files')
|
|
34
|
+
.description('Clone github repository')
|
|
35
|
+
.action(Underpost.repo.clone);
|
|
26
36
|
|
|
27
37
|
program
|
|
28
|
-
.command('pull
|
|
29
|
-
.
|
|
30
|
-
.
|
|
38
|
+
.command('pull')
|
|
39
|
+
.argument('<path>', 'Absolute or relative directory')
|
|
40
|
+
.argument(`<uri>`, 'e.g. username/repository')
|
|
41
|
+
.description('Pull github repository')
|
|
42
|
+
.action(Underpost.repo.pull);
|
|
31
43
|
|
|
32
44
|
program
|
|
33
|
-
.
|
|
34
|
-
.
|
|
35
|
-
.
|
|
36
|
-
.
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
.
|
|
45
|
+
.command('cmt')
|
|
46
|
+
.argument('<path>', 'Absolute or relative directory')
|
|
47
|
+
.argument(`<commit-type>`, `Options: ${Object.keys(commitData)}`)
|
|
48
|
+
.argument(`[module-tag]`, 'Optional set module tag')
|
|
49
|
+
.argument(`[message]`, 'Optional set additional message')
|
|
50
|
+
.option('--empty', 'Allow empty files')
|
|
51
|
+
.option('--copy', 'Copy to clipboard message')
|
|
52
|
+
.option('--info', 'Info commit types')
|
|
53
|
+
.description('Commit github repository')
|
|
54
|
+
.action(Underpost.repo.commit);
|
|
41
55
|
|
|
42
56
|
program
|
|
43
|
-
.command('push
|
|
44
|
-
.
|
|
45
|
-
.
|
|
57
|
+
.command('push')
|
|
58
|
+
.argument('<path>', 'Absolute or relative directory')
|
|
59
|
+
.argument(`<uri>`, 'e.g. username/repository')
|
|
60
|
+
.option('-f', 'Force push overwriting repository')
|
|
61
|
+
.description('Push github repository')
|
|
62
|
+
.action(Underpost.repo.push);
|
|
46
63
|
|
|
47
64
|
program
|
|
48
|
-
.command('env
|
|
65
|
+
.command('env')
|
|
66
|
+
.argument('<deploy-id>', `deploy configuration id, if 'clean' restore default`)
|
|
67
|
+
.argument('[env]', 'Optional environment, for default is production')
|
|
49
68
|
.description('Set environment variables files and conf related to <deploy-id>')
|
|
50
|
-
.action(
|
|
69
|
+
.action(loadConf);
|
|
70
|
+
|
|
71
|
+
program
|
|
72
|
+
.command('config')
|
|
73
|
+
.argument('operator', `Options: ${Object.keys(Underpost.env)}`)
|
|
74
|
+
.argument('[key]', 'Config key')
|
|
75
|
+
.argument('[value]', 'Config value')
|
|
76
|
+
.description(`Manage configuration, operators`)
|
|
77
|
+
.action((...args) => Underpost.env[args[0]](args[1], args[2]));
|
|
78
|
+
|
|
79
|
+
program
|
|
80
|
+
.command('root')
|
|
81
|
+
.description('Get npm root path')
|
|
82
|
+
.action(() => console.log(getNpmRootPath()));
|
|
83
|
+
|
|
84
|
+
program
|
|
85
|
+
.command('cluster')
|
|
86
|
+
.option('--reset', `Delete all clusters and prune all data and caches`)
|
|
87
|
+
.option('--mariadb', 'Init with mariadb statefulset')
|
|
88
|
+
.option('--mongodb', 'Init with mongodb statefulset')
|
|
89
|
+
.option('--valkey', 'Init with valkey service')
|
|
90
|
+
.option('--contour', 'Init with project contour base HTTPProxy and envoy')
|
|
91
|
+
.option('--info', 'Get all kinds objects deployed')
|
|
92
|
+
.option('--full', 'Init with all statefulsets and services available')
|
|
93
|
+
.option('--ns-use <ns-name>', 'Switches current context to namespace')
|
|
94
|
+
.action((...args) => {
|
|
95
|
+
if (args[0].reset) return Underpost.cluster.reset();
|
|
96
|
+
return Underpost.cluster.init(args[0]);
|
|
97
|
+
})
|
|
98
|
+
.description('Manage cluster, for default initialization base kind cluster');
|
|
99
|
+
|
|
100
|
+
program
|
|
101
|
+
.command('deploy')
|
|
102
|
+
.argument('<deploy-list>', 'Deploy id list, e.g. default-a,default-b')
|
|
103
|
+
.argument('[env]', 'Optional environment, for default is development')
|
|
104
|
+
.option('--remove', 'Delete deployments and services')
|
|
105
|
+
.option('--sync', 'Sync deployments env, ports, and replicas')
|
|
106
|
+
.option('--info-router', 'Display router structure')
|
|
107
|
+
.option('--build-manifest', 'Build kind yaml manifests: deployments, services, proxy and secrets')
|
|
108
|
+
.description('Manage deployment, for default deploy development pods')
|
|
109
|
+
.action(Underpost.deploy.callback);
|
|
51
110
|
|
|
52
|
-
program
|
|
111
|
+
program
|
|
112
|
+
.command('secret')
|
|
113
|
+
.argument('<platform>', `Options: ${Object.keys(Underpost.secret)}`)
|
|
114
|
+
.option('--init', 'Init secrets platform environment')
|
|
115
|
+
.option('--create-from-file <path-env-file>', 'Create secret from env file')
|
|
116
|
+
.option('--list', 'Lists secrets')
|
|
117
|
+
// .option('--delete [secret-key]', 'Delete key secret, if not set, are default delete all')
|
|
118
|
+
// .option('--create [secret-key] [secret-value]', 'Create secret key, with secret value')
|
|
119
|
+
.description(`Manage secrets`)
|
|
120
|
+
.action((...args) => {
|
|
121
|
+
if (args[1].createFromFile) return Underpost.secret[args[0]].createFromEnvFile(args[1].createFromFile);
|
|
122
|
+
if (args[1].list) return Underpost.secret[args[0]].list();
|
|
123
|
+
if (args[1].init) return Underpost.secret[args[0]].init();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
program
|
|
127
|
+
.command('dockerfile-node-script')
|
|
128
|
+
.argument('<deploy-id>', 'Deploy configuration id')
|
|
129
|
+
.argument('[env]', 'Optional environment, for default is development')
|
|
130
|
+
.option('--run', 'Run custom entry point script')
|
|
131
|
+
.description('Dockerfile custom node build script')
|
|
132
|
+
.action(Underpost.image.dockerfile.script);
|
|
53
133
|
|
|
54
134
|
program
|
|
55
|
-
.command('
|
|
56
|
-
.
|
|
135
|
+
.command('dockerfile-image-build')
|
|
136
|
+
.argument('<deploy-id>', 'Deploy configuration id')
|
|
137
|
+
.argument('[env]', 'Optional environment, for default is development')
|
|
138
|
+
.argument('[path]', 'Absolute or relative directory, for default is current')
|
|
139
|
+
.option('--image-archive', 'Only load tar image from /images')
|
|
140
|
+
.description('Build image from Dockerfile')
|
|
141
|
+
.action(Underpost.image.dockerfile.build);
|
|
142
|
+
|
|
143
|
+
program
|
|
144
|
+
.command('dockerfile-pull-base-images')
|
|
145
|
+
.description('Pull underpost dockerfile images requirements')
|
|
146
|
+
.action(Underpost.image.dockerfile.pullBaseImages);
|
|
147
|
+
|
|
148
|
+
program
|
|
149
|
+
.command('install')
|
|
150
|
+
.description('Fast import underpost npm dependencies')
|
|
57
151
|
.action(() => {
|
|
58
|
-
|
|
152
|
+
fs.copySync(`${npmRoot}/underpost/node_modules`, './node_modules');
|
|
59
153
|
});
|
|
60
154
|
|
|
61
|
-
|
|
155
|
+
program
|
|
156
|
+
.command('db')
|
|
157
|
+
.argument('<deploy-list>', 'Deploy id list, e.g. default-a,default-b')
|
|
158
|
+
.option('--import', 'Import container backups from repositories')
|
|
159
|
+
.option('--export', 'Export container backups to repositories')
|
|
160
|
+
.description('Manage databases')
|
|
161
|
+
.action(UnderpostDB.API.callback);
|
|
162
|
+
|
|
163
|
+
program
|
|
164
|
+
.command('script')
|
|
165
|
+
.argument('operator', `Options: ${Object.keys(UnderpostScript.API)}`)
|
|
166
|
+
.argument('<script-name>', 'Script name')
|
|
167
|
+
.argument('[script-value]', 'Literal command')
|
|
168
|
+
.description(
|
|
169
|
+
'Supports a number of built-in underpost global scripts and their preset life cycle events as well as arbitrary scripts',
|
|
170
|
+
)
|
|
171
|
+
.action((...args) => Underpost.script[args[0]](args[1], args[2]));
|
|
172
|
+
|
|
173
|
+
program
|
|
174
|
+
.command('cron')
|
|
175
|
+
.argument('[deploy-list]', 'Deploy id list, e.g. default-a,default-b')
|
|
176
|
+
.argument('[job-list]', `Deploy id list, e.g. ${Object.keys(UnderpostCron.JOB)}, for default all available jobs`)
|
|
177
|
+
.option('--disable-kind-cluster', 'Disable kind cluster configuration')
|
|
178
|
+
.option('--init', 'Init cron jobs for cron job default deploy id')
|
|
179
|
+
.description('Cron jobs management')
|
|
180
|
+
.action(Underpost.cron.callback);
|
|
181
|
+
|
|
182
|
+
program
|
|
183
|
+
.command('test')
|
|
184
|
+
.argument('[deploy-list]', 'Deploy id list, e.g. default-a,default-b')
|
|
185
|
+
.description('Manage Test, for default run current underpost default test')
|
|
186
|
+
.option('--inside-container', 'Inside container execution context')
|
|
187
|
+
.option('--sh', 'Copy to clipboard, container entrypoint shell command')
|
|
188
|
+
.option('--logs', 'Display container logs')
|
|
189
|
+
.action(Underpost.test.callback);
|
|
62
190
|
|
|
63
191
|
program.parse();
|
package/bin/util.js
CHANGED
|
@@ -112,14 +112,6 @@ try {
|
|
|
112
112
|
fs.writeFileSync('b64-image', `data:image/jpg;base64,${fs.readFileSync(process.argv[3]).toString('base64')}`);
|
|
113
113
|
break;
|
|
114
114
|
|
|
115
|
-
case 'clean-env': {
|
|
116
|
-
shellExec(`git checkout package.json`);
|
|
117
|
-
shellExec(`git checkout .env.production`);
|
|
118
|
-
shellExec(`git checkout .env.development`);
|
|
119
|
-
shellExec(`git checkout .env.test`);
|
|
120
|
-
shellExec(`git checkout jsdoc.json`);
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
115
|
case 'get-keys': {
|
|
124
116
|
const sentence = fs.existsSync('./_')
|
|
125
117
|
? fs.readFileSync('./_', 'utf8')
|
package/docker-compose.yml
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1,42 @@
|
|
|
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 --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
|
+
restartPolicy: Never
|
|
26
|
+
volumes:
|
|
27
|
+
- name: backup-storage
|
|
28
|
+
persistentVolumeClaim:
|
|
29
|
+
claimName: backup-pvc
|
|
30
|
+
# 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)
|
|
31
|
+
|
|
32
|
+
# env:
|
|
33
|
+
# - name: MONGO_INITDB_ROOT_USERNAME
|
|
34
|
+
# valueFrom:
|
|
35
|
+
# secretKeyRef:
|
|
36
|
+
# name: mongodb-secret
|
|
37
|
+
# key: username
|
|
38
|
+
# - name: MONGO_INITDB_ROOT_PASSWORD
|
|
39
|
+
# valueFrom:
|
|
40
|
+
# secretKeyRef:
|
|
41
|
+
# name: mongodb-secret
|
|
42
|
+
# key: password
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
apiVersion: apps/v1
|
|
2
|
+
kind: StatefulSet
|
|
3
|
+
metadata:
|
|
4
|
+
name: mongodb # Specifies the name of the statefulset
|
|
5
|
+
spec:
|
|
6
|
+
serviceName: 'mongodb-service' # Specifies the service to use
|
|
7
|
+
replicas: 2
|
|
8
|
+
selector:
|
|
9
|
+
matchLabels:
|
|
10
|
+
app: mongodb
|
|
11
|
+
template:
|
|
12
|
+
metadata:
|
|
13
|
+
labels:
|
|
14
|
+
app: mongodb
|
|
15
|
+
spec:
|
|
16
|
+
containers:
|
|
17
|
+
- name: mongodb
|
|
18
|
+
image: docker.io/library/mongo:latest
|
|
19
|
+
command:
|
|
20
|
+
- mongod
|
|
21
|
+
- '--replSet'
|
|
22
|
+
- 'rs0'
|
|
23
|
+
# - '--config'
|
|
24
|
+
# - '-f'
|
|
25
|
+
# - '/etc/mongod.conf'
|
|
26
|
+
# - '--auth'
|
|
27
|
+
# - '--clusterAuthMode'
|
|
28
|
+
# - 'keyFile'
|
|
29
|
+
# - '--keyFile'
|
|
30
|
+
# - '/etc/mongodb-keyfile'
|
|
31
|
+
# - '--interleave'
|
|
32
|
+
# - 'all'
|
|
33
|
+
# - '--wiredTigerCacheSizeGB'
|
|
34
|
+
# - '0.25'
|
|
35
|
+
# - '--setParameter'
|
|
36
|
+
# - 'authenticationMechanisms=SCRAM-SHA-1'
|
|
37
|
+
# - '--fork'
|
|
38
|
+
- '--logpath'
|
|
39
|
+
- '/var/log/mongodb/mongod.log'
|
|
40
|
+
- '--bind_ip_all'
|
|
41
|
+
# command: ['sh', '-c']
|
|
42
|
+
# args:
|
|
43
|
+
# - |
|
|
44
|
+
# mongod --replSet rs0 --bind_ip_all &
|
|
45
|
+
# sleep 1000
|
|
46
|
+
# if mongosh --host mongodb-0.mongodb-service:27017 --eval "rs.status()" | grep -q "not yet initialized"; then
|
|
47
|
+
# mongosh --host mongodb-0.mongodb-service:27017 <<EOF
|
|
48
|
+
# use admin;
|
|
49
|
+
# rs.initiate({
|
|
50
|
+
# _id: "rs0",
|
|
51
|
+
# members: [
|
|
52
|
+
# { _id: 0, host: "mongodb-0.mongodb-service:27017", priority: 1 },
|
|
53
|
+
# { _id: 1, host: "mongodb-1.mongodb-service:27017", priority: 1 }
|
|
54
|
+
# ]
|
|
55
|
+
# });
|
|
56
|
+
# db.getSiblingDB("admin").createUser({
|
|
57
|
+
# user: process.env.MONGO_INITDB_ROOT_USERNAME,
|
|
58
|
+
# pwd: process.env.MONGO_INITDB_ROOT_PASSWORD,
|
|
59
|
+
# roles: [{ role: "userAdminAnyDatabase", db: "admin" }]
|
|
60
|
+
# });
|
|
61
|
+
# use default;
|
|
62
|
+
# db.createUser(
|
|
63
|
+
# {
|
|
64
|
+
# user: process.env.MONGO_INITDB_ROOT_USERNAME,
|
|
65
|
+
# pwd: process.env.MONGO_INITDB_ROOT_PASSWORD,
|
|
66
|
+
# roles: [
|
|
67
|
+
# { role: "read", db: "test" },
|
|
68
|
+
# { role: "readWrite", db: "default" }
|
|
69
|
+
# ]
|
|
70
|
+
# }
|
|
71
|
+
# );
|
|
72
|
+
# EOF
|
|
73
|
+
# fi
|
|
74
|
+
# wait
|
|
75
|
+
ports:
|
|
76
|
+
- containerPort: 27017
|
|
77
|
+
volumeMounts:
|
|
78
|
+
- name: mongodb-storage
|
|
79
|
+
mountPath: /data/db
|
|
80
|
+
- name: keyfile
|
|
81
|
+
mountPath: /etc/mongodb-keyfile
|
|
82
|
+
readOnly: true
|
|
83
|
+
# - name: mongodb-configuration-file
|
|
84
|
+
# mountPath: /etc/mongod.conf
|
|
85
|
+
# subPath: mongod.conf
|
|
86
|
+
# readOnly: true
|
|
87
|
+
# - name: mongodb-config
|
|
88
|
+
# mountPath: /config
|
|
89
|
+
env:
|
|
90
|
+
- name: MONGO_INITDB_ROOT_USERNAME
|
|
91
|
+
valueFrom:
|
|
92
|
+
secretKeyRef:
|
|
93
|
+
name: mongodb-secret
|
|
94
|
+
key: username
|
|
95
|
+
- name: MONGO_INITDB_ROOT_PASSWORD
|
|
96
|
+
valueFrom:
|
|
97
|
+
secretKeyRef:
|
|
98
|
+
name: mongodb-secret
|
|
99
|
+
key: password
|
|
100
|
+
resources:
|
|
101
|
+
requests:
|
|
102
|
+
cpu: '100m'
|
|
103
|
+
memory: '256Mi'
|
|
104
|
+
limits:
|
|
105
|
+
cpu: '500m'
|
|
106
|
+
memory: '512Mi'
|
|
107
|
+
volumes:
|
|
108
|
+
- name: keyfile
|
|
109
|
+
secret:
|
|
110
|
+
secretName: mongodb-keyfile
|
|
111
|
+
defaultMode: 0400
|
|
112
|
+
# - name: mongodb-configuration-file
|
|
113
|
+
# configMap:
|
|
114
|
+
# name: mongodb-config-file
|
|
115
|
+
# - name: mongodb-config
|
|
116
|
+
# configMap:
|
|
117
|
+
# name: mongodb-config
|
|
118
|
+
volumeClaimTemplates:
|
|
119
|
+
- metadata:
|
|
120
|
+
name: mongodb-storage
|
|
121
|
+
spec:
|
|
122
|
+
accessModes: ['ReadWriteOnce']
|
|
123
|
+
resources:
|
|
124
|
+
requests:
|
|
125
|
+
storage: 5Gi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
apiVersion: v1
|
|
3
|
+
kind: Service
|
|
4
|
+
metadata:
|
|
5
|
+
name: service-valkey
|
|
6
|
+
namespace: default
|
|
7
|
+
spec:
|
|
8
|
+
ports:
|
|
9
|
+
- port: 6379
|
|
10
|
+
targetPort: 6379
|
|
11
|
+
selector:
|
|
12
|
+
app: service-valkey
|
|
13
|
+
ipFamilyPolicy: PreferDualStack
|
|
14
|
+
ipFamilies:
|
|
15
|
+
- IPv4
|
|
16
|
+
# - IPv6
|
|
17
|
+
type: ClusterIP
|