@underpostnet/underpost 2.8.4 → 2.8.6
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 +12 -45
- package/.github/workflows/npmpkg.yml +67 -0
- package/.github/workflows/publish.yml +5 -5
- package/.github/workflows/pwa-microservices-template.page.yml +2 -1
- package/.github/workflows/pwa-microservices-template.test.yml +2 -2
- package/.vscode/settings.json +10 -1
- package/CHANGELOG.md +40 -0
- package/Dockerfile +6 -27
- package/bin/build.js +73 -165
- package/bin/deploy.js +76 -101
- package/bin/file.js +29 -15
- package/bin/hwt.js +0 -10
- package/bin/index.js +191 -32
- package/bin/util.js +0 -15
- package/bin/vs.js +1 -0
- package/conf.js +0 -2
- package/docker-compose.yml +1 -1
- package/manifests/kind-config-dev.yaml +12 -0
- package/manifests/{core/underpost-engine-mongodb-backup-cronjob.yaml → mongodb/backup-cronjob.yaml} +14 -12
- package/manifests/mongodb/kustomization.yaml +11 -0
- package/manifests/mongodb/pv-pvc.yaml +23 -0
- package/manifests/{core/underpost-engine-statefulset.yaml → mongodb/statefulset.yaml} +34 -0
- package/manifests/mongodb-4.4/kustomization.yaml +7 -0
- package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
- package/manifests/valkey/kustomization.yaml +2 -2
- package/package.json +22 -4
- package/src/api/core/core.service.js +1 -1
- package/src/cli/cluster.js +202 -0
- package/src/cli/cron.js +90 -0
- package/src/cli/db.js +212 -0
- package/src/cli/deploy.js +318 -0
- package/src/cli/env.js +52 -0
- package/src/cli/fs.js +149 -0
- package/src/cli/image.js +148 -0
- package/src/cli/repository.js +125 -0
- package/src/cli/script.js +53 -0
- package/src/cli/secrets.js +37 -0
- package/src/cli/test.js +118 -0
- package/src/client/components/core/Auth.js +22 -4
- package/src/client/components/core/CalendarCore.js +12 -1
- package/src/client/components/core/CommonJs.js +134 -2
- package/src/client/components/core/Css.js +1 -0
- package/src/client/components/core/CssCore.js +2 -4
- package/src/client/components/core/Docs.js +1 -2
- package/src/client/components/core/Input.js +5 -3
- package/src/client/components/core/LoadingAnimation.js +8 -1
- package/src/client/components/core/Modal.js +30 -7
- package/src/client/components/core/Panel.js +8 -6
- package/src/client/components/core/PanelForm.js +23 -7
- 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/services/core/core.service.js +15 -10
- package/src/client/ssr/Render.js +4 -1
- package/src/client/ssr/body/CacheControl.js +2 -3
- package/src/client/sw/default.sw.js +3 -3
- package/src/db/mongo/MongooseDB.js +17 -1
- package/src/index.js +85 -26
- package/src/server/backup.js +49 -93
- package/src/server/client-build.js +33 -33
- package/src/server/client-formatted.js +6 -3
- package/src/server/conf.js +82 -199
- package/src/server/dns.js +29 -53
- package/src/server/downloader.js +0 -8
- package/src/server/logger.js +7 -7
- package/src/server/network.js +17 -7
- package/src/server/runtime.js +24 -23
- package/test/api.test.js +0 -8
- package/manifests/core/kustomization.yaml +0 -11
- 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/manifests/{core/underpost-engine-backup-access.yaml → mongodb/backup-access.yaml} +0 -0
- /package/manifests/{core/underpost-engine-backup-pv-pvc.yaml → mongodb/backup-pv-pvc.yaml} +0 -0
- /package/manifests/{core/underpost-engine-mongodb-configmap.yaml → mongodb/configmap.yaml} +0 -0
- /package/manifests/{core/underpost-engine-headless-service.yaml → mongodb/headless-service.yaml} +0 -0
- /package/manifests/{core/underpost-engine-pv-pvc.yaml → mongodb-4.4/pv-pvc.yaml} +0 -0
- /package/manifests/valkey/{underpost-engine-valkey-service.yaml → service.yaml} +0 -0
- /package/manifests/valkey/{underpost-engine-valkey-statefulset.yaml → statefulset.yaml} +0 -0
package/bin/vs.js
CHANGED
|
@@ -20,6 +20,7 @@ switch (process.argv[2]) {
|
|
|
20
20
|
logger.info('Open new vs windows', 'Ctrl Shift N');
|
|
21
21
|
logger.info('Close current vs windows', 'Ctrl Shift W');
|
|
22
22
|
logger.info('Preview md', 'Ctrl shift V');
|
|
23
|
+
logger.info('Open git changes', 'Ctrl G + G');
|
|
23
24
|
logger.warn('Terminal shortcut configure with command pallette', 'Ctl shift T');
|
|
24
25
|
break;
|
|
25
26
|
}
|
package/conf.js
CHANGED
|
@@ -179,9 +179,7 @@ const DefaultConf = /**/ {
|
|
|
179
179
|
},
|
|
180
180
|
},
|
|
181
181
|
cron: {
|
|
182
|
-
ipDaemon: { ip: null },
|
|
183
182
|
records: { A: [{ host: 'example.com', dns: 'dondominio', api_key: '???', user: '???' }] },
|
|
184
|
-
backups: [{ deployGroupId: 'default-group' }],
|
|
185
183
|
jobs: { dns: { expression: '* * * * *', enabled: true }, backups: { expression: '0 1 * * *', enabled: true } },
|
|
186
184
|
},
|
|
187
185
|
}; /**/
|
package/docker-compose.yml
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
kind: Cluster
|
|
2
|
+
apiVersion: kind.x-k8s.io/v1alpha4
|
|
3
|
+
nodes:
|
|
4
|
+
- role: control-plane
|
|
5
|
+
- role: worker
|
|
6
|
+
# extraPortMappings:
|
|
7
|
+
# - containerPort: 80
|
|
8
|
+
# hostPort: 80
|
|
9
|
+
# listenAddress: '0.0.0.0'
|
|
10
|
+
# - containerPort: 443
|
|
11
|
+
# hostPort: 443
|
|
12
|
+
# listenAddress: '0.0.0.0'
|
package/manifests/{core/underpost-engine-mongodb-backup-cronjob.yaml → mongodb/backup-cronjob.yaml}
RENAMED
|
@@ -16,25 +16,27 @@ spec:
|
|
|
16
16
|
- -c
|
|
17
17
|
- |
|
|
18
18
|
# Perform backup
|
|
19
|
-
mongodump
|
|
19
|
+
mongodump --host=mongodb-service --port=27017 --out=/backup/$(date +\%Y-\%m-\%dT\%H-\%M-\%S)
|
|
20
20
|
# Remove backups older than 7 days
|
|
21
21
|
find /backup -type d -mtime +7 -exec rm -rf {} +
|
|
22
22
|
volumeMounts:
|
|
23
23
|
- name: backup-storage
|
|
24
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
25
|
restartPolicy: Never
|
|
37
26
|
volumes:
|
|
38
27
|
- name: backup-storage
|
|
39
28
|
persistentVolumeClaim:
|
|
40
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,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
|
|
@@ -38,6 +38,40 @@ spec:
|
|
|
38
38
|
- '--logpath'
|
|
39
39
|
- '/var/log/mongodb/mongod.log'
|
|
40
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
|
|
41
75
|
ports:
|
|
42
76
|
- containerPort: 27017
|
|
43
77
|
volumeMounts:
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
apiVersion: apps/v1
|
|
2
|
+
kind: Deployment
|
|
3
|
+
metadata:
|
|
4
|
+
name: mongodb-deployment
|
|
5
|
+
namespace: default
|
|
6
|
+
spec:
|
|
7
|
+
selector:
|
|
8
|
+
matchLabels:
|
|
9
|
+
app: mongodb
|
|
10
|
+
replicas: 1
|
|
11
|
+
template:
|
|
12
|
+
metadata:
|
|
13
|
+
labels:
|
|
14
|
+
app: mongodb
|
|
15
|
+
spec:
|
|
16
|
+
hostname: mongo
|
|
17
|
+
containers:
|
|
18
|
+
- name: mongodb
|
|
19
|
+
image: docker.io/library/mongo:4.4
|
|
20
|
+
command: ['mongod', '--replSet', 'rs0', '--bind_ip_all']
|
|
21
|
+
# -- bash
|
|
22
|
+
# mongo
|
|
23
|
+
# use admin
|
|
24
|
+
# rs.initiate()
|
|
25
|
+
ports:
|
|
26
|
+
- containerPort: 27017
|
|
27
|
+
|
|
28
|
+
volumeMounts:
|
|
29
|
+
- name: mongo-persistent-storage
|
|
30
|
+
mountPath: /data/db
|
|
31
|
+
|
|
32
|
+
# resources:
|
|
33
|
+
# requests:
|
|
34
|
+
# memory: '500Mi'
|
|
35
|
+
# cpu: '500m'
|
|
36
|
+
volumes:
|
|
37
|
+
- name: mongo-persistent-storage
|
|
38
|
+
persistentVolumeClaim:
|
|
39
|
+
claimName: mongodb-pvc
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
apiVersion: v1
|
|
43
|
+
kind: Service
|
|
44
|
+
metadata:
|
|
45
|
+
name: mongodb-service
|
|
46
|
+
namespace: default
|
|
47
|
+
spec:
|
|
48
|
+
clusterIP: None
|
|
49
|
+
selector:
|
|
50
|
+
app: mongodb
|
|
51
|
+
ports:
|
|
52
|
+
- protocol: TCP
|
|
53
|
+
port: 27017
|
|
54
|
+
# targetPort: 27017
|
|
55
|
+
# type: ClusterIP
|
|
56
|
+
|
|
57
|
+
# rs.initiate();
|
|
58
|
+
# use admin;
|
|
59
|
+
# rs.initiate({ _id: "rs0", members: [ { _id: 0, host: "127.0.0.1:27017" } ] })
|
|
60
|
+
# db.createUser({user: "your_user",pwd: "your_password", roles: [{role: "userAdminAnyDatabase", db: "admin" },{ role: "readWriteAnyDatabase", db: "admin" }]});
|
|
61
|
+
# cfg = rs.conf();
|
|
62
|
+
# cfg.members[0].host = "127.0.0.1:27027";
|
|
63
|
+
# rs.reconfig(cfg);
|
package/package.json
CHANGED
|
@@ -2,20 +2,28 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"main": "src/index.js",
|
|
4
4
|
"name": "@underpostnet/underpost",
|
|
5
|
-
"version": "2.8.
|
|
5
|
+
"version": "2.8.6",
|
|
6
6
|
"description": "pwa api rest template",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "env-cmd -f .env.production node --max-old-space-size=8192 src/server",
|
|
9
|
-
"
|
|
9
|
+
"test": "env-cmd -f .env.test c8 mocha",
|
|
10
|
+
"pm2": "env-cmd -f .env.production pm2 start src/server.js --node-args=\"--max-old-space-size=8192\" --name engine",
|
|
10
11
|
"dev": "env-cmd -f .env.development node src/client.dev default",
|
|
12
|
+
"dev-img": "env-cmd -f .env.development node src/server",
|
|
13
|
+
"prod-img": "env-cmd -f .env.production node src/server",
|
|
11
14
|
"dev-api": "env-cmd -f .env.development nodemon --watch src --ignore src/client src/api",
|
|
15
|
+
"dev-client": "env-cmd -f .env.development node src/client.dev",
|
|
16
|
+
"proxy": "node src/proxy proxy",
|
|
12
17
|
"docs": "jsdoc -c jsdoc.json",
|
|
13
18
|
"install-global": "npm install -g pm2 && npm install -g jsdoc && npm install -g prettier && npm install -g env-cmd && npm install -g yarn && npm install -g auto-changelog",
|
|
14
19
|
"install-test": "npm install -g mocha && npm install -g c8 && npm install -g nyc && npm install -g coveralls",
|
|
20
|
+
"install-underpost": "cp -a $(npm root -g)/underpost/node_modules ./node_modules && npm install --only=dev --ignore-scripts",
|
|
15
21
|
"install": "npm run install-global && npm run install-test",
|
|
16
22
|
"docker:start": "docker-compose up",
|
|
17
23
|
"prettier": "prettier --write .",
|
|
18
|
-
"
|
|
24
|
+
"fix": "npm audit fix --force && npm audit",
|
|
25
|
+
"changelog": "auto-changelog",
|
|
26
|
+
"build": "node bin/deploy build-full-client"
|
|
19
27
|
},
|
|
20
28
|
"bin": {
|
|
21
29
|
"underpost": "bin/index.js"
|
|
@@ -25,6 +33,10 @@
|
|
|
25
33
|
"url": "git+https://github.com/underpostnet/pwa-microservices-template-ghpkg.git"
|
|
26
34
|
},
|
|
27
35
|
"keywords": [
|
|
36
|
+
"pwa",
|
|
37
|
+
"microservices",
|
|
38
|
+
"template",
|
|
39
|
+
"builder",
|
|
28
40
|
"engine",
|
|
29
41
|
"server",
|
|
30
42
|
"proxy",
|
|
@@ -45,9 +57,11 @@
|
|
|
45
57
|
"ag-grid-community": "31.0.0",
|
|
46
58
|
"axios": "^1.5.1",
|
|
47
59
|
"chai": "^5.1.0",
|
|
60
|
+
"clean-jsdoc-theme": "^4.3.0",
|
|
48
61
|
"cli-progress": "^3.12.0",
|
|
49
62
|
"cli-spinners": "^3.0.0",
|
|
50
63
|
"clipboardy": "^4.0.0",
|
|
64
|
+
"cloudinary": "^2.5.1",
|
|
51
65
|
"color": "^4.2.3",
|
|
52
66
|
"colors": "^1.4.0",
|
|
53
67
|
"commander": "^12.1.0",
|
|
@@ -55,6 +69,7 @@
|
|
|
55
69
|
"cors": "^2.8.5",
|
|
56
70
|
"d3": "^7.9.0",
|
|
57
71
|
"dotenv": "^16.3.1",
|
|
72
|
+
"easy-json-schema": "^0.0.2-beta",
|
|
58
73
|
"easymde": "^2.18.0",
|
|
59
74
|
"env-cmd": "^10.1.0",
|
|
60
75
|
"express": "^4.18.2",
|
|
@@ -75,6 +90,7 @@
|
|
|
75
90
|
"log-update": "^6.0.0",
|
|
76
91
|
"mariadb": "^3.2.2",
|
|
77
92
|
"marked": "^12.0.2",
|
|
93
|
+
"mocha": "^10.8.2",
|
|
78
94
|
"mongoose": "^8.9.5",
|
|
79
95
|
"morgan": "^1.10.0",
|
|
80
96
|
"nodemailer": "^6.9.9",
|
|
@@ -83,6 +99,7 @@
|
|
|
83
99
|
"peer": "^1.0.2",
|
|
84
100
|
"peerjs": "^1.5.2",
|
|
85
101
|
"pixi.js": "7.4.2",
|
|
102
|
+
"plantuml": "^0.0.2",
|
|
86
103
|
"prom-client": "^15.1.2",
|
|
87
104
|
"public-ip": "^6.0.1",
|
|
88
105
|
"read": "^2.1.0",
|
|
@@ -94,6 +111,7 @@
|
|
|
94
111
|
"socket.io": "^4.8.0",
|
|
95
112
|
"sortablejs": "^1.15.0",
|
|
96
113
|
"split-file": "^2.3.0",
|
|
114
|
+
"swagger-autogen": "^2.23.7",
|
|
97
115
|
"swagger-ui-express": "^5.0.0",
|
|
98
116
|
"systeminformation": "^5.23.7",
|
|
99
117
|
"uglify-js": "^3.17.4",
|
|
@@ -104,7 +122,7 @@
|
|
|
104
122
|
"devDependencies": {
|
|
105
123
|
"clean-jsdoc-theme": "^4.3.0",
|
|
106
124
|
"easy-json-schema": "^0.0.2-beta",
|
|
107
|
-
"mocha": "^10.
|
|
125
|
+
"mocha": "^10.8.2",
|
|
108
126
|
"plantuml": "^0.0.2",
|
|
109
127
|
"swagger-autogen": "^2.23.7"
|
|
110
128
|
},
|
|
@@ -9,7 +9,7 @@ const CoreService = {
|
|
|
9
9
|
/** @type {import('./core.model.js').CoreModel} */
|
|
10
10
|
const Core = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Core;
|
|
11
11
|
if (req.path.startsWith('/sh')) {
|
|
12
|
-
if (req.body.
|
|
12
|
+
if (req.body.stdout) return shellExec(req.body.sh, { stdout: true });
|
|
13
13
|
shellExec(req.body.sh, { async: true });
|
|
14
14
|
return 'Command "' + req.body.sh + '" running';
|
|
15
15
|
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { timer } from '../client/components/core/CommonJs.js';
|
|
2
|
+
import { cliSpinner, getNpmRootPath } from '../server/conf.js';
|
|
3
|
+
import { loggerFactory } from '../server/logger.js';
|
|
4
|
+
import { shellExec } from '../server/process.js';
|
|
5
|
+
import UnderpostDeploy from './deploy.js';
|
|
6
|
+
import UnderpostTest from './test.js';
|
|
7
|
+
|
|
8
|
+
const logger = loggerFactory(import.meta);
|
|
9
|
+
|
|
10
|
+
class UnderpostCluster {
|
|
11
|
+
static API = {
|
|
12
|
+
async init(
|
|
13
|
+
podName,
|
|
14
|
+
options = {
|
|
15
|
+
mongodb: false,
|
|
16
|
+
mongodb4: false,
|
|
17
|
+
mariadb: false,
|
|
18
|
+
valkey: false,
|
|
19
|
+
full: false,
|
|
20
|
+
info: false,
|
|
21
|
+
certManager: false,
|
|
22
|
+
listPods: false,
|
|
23
|
+
reset: false,
|
|
24
|
+
dev: false,
|
|
25
|
+
nsUse: '',
|
|
26
|
+
},
|
|
27
|
+
) {
|
|
28
|
+
const npmRoot = getNpmRootPath();
|
|
29
|
+
const underpostRoot = options?.dev === true ? '.' : `${npmRoot}/underpost`;
|
|
30
|
+
if (options.reset === true) return await UnderpostCluster.API.reset();
|
|
31
|
+
if (options.listPods === true) return console.table(UnderpostDeploy.API.get(podName ?? undefined));
|
|
32
|
+
|
|
33
|
+
if (options.nsUse && typeof options.nsUse === 'string') {
|
|
34
|
+
shellExec(`kubectl config set-context --current --namespace=${options.nsUse}`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (options.info === true) {
|
|
38
|
+
shellExec(`kubectl config get-contexts`); // config env persisente for manage multiple clusters
|
|
39
|
+
shellExec(`kubectl config get-clusters`);
|
|
40
|
+
shellExec(`kubectl get nodes -o wide`); // set of nodes of a cluster
|
|
41
|
+
shellExec(`kubectl config view | grep namespace`);
|
|
42
|
+
shellExec(`kubectl get ns -o wide`); // A namespace can have pods of different nodes
|
|
43
|
+
shellExec(`kubectl get pvc --all-namespaces -o wide`); // PersistentVolumeClaim -> request storage service
|
|
44
|
+
shellExec(`kubectl get pv --all-namespaces -o wide`); // PersistentVolume -> real storage
|
|
45
|
+
shellExec(`kubectl get cronjob --all-namespaces -o wide`);
|
|
46
|
+
shellExec(`kubectl get svc --all-namespaces -o wide`); // proxy dns gate way -> deployments, statefulsets, pods
|
|
47
|
+
shellExec(`kubectl get statefulsets --all-namespaces -o wide`); // set pods with data/volume persistence
|
|
48
|
+
shellExec(`kubectl get deployments --all-namespaces -o wide`); // set pods
|
|
49
|
+
shellExec(`kubectl get configmap --all-namespaces -o wide`);
|
|
50
|
+
shellExec(`kubectl get pods --all-namespaces -o wide`);
|
|
51
|
+
shellExec(
|
|
52
|
+
`kubectl get pod --all-namespaces -o="custom-columns=NAME:.metadata.name,INIT-CONTAINERS:.spec.initContainers[*].name,CONTAINERS:.spec.containers[*].name"`,
|
|
53
|
+
);
|
|
54
|
+
shellExec(
|
|
55
|
+
`kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\\n"}{.metadata.name}{":\\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'`,
|
|
56
|
+
);
|
|
57
|
+
console.log();
|
|
58
|
+
logger.info('contour -------------------------------------------------');
|
|
59
|
+
for (const _k of ['Cluster', 'HTTPProxy', 'ClusterIssuer', 'Certificate']) {
|
|
60
|
+
shellExec(`kubectl get ${_k} --all-namespaces -o wide`);
|
|
61
|
+
}
|
|
62
|
+
logger.info('----------------------------------------------------------------');
|
|
63
|
+
shellExec(`kubectl get secrets --all-namespaces -o wide`);
|
|
64
|
+
shellExec(`docker secret ls`);
|
|
65
|
+
shellExec(`kubectl get crd --all-namespaces -o wide`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!UnderpostDeploy.API.get('kube-apiserver-kind-control-plane')[0]) {
|
|
70
|
+
shellExec(`containerd config default > /etc/containerd/config.toml`);
|
|
71
|
+
shellExec(`sed -i -e "s/SystemdCgroup = false/SystemdCgroup = true/g" /etc/containerd/config.toml`);
|
|
72
|
+
// shellExec(`cp /etc/kubernetes/admin.conf ~/.kube/config`);
|
|
73
|
+
shellExec(`sudo systemctl restart kubelet`);
|
|
74
|
+
shellExec(`sudo service docker restart`);
|
|
75
|
+
shellExec(`sudo systemctl enable --now containerd.service`);
|
|
76
|
+
shellExec(`sudo systemctl restart containerd`);
|
|
77
|
+
shellExec(
|
|
78
|
+
`cd ${underpostRoot}/manifests && kind create cluster --config kind-config${
|
|
79
|
+
options?.dev === true ? '-dev' : ''
|
|
80
|
+
}.yaml`,
|
|
81
|
+
);
|
|
82
|
+
shellExec(`sudo chown $(id -u):$(id -g) $HOME/.kube/config**`);
|
|
83
|
+
} else logger.warn('Cluster already initialized');
|
|
84
|
+
|
|
85
|
+
if (options.full === true || options.valkey === true) {
|
|
86
|
+
shellExec(`kubectl delete statefulset service-valkey`);
|
|
87
|
+
shellExec(`kubectl apply -k ${underpostRoot}/manifests/valkey`);
|
|
88
|
+
}
|
|
89
|
+
if (options.full === true || options.mariadb === true) {
|
|
90
|
+
shellExec(
|
|
91
|
+
`sudo kubectl create secret generic mariadb-secret --from-file=username=/home/dd/engine/engine-private/mariadb-username --from-file=password=/home/dd/engine/engine-private/mariadb-password`,
|
|
92
|
+
);
|
|
93
|
+
shellExec(
|
|
94
|
+
`sudo kubectl create secret generic github-secret --from-literal=GITHUB_TOKEN=${process.env.GITHUB_TOKEN}`,
|
|
95
|
+
);
|
|
96
|
+
shellExec(`kubectl delete statefulset mariadb-statefulset`);
|
|
97
|
+
shellExec(`kubectl apply -k ${underpostRoot}/manifests/mariadb`);
|
|
98
|
+
}
|
|
99
|
+
if (options.mongodb4 === true) {
|
|
100
|
+
shellExec(`kubectl apply -k ${underpostRoot}/manifests/mongodb-4.4`);
|
|
101
|
+
|
|
102
|
+
const deploymentName = 'mongodb-deployment';
|
|
103
|
+
|
|
104
|
+
const successInstance = await UnderpostTest.API.statusMonitor(deploymentName);
|
|
105
|
+
|
|
106
|
+
if (successInstance) {
|
|
107
|
+
const mongoConfig = {
|
|
108
|
+
_id: 'rs0',
|
|
109
|
+
members: [{ _id: 0, host: '127.0.0.1:27017' }],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const [pod] = UnderpostDeploy.API.get(deploymentName);
|
|
113
|
+
|
|
114
|
+
shellExec(
|
|
115
|
+
`sudo kubectl exec -i ${pod.NAME} -- mongo --quiet \
|
|
116
|
+
--eval 'rs.initiate(${JSON.stringify(mongoConfig)})'`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// await UnderpostTest.API.statusMonitor('mongodb-1');
|
|
121
|
+
} else if (options.full === true || options.mongodb === true) {
|
|
122
|
+
shellExec(
|
|
123
|
+
`sudo kubectl create secret generic mongodb-keyfile --from-file=/home/dd/engine/engine-private/mongodb-keyfile`,
|
|
124
|
+
);
|
|
125
|
+
shellExec(
|
|
126
|
+
`sudo kubectl create secret generic mongodb-secret --from-file=username=/home/dd/engine/engine-private/mongodb-username --from-file=password=/home/dd/engine/engine-private/mongodb-password`,
|
|
127
|
+
);
|
|
128
|
+
shellExec(`kubectl delete statefulset mongodb`);
|
|
129
|
+
shellExec(`kubectl apply -k ${underpostRoot}/manifests/mongodb`);
|
|
130
|
+
|
|
131
|
+
const successInstance = await UnderpostTest.API.statusMonitor('mongodb-1');
|
|
132
|
+
|
|
133
|
+
if (successInstance) {
|
|
134
|
+
const mongoConfig = {
|
|
135
|
+
_id: 'rs0',
|
|
136
|
+
members: [
|
|
137
|
+
{ _id: 0, host: 'mongodb-0.mongodb-service:27017', priority: 1 },
|
|
138
|
+
{ _id: 1, host: 'mongodb-1.mongodb-service:27017', priority: 1 },
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
shellExec(
|
|
143
|
+
`sudo kubectl exec -i mongodb-0 -- mongosh --quiet --json=relaxed \
|
|
144
|
+
--eval 'use admin' \
|
|
145
|
+
--eval 'rs.initiate(${JSON.stringify(mongoConfig)})' \
|
|
146
|
+
--eval 'rs.status()'`,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (options.full === true || options.contour === true)
|
|
152
|
+
shellExec(`kubectl apply -f https://projectcontour.io/quickstart/contour.yaml`);
|
|
153
|
+
|
|
154
|
+
if (options.full === true || options.certManager === true) {
|
|
155
|
+
if (!UnderpostDeploy.API.get('cert-manager').find((p) => p.STATUS === 'Running')) {
|
|
156
|
+
shellExec(`helm repo add jetstack https://charts.jetstack.io --force-update`);
|
|
157
|
+
shellExec(
|
|
158
|
+
`helm install cert-manager jetstack/cert-manager \
|
|
159
|
+
--namespace cert-manager \
|
|
160
|
+
--create-namespace \
|
|
161
|
+
--version v1.17.0 \
|
|
162
|
+
--set crds.enabled=true`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const letsEncName = 'letsencrypt-prod';
|
|
167
|
+
shellExec(`sudo kubectl delete ClusterIssuer ${letsEncName}`);
|
|
168
|
+
shellExec(`sudo kubectl apply -f ${underpostRoot}/manifests/${letsEncName}.yaml`);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
reset() {
|
|
172
|
+
shellExec(`kind get clusters | xargs -t -n1 kind delete cluster --name`);
|
|
173
|
+
shellExec(`sudo kubeadm reset -f`);
|
|
174
|
+
shellExec('sudo rm -f /etc/cni/net.d/10-flannel.conflist');
|
|
175
|
+
shellExec('sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X');
|
|
176
|
+
shellExec('sudo rm -f $HOME/.kube/config');
|
|
177
|
+
shellExec('sudo rm -rf /root/.local/share/Trash/files/*');
|
|
178
|
+
shellExec('sudo docker system prune -a -f');
|
|
179
|
+
shellExec('sudo service docker stop');
|
|
180
|
+
shellExec(`sudo rm -rf /var/lib/containers/storage/*`);
|
|
181
|
+
shellExec(`sudo rm -rf /var/lib/docker/volumes/*`);
|
|
182
|
+
shellExec(`sudo rm -rf /var/lib/docker~/*`);
|
|
183
|
+
shellExec(`sudo rm -rf /home/containers/storage/*`);
|
|
184
|
+
shellExec(`sudo rm -rf /home/docker/*`);
|
|
185
|
+
shellExec('sudo mv /var/lib/docker /var/lib/docker~');
|
|
186
|
+
shellExec('sudo mkdir /home/docker');
|
|
187
|
+
shellExec('sudo chmod 0711 /home/docker');
|
|
188
|
+
shellExec('sudo ln -s /home/docker /var/lib/docker');
|
|
189
|
+
shellExec(`sudo podman system prune -a -f`);
|
|
190
|
+
shellExec(`sudo podman system prune --all --volumes --force`);
|
|
191
|
+
shellExec(`sudo podman system prune --external --force`);
|
|
192
|
+
shellExec(`sudo podman system prune --all --volumes --force`);
|
|
193
|
+
shellExec(`sudo mkdir -p /home/containers/storage`);
|
|
194
|
+
shellExec('sudo chmod 0711 /home/containers/storage');
|
|
195
|
+
shellExec(
|
|
196
|
+
`sudo sed -i -e "s@/var/lib/containers/storage@/home/containers/storage@g" /etc/containers/storage.conf`,
|
|
197
|
+
);
|
|
198
|
+
shellExec(`sudo podman system reset -f`);
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export default UnderpostCluster;
|
package/src/cli/cron.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UnderpostCron CLI index module
|
|
3
|
+
* @module src/cli/cron.js
|
|
4
|
+
* @namespace UnderpostCron
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import Underpost from '../index.js';
|
|
8
|
+
import BackUp from '../server/backup.js';
|
|
9
|
+
import { Cmd } from '../server/conf.js';
|
|
10
|
+
import Dns from '../server/dns.js';
|
|
11
|
+
import { netWorkCron, saveRuntimeCron } from '../server/network.js';
|
|
12
|
+
import { shellExec } from '../server/process.js';
|
|
13
|
+
import fs from 'fs-extra';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* UnderpostCron main module methods
|
|
17
|
+
* @class
|
|
18
|
+
* @memberof UnderpostCron
|
|
19
|
+
*/
|
|
20
|
+
class UnderpostCron {
|
|
21
|
+
static JOB = {
|
|
22
|
+
/**
|
|
23
|
+
* DNS cli API
|
|
24
|
+
* @static
|
|
25
|
+
* @type {Dns}
|
|
26
|
+
* @memberof UnderpostCron
|
|
27
|
+
*/
|
|
28
|
+
dns: Dns,
|
|
29
|
+
/**
|
|
30
|
+
* BackUp cli API
|
|
31
|
+
* @static
|
|
32
|
+
* @type {BackUp}
|
|
33
|
+
* @memberof UnderpostCron
|
|
34
|
+
*/
|
|
35
|
+
backup: BackUp,
|
|
36
|
+
};
|
|
37
|
+
static API = {
|
|
38
|
+
/**
|
|
39
|
+
* Run the cron jobs
|
|
40
|
+
* @static
|
|
41
|
+
* @param {String} deployList - Comma separated deploy ids
|
|
42
|
+
* @param {String} jobList - Comma separated job ids
|
|
43
|
+
* @return {void}
|
|
44
|
+
* @memberof UnderpostCron
|
|
45
|
+
*/
|
|
46
|
+
callback: async function (
|
|
47
|
+
deployList = 'default',
|
|
48
|
+
jobList = Object.keys(UnderpostCron.JOB),
|
|
49
|
+
options = { itc: false, init: false, git: false },
|
|
50
|
+
) {
|
|
51
|
+
if (options.init === true) {
|
|
52
|
+
await Underpost.test.setUpInfo();
|
|
53
|
+
const jobDeployId = fs.readFileSync('./engine-private/deploy/dd.cron', 'utf8').trim();
|
|
54
|
+
deployList = fs.readFileSync('./engine-private/deploy/dd.router', 'utf8').trim();
|
|
55
|
+
const confCronConfig = JSON.parse(fs.readFileSync(`./engine-private/conf/${jobDeployId}/conf.cron.json`));
|
|
56
|
+
if (confCronConfig.jobs && Object.keys(confCronConfig.jobs).length > 0) {
|
|
57
|
+
for (const job of Object.keys(confCronConfig.jobs)) {
|
|
58
|
+
const name = `${jobDeployId}-${job}`;
|
|
59
|
+
let deployId;
|
|
60
|
+
shellExec(Cmd.delete(name));
|
|
61
|
+
switch (job) {
|
|
62
|
+
case 'dns':
|
|
63
|
+
deployId = jobDeployId;
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
deployId = deployList;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
shellExec(Cmd.cron(deployId, job, name, confCronConfig.jobs[job].expression, options));
|
|
71
|
+
netWorkCron.push({
|
|
72
|
+
deployId,
|
|
73
|
+
jobId: job,
|
|
74
|
+
expression: confCronConfig.jobs[job].expression,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
await saveRuntimeCron();
|
|
79
|
+
if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const _jobId of jobList.split(',')) {
|
|
83
|
+
const jobId = _jobId.trim();
|
|
84
|
+
if (UnderpostCron.JOB[jobId]) await UnderpostCron.JOB[jobId].callback(deployList, options);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default UnderpostCron;
|