underpost 2.8.635 → 2.8.641
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/Dockerfile +9 -10
- package/bin/build.js +2 -2
- package/bin/deploy.js +2 -1
- package/bin/index.js +14 -8
- package/docker-compose.yml +1 -1
- package/package.json +1 -3
- package/src/api/default/default.service.js +1 -1
- package/src/api/user/user.service.js +1 -1
- package/src/cli/cron.js +39 -8
- package/src/cli/deploy.js +63 -10
- package/src/cli/fs.js +7 -6
- package/src/cli/image.js +40 -34
- package/src/cli/monitor.js +62 -38
- package/src/client/components/core/Account.js +25 -21
- package/src/client/components/core/Blockchain.js +1 -1
- package/src/client/components/core/CalendarCore.js +14 -84
- package/src/client/components/core/CommonJs.js +2 -1
- package/src/client/components/core/CssCore.js +8 -2
- package/src/client/components/core/EventsUI.js +2 -2
- package/src/client/components/core/FileExplorer.js +86 -78
- package/src/client/components/core/LoadingAnimation.js +1 -17
- package/src/client/components/core/LogIn.js +3 -3
- package/src/client/components/core/LogOut.js +1 -1
- package/src/client/components/core/Modal.js +12 -7
- package/src/client/components/core/Panel.js +19 -61
- package/src/client/components/core/PanelForm.js +13 -22
- package/src/client/components/core/Recover.js +3 -3
- package/src/client/components/core/Router.js +3 -1
- package/src/client/components/core/SignUp.js +2 -2
- package/src/client/components/default/RoutesDefault.js +3 -2
- package/src/client/services/default/default.management.js +45 -38
- package/src/client/ssr/Render.js +2 -0
- package/src/index.js +10 -3
- package/src/runtime/lampp/Dockerfile +65 -0
- package/src/server/dns.js +9 -1
- package/src/server/json-schema.js +77 -0
- package/src/server/network.js +7 -122
- package/src/server/runtime.js +1 -3
package/Dockerfile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
ARG BASE_DEBIAN=buster
|
|
2
2
|
|
|
3
|
+
# USER root
|
|
4
|
+
|
|
3
5
|
FROM debian:${BASE_DEBIAN}
|
|
4
6
|
|
|
5
7
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
6
8
|
|
|
7
|
-
WORKDIR /home/dd
|
|
8
|
-
|
|
9
9
|
# Set root password to root, format is 'user:password'.
|
|
10
10
|
RUN echo 'root:root' | chpasswd
|
|
11
11
|
|
|
@@ -25,9 +25,6 @@ RUN mkdir -p /var/run/sshd
|
|
|
25
25
|
# Allow root login via password
|
|
26
26
|
RUN sed -ri 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
|
27
27
|
|
|
28
|
-
# copy supervisor config file to start openssh-server
|
|
29
|
-
COPY supervisord-openssh-server.conf /etc/supervisor/conf.d/supervisord-openssh-server.conf
|
|
30
|
-
|
|
31
28
|
# install open ssl git and others tools
|
|
32
29
|
RUN apt-get install -yq --no-install-recommends libssl-dev curl wget git gnupg
|
|
33
30
|
|
|
@@ -37,12 +34,14 @@ RUN apt-get install -y nodejs build-essential
|
|
|
37
34
|
RUN node --version
|
|
38
35
|
RUN npm --version
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
VOLUME [ "/home/dd/engine/logs" ]
|
|
37
|
+
WORKDIR /home/dd
|
|
43
38
|
|
|
44
39
|
EXPOSE 22
|
|
45
40
|
|
|
46
|
-
EXPOSE
|
|
41
|
+
EXPOSE 80
|
|
42
|
+
|
|
43
|
+
EXPOSE 443
|
|
44
|
+
|
|
45
|
+
EXPOSE 3000-3100
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
EXPOSE 4000-4100
|
package/bin/build.js
CHANGED
|
@@ -47,7 +47,7 @@ if (process.argv.includes('conf')) {
|
|
|
47
47
|
if (!fs.existsSync(`../${privateRepoName}`)) {
|
|
48
48
|
shellExec(`cd .. && underpost clone ${privateGitUri}`, { silent: true });
|
|
49
49
|
} else {
|
|
50
|
-
shellExec(`cd ../${privateRepoName} && underpost pull . ${privateGitUri}`);
|
|
50
|
+
shellExec(`cd ../${privateRepoName} && git checkout . && git clean -f -d && underpost pull . ${privateGitUri}`);
|
|
51
51
|
}
|
|
52
52
|
const toPath = `../${privateRepoName}/conf/${_confName}`;
|
|
53
53
|
fs.removeSync(toPath);
|
|
@@ -176,7 +176,7 @@ const { DefaultConf } = await import(`../conf.${confName}.js`);
|
|
|
176
176
|
if (!fs.existsSync(`${basePath}/images`)) fs.mkdirSync(`${basePath}/images`);
|
|
177
177
|
|
|
178
178
|
const env = process.argv.includes('development') ? 'development' : 'production';
|
|
179
|
-
const deploymentsFiles = ['
|
|
179
|
+
const deploymentsFiles = ['proxy.yaml', 'deployment.yaml', 'secret.yaml'];
|
|
180
180
|
// remove engine-private of .dockerignore for local testing
|
|
181
181
|
for (const file of deploymentsFiles) {
|
|
182
182
|
if (fs.existsSync(`./manifests/deployment/${confName}-${env}/${file}`)) {
|
package/bin/deploy.js
CHANGED
|
@@ -33,8 +33,9 @@ import { MongooseDB } from '../src/db/mongo/MongooseDB.js';
|
|
|
33
33
|
import { Lampp } from '../src/runtime/lampp/Lampp.js';
|
|
34
34
|
import { DefaultConf } from '../conf.js';
|
|
35
35
|
import { JSONweb } from '../src/server/client-formatted.js';
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
import { Xampp } from '../src/runtime/xampp/Xampp.js';
|
|
38
|
+
import { ejs } from '../src/server/json-schema.js';
|
|
38
39
|
|
|
39
40
|
const logger = loggerFactory(import.meta);
|
|
40
41
|
|
package/bin/index.js
CHANGED
|
@@ -105,6 +105,7 @@ program
|
|
|
105
105
|
.option('--info-util', 'Display kubectl util management commands')
|
|
106
106
|
.option('--cert', 'Reset tls/ssl certificate secrets')
|
|
107
107
|
.option('--build-manifest', 'Build kind yaml manifests: deployments, services, proxy and secrets')
|
|
108
|
+
.option('--dashboard-update', 'Update dashboard instance data with current router config')
|
|
108
109
|
.option('--version', 'Set custom version')
|
|
109
110
|
.description('Manage deployment, for default deploy development pods')
|
|
110
111
|
.action(Underpost.deploy.callback);
|
|
@@ -135,13 +136,15 @@ program
|
|
|
135
136
|
|
|
136
137
|
program
|
|
137
138
|
.command('dockerfile-image-build')
|
|
138
|
-
.
|
|
139
|
-
.
|
|
140
|
-
.
|
|
141
|
-
.option('--
|
|
142
|
-
.option('--podman-save', '
|
|
143
|
-
.option('--
|
|
144
|
-
.option('--
|
|
139
|
+
.option('--path [path]', 'Dockerfile path')
|
|
140
|
+
.option('--image-name [image-name]', 'Set image name')
|
|
141
|
+
.option('--image-path [image-path]', 'Set tar image path')
|
|
142
|
+
.option('--dockerfile-name [dockerfile-name]', 'set Dockerfile name')
|
|
143
|
+
.option('--podman-save', 'Export tar file from podman')
|
|
144
|
+
.option('--kind-load', 'Import tar image to Kind cluster')
|
|
145
|
+
.option('--secrets', 'Dockerfile env secrets')
|
|
146
|
+
.option('--secrets-path [secrets-path]', 'Dockerfile custom path env secrets')
|
|
147
|
+
.option('--no-cache', 'Build without using cache')
|
|
145
148
|
.description('Build image from Dockerfile')
|
|
146
149
|
.action(Underpost.image.dockerfile.build);
|
|
147
150
|
|
|
@@ -193,6 +196,7 @@ program
|
|
|
193
196
|
.option('--itc', 'Inside container execution context')
|
|
194
197
|
.option('--init', 'Init cron jobs for cron job default deploy id')
|
|
195
198
|
.option('--git', 'Upload to github')
|
|
199
|
+
.option('--dashboard-update', 'Update dashboard cron data with current jobs config')
|
|
196
200
|
.description('Cron jobs management')
|
|
197
201
|
.action(Underpost.cron.callback);
|
|
198
202
|
|
|
@@ -224,8 +228,10 @@ program
|
|
|
224
228
|
.command('monitor')
|
|
225
229
|
.argument('<deploy-id>', 'Deploy configuration id')
|
|
226
230
|
.argument('[env]', 'Optional environment, for default is development')
|
|
231
|
+
.option('--ms-interval <ms-interval>', 'Custom ms interval delta time')
|
|
232
|
+
.option('--now', 'Exec immediately monitor script')
|
|
233
|
+
.option('--single', 'Disable recurrence')
|
|
227
234
|
.description('Monitor health server management')
|
|
228
|
-
.option('--itc', 'Inside container execution context')
|
|
229
235
|
.action(Underpost.monitor.callback);
|
|
230
236
|
|
|
231
237
|
program.parse();
|
package/docker-compose.yml
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"main": "src/index.js",
|
|
4
4
|
"name": "underpost",
|
|
5
|
-
"version": "2.8.
|
|
5
|
+
"version": "2.8.641",
|
|
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",
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"cors": "^2.8.5",
|
|
70
70
|
"d3": "^7.9.0",
|
|
71
71
|
"dotenv": "^16.3.1",
|
|
72
|
-
"easy-json-schema": "^0.0.2-beta",
|
|
73
72
|
"easymde": "^2.18.0",
|
|
74
73
|
"env-cmd": "^10.1.0",
|
|
75
74
|
"express": "^4.18.2",
|
|
@@ -121,7 +120,6 @@
|
|
|
121
120
|
},
|
|
122
121
|
"devDependencies": {
|
|
123
122
|
"clean-jsdoc-theme": "^4.3.0",
|
|
124
|
-
"easy-json-schema": "^0.0.2-beta",
|
|
125
123
|
"mocha": "^10.8.2",
|
|
126
124
|
"plantuml": "^0.0.2",
|
|
127
125
|
"swagger-autogen": "^2.23.7"
|
|
@@ -24,7 +24,7 @@ const DefaultService = {
|
|
|
24
24
|
/** @type {import('./default.model.js').DefaultModel} */
|
|
25
25
|
const Default = DataBaseProvider.instance[`${options.host}${options.path}`].mongoose.models.Default;
|
|
26
26
|
if (req.params.id) return await Default.findByIdAndDelete(req.params.id);
|
|
27
|
-
else return await
|
|
27
|
+
else return await Default.deleteMany();
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
|
|
@@ -378,7 +378,7 @@ const UserService = {
|
|
|
378
378
|
switch (user.role) {
|
|
379
379
|
case 'admin': {
|
|
380
380
|
if (req.params.id) return await User.findByIdAndDelete(req.params.id);
|
|
381
|
-
else return await
|
|
381
|
+
else return await User.deleteMany();
|
|
382
382
|
}
|
|
383
383
|
default:
|
|
384
384
|
if (req.auth.user._id !== req.params.id) throw new Error(`Invalid token user id`);
|
package/src/cli/cron.js
CHANGED
|
@@ -4,20 +4,24 @@
|
|
|
4
4
|
* @namespace UnderpostCron
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { DataBaseProvider } from '../db/DataBaseProvider.js';
|
|
8
8
|
import BackUp from '../server/backup.js';
|
|
9
9
|
import { Cmd } from '../server/conf.js';
|
|
10
10
|
import Dns from '../server/dns.js';
|
|
11
|
-
import {
|
|
11
|
+
import { loggerFactory } from '../server/logger.js';
|
|
12
|
+
|
|
12
13
|
import { shellExec } from '../server/process.js';
|
|
13
14
|
import fs from 'fs-extra';
|
|
14
15
|
|
|
16
|
+
const logger = loggerFactory(import.meta);
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* UnderpostCron main module methods
|
|
17
20
|
* @class
|
|
18
21
|
* @memberof UnderpostCron
|
|
19
22
|
*/
|
|
20
23
|
class UnderpostCron {
|
|
24
|
+
static NETWORK = [];
|
|
21
25
|
static JOB = {
|
|
22
26
|
/**
|
|
23
27
|
* DNS cli API
|
|
@@ -46,10 +50,10 @@ class UnderpostCron {
|
|
|
46
50
|
callback: async function (
|
|
47
51
|
deployList = 'default',
|
|
48
52
|
jobList = Object.keys(UnderpostCron.JOB),
|
|
49
|
-
options = { itc: false, init: false, git: false },
|
|
53
|
+
options = { itc: false, init: false, git: false, dashboardUpdate: false },
|
|
50
54
|
) {
|
|
51
55
|
if (options.init === true) {
|
|
52
|
-
|
|
56
|
+
UnderpostCron.NETWORK = [];
|
|
53
57
|
const jobDeployId = fs.readFileSync('./engine-private/deploy/dd.cron', 'utf8').trim();
|
|
54
58
|
deployList = fs.readFileSync('./engine-private/deploy/dd.router', 'utf8').trim();
|
|
55
59
|
const confCronConfig = JSON.parse(fs.readFileSync(`./engine-private/conf/${jobDeployId}/conf.cron.json`));
|
|
@@ -57,7 +61,7 @@ class UnderpostCron {
|
|
|
57
61
|
for (const job of Object.keys(confCronConfig.jobs)) {
|
|
58
62
|
const name = `${jobDeployId}-${job}`;
|
|
59
63
|
let deployId;
|
|
60
|
-
shellExec(Cmd.delete(name));
|
|
64
|
+
if (!options.dashboardUpdate) shellExec(Cmd.delete(name));
|
|
61
65
|
switch (job) {
|
|
62
66
|
case 'dns':
|
|
63
67
|
deployId = jobDeployId;
|
|
@@ -67,15 +71,16 @@ class UnderpostCron {
|
|
|
67
71
|
deployId = deployList;
|
|
68
72
|
break;
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
if (!options.dashboardUpdate)
|
|
75
|
+
shellExec(Cmd.cron(deployId, job, name, confCronConfig.jobs[job].expression, options));
|
|
76
|
+
UnderpostCron.NETWORK.push({
|
|
72
77
|
deployId,
|
|
73
78
|
jobId: job,
|
|
74
79
|
expression: confCronConfig.jobs[job].expression,
|
|
75
80
|
});
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
|
-
await
|
|
83
|
+
if (options.dashboardUpdate === true) await UnderpostCron.API.updateDashboardData();
|
|
79
84
|
if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
|
|
80
85
|
return;
|
|
81
86
|
}
|
|
@@ -84,6 +89,32 @@ class UnderpostCron {
|
|
|
84
89
|
if (UnderpostCron.JOB[jobId]) await UnderpostCron.JOB[jobId].callback(deployList, options);
|
|
85
90
|
}
|
|
86
91
|
},
|
|
92
|
+
async updateDashboardData() {
|
|
93
|
+
try {
|
|
94
|
+
const deployId = process.env.DEFAULT_DEPLOY_ID;
|
|
95
|
+
const host = process.env.DEFAULT_DEPLOY_HOST;
|
|
96
|
+
const path = process.env.DEFAULT_DEPLOY_PATH;
|
|
97
|
+
const confServerPath = `./engine-private/conf/${deployId}/conf.server.json`;
|
|
98
|
+
const confServer = JSON.parse(fs.readFileSync(confServerPath, 'utf8'));
|
|
99
|
+
const { db } = confServer[host][path];
|
|
100
|
+
|
|
101
|
+
await DataBaseProvider.load({ apis: ['cron'], host, path, db });
|
|
102
|
+
|
|
103
|
+
/** @type {import('../api/cron/cron.model.js').CronModel} */
|
|
104
|
+
const Cron = DataBaseProvider.instance[`${host}${path}`].mongoose.models.Cron;
|
|
105
|
+
|
|
106
|
+
await Cron.deleteMany();
|
|
107
|
+
|
|
108
|
+
for (const cronInstance of UnderpostCron.NETWORK) {
|
|
109
|
+
logger.info('save', cronInstance);
|
|
110
|
+
await new Cron(cronInstance).save();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
logger.error(error, error.stack);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
87
118
|
};
|
|
88
119
|
}
|
|
89
120
|
|
package/src/cli/deploy.js
CHANGED
|
@@ -12,11 +12,12 @@ import { loggerFactory } from '../server/logger.js';
|
|
|
12
12
|
import { shellExec } from '../server/process.js';
|
|
13
13
|
import fs from 'fs-extra';
|
|
14
14
|
import dotenv from 'dotenv';
|
|
15
|
-
import
|
|
15
|
+
import { DataBaseProvider } from '../db/DataBaseProvider.js';
|
|
16
16
|
|
|
17
17
|
const logger = loggerFactory(import.meta);
|
|
18
18
|
|
|
19
19
|
class UnderpostDeploy {
|
|
20
|
+
static NETWORK = {};
|
|
20
21
|
static API = {
|
|
21
22
|
sync(deployList) {
|
|
22
23
|
const deployGroupId = 'dd.tmp';
|
|
@@ -50,7 +51,7 @@ class UnderpostDeploy {
|
|
|
50
51
|
if (env === 'development') fs.mkdirSync(`./manifests/deployment/${deployId}-${env}`, { recursive: true });
|
|
51
52
|
|
|
52
53
|
logger.info('port range', { deployId, fromPort, toPort });
|
|
53
|
-
// const customImg = `underpost-engine:${version && typeof version === 'string' ? version :
|
|
54
|
+
// const customImg = `underpost-engine:${version && typeof version === 'string' ? version : '0.0.0'}`;
|
|
54
55
|
// lifecycle:
|
|
55
56
|
// postStart:
|
|
56
57
|
// exec:
|
|
@@ -85,11 +86,7 @@ spec:
|
|
|
85
86
|
- -c
|
|
86
87
|
- >
|
|
87
88
|
npm install -g npm@11.2.0 &&
|
|
88
|
-
npm
|
|
89
|
-
npm config delete http-proxy &&
|
|
90
|
-
npm config delete https-proxy &&
|
|
91
|
-
npm config set registry http://registry.npmjs.org/ &&
|
|
92
|
-
npm install --unsafe-perm --ignore-scripts -g underpost &&
|
|
89
|
+
npm install -g underpost &&
|
|
93
90
|
underpost secret underpost --create-from-file /etc/config/.env.${env} &&
|
|
94
91
|
underpost dockerfile-node-script --build --run ${deployId} ${env}
|
|
95
92
|
volumeMounts:
|
|
@@ -99,7 +96,7 @@ spec:
|
|
|
99
96
|
- name: config-volume
|
|
100
97
|
configMap:
|
|
101
98
|
name: underpost-config
|
|
102
|
-
# image: localhost/${deployId}-${env}:${version && typeof version === 'string' ? version :
|
|
99
|
+
# image: localhost/${deployId}-${env}:${version && typeof version === 'string' ? version : '0.0.0'}
|
|
103
100
|
---
|
|
104
101
|
apiVersion: v1
|
|
105
102
|
kind: Service
|
|
@@ -200,6 +197,7 @@ spec:
|
|
|
200
197
|
expose: false,
|
|
201
198
|
cert: false,
|
|
202
199
|
version: '',
|
|
200
|
+
dashboardUpdate: false,
|
|
203
201
|
},
|
|
204
202
|
) {
|
|
205
203
|
if (options.infoUtil === true)
|
|
@@ -212,8 +210,9 @@ kubectl scale statefulsets <stateful-set-name> --replicas=<new-replicas>
|
|
|
212
210
|
deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
|
|
213
211
|
if (options.sync) UnderpostDeploy.API.sync(deployList);
|
|
214
212
|
if (options.buildManifest === true) await UnderpostDeploy.API.buildManifest(deployList, env, options.version);
|
|
215
|
-
if (options.infoRouter === true)
|
|
216
|
-
|
|
213
|
+
if (options.infoRouter === true) logger.info('router', await UnderpostDeploy.API.routerFactory(deployList, env));
|
|
214
|
+
if (options.dashboardUpdate === true) await UnderpostDeploy.API.updateDashboardData(deployList, env, options);
|
|
215
|
+
if (options.infoRouter === true) return;
|
|
217
216
|
shellExec(`kubectl delete configmap underpost-config`);
|
|
218
217
|
shellExec(
|
|
219
218
|
`kubectl create configmap underpost-config --from-file=/home/dd/engine/engine-private/conf/dd-cron/.env.${env}`,
|
|
@@ -316,6 +315,60 @@ kubectl scale statefulsets <stateful-set-name> --replicas=<new-replicas>
|
|
|
316
315
|
|
|
317
316
|
return result;
|
|
318
317
|
},
|
|
318
|
+
async updateDashboardData(deployList, env, options) {
|
|
319
|
+
try {
|
|
320
|
+
const deployId = process.env.DEFAULT_DEPLOY_ID;
|
|
321
|
+
const host = process.env.DEFAULT_DEPLOY_HOST;
|
|
322
|
+
const path = process.env.DEFAULT_DEPLOY_PATH;
|
|
323
|
+
const { db } = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'))[host][
|
|
324
|
+
path
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
await DataBaseProvider.load({ apis: ['instance'], host, path, db });
|
|
328
|
+
|
|
329
|
+
/** @type {import('../api/instance/instance.model.js').InstanceModel} */
|
|
330
|
+
const Instance = DataBaseProvider.instance[`${host}${path}`].mongoose.models.Instance;
|
|
331
|
+
|
|
332
|
+
await Instance.deleteMany();
|
|
333
|
+
|
|
334
|
+
for (const _deployId of deployList.split(',')) {
|
|
335
|
+
const deployId = _deployId.trim();
|
|
336
|
+
if (!deployId) continue;
|
|
337
|
+
const confServer = loadReplicas(
|
|
338
|
+
JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8')),
|
|
339
|
+
'proxy',
|
|
340
|
+
);
|
|
341
|
+
const router = await UnderpostDeploy.API.routerFactory(deployId, env);
|
|
342
|
+
const pathPortAssignmentData = pathPortAssignmentFactory(router, confServer);
|
|
343
|
+
|
|
344
|
+
for (const host of Object.keys(confServer)) {
|
|
345
|
+
for (const { path, port } of pathPortAssignmentData[host]) {
|
|
346
|
+
if (!confServer[host][path]) continue;
|
|
347
|
+
|
|
348
|
+
const { client, runtime, apis } = confServer[host][path];
|
|
349
|
+
|
|
350
|
+
const body = {
|
|
351
|
+
deployId,
|
|
352
|
+
host,
|
|
353
|
+
path,
|
|
354
|
+
port,
|
|
355
|
+
client,
|
|
356
|
+
runtime,
|
|
357
|
+
apis,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
logger.info('save', body);
|
|
361
|
+
|
|
362
|
+
await new Instance(body).save();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
|
|
368
|
+
} catch (error) {
|
|
369
|
+
logger.error(error, error.stack);
|
|
370
|
+
}
|
|
371
|
+
},
|
|
319
372
|
};
|
|
320
373
|
}
|
|
321
374
|
|
package/src/cli/fs.js
CHANGED
|
@@ -38,7 +38,7 @@ class UnderpostFileStorage {
|
|
|
38
38
|
options = { rm: false, recursive: false, deployId: '', force: false, pull: false, git: false },
|
|
39
39
|
) {
|
|
40
40
|
const { storage, storageConf } = UnderpostFileStorage.API.getStorageConf(options);
|
|
41
|
-
const deleteFiles = UnderpostRepository.API.getDeleteFiles(path);
|
|
41
|
+
const deleteFiles = options.pull === true ? [] : UnderpostRepository.API.getDeleteFiles(path);
|
|
42
42
|
for (const relativePath of deleteFiles) {
|
|
43
43
|
const _path = path + '/' + relativePath;
|
|
44
44
|
if (_path in storage) {
|
|
@@ -46,10 +46,6 @@ class UnderpostFileStorage {
|
|
|
46
46
|
delete storage[_path];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
const files =
|
|
50
|
-
options.git === true
|
|
51
|
-
? UnderpostRepository.API.getChangedFiles(path)
|
|
52
|
-
: await fs.readdir(path, { recursive: true });
|
|
53
49
|
if (options.pull === true) {
|
|
54
50
|
for (const _path of Object.keys(storage)) {
|
|
55
51
|
if (!fs.existsSync(_path) || options.force === true) {
|
|
@@ -57,7 +53,11 @@ class UnderpostFileStorage {
|
|
|
57
53
|
await UnderpostFileStorage.API.pull(_path, options);
|
|
58
54
|
} else logger.warn(`Pull path already exists`, _path);
|
|
59
55
|
}
|
|
60
|
-
} else
|
|
56
|
+
} else {
|
|
57
|
+
const files =
|
|
58
|
+
options.git === true
|
|
59
|
+
? UnderpostRepository.API.getChangedFiles(path)
|
|
60
|
+
: await fs.readdir(path, { recursive: true });
|
|
61
61
|
for (const relativePath of files) {
|
|
62
62
|
const _path = path + '/' + relativePath;
|
|
63
63
|
if (fs.statSync(_path).isDirectory()) {
|
|
@@ -68,6 +68,7 @@ class UnderpostFileStorage {
|
|
|
68
68
|
if (storage) storage[_path] = {};
|
|
69
69
|
} else logger.warn('File already exists', _path);
|
|
70
70
|
}
|
|
71
|
+
}
|
|
71
72
|
UnderpostFileStorage.API.writeStorageConf(storage, storageConf);
|
|
72
73
|
if (options.git === true) {
|
|
73
74
|
shellExec(`cd ${path} && git add .`);
|
package/src/cli/image.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
|
-
import Underpost from '../index.js';
|
|
3
2
|
import { shellCd, shellExec } from '../server/process.js';
|
|
4
3
|
import dotenv from 'dotenv';
|
|
5
4
|
import { awaitDeployMonitor, getNpmRootPath } from '../server/conf.js';
|
|
6
|
-
import { timer } from '../client/components/core/CommonJs.js';
|
|
7
5
|
import { loggerFactory } from '../server/logger.js';
|
|
8
6
|
import UnderpostMonitor from './monitor.js';
|
|
9
7
|
|
|
@@ -18,41 +16,49 @@ class UnderpostImage {
|
|
|
18
16
|
shellExec(`sudo podman pull docker.io/library/debian:buster`);
|
|
19
17
|
},
|
|
20
18
|
build(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
options = {
|
|
20
|
+
path: '',
|
|
21
|
+
imageName: '',
|
|
22
|
+
imagePath: '',
|
|
23
|
+
dockerfileName: '',
|
|
24
|
+
podmanSave: false,
|
|
25
|
+
kindLoad: false,
|
|
26
|
+
secrets: false,
|
|
27
|
+
secretsPath: '',
|
|
28
|
+
noCache: false,
|
|
29
|
+
},
|
|
25
30
|
) {
|
|
26
|
-
const
|
|
27
|
-
options
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
if (!fs.existsSync(`${path}${imagesStoragePath}`))
|
|
34
|
-
fs.mkdirSync(`${path}${imagesStoragePath}`, { recursive: true });
|
|
35
|
-
const tarFile = `.${imagesStoragePath}/${imgName.replace(':', '_')}.tar`;
|
|
36
|
-
|
|
37
|
-
let secrets = ' ';
|
|
31
|
+
const { path, imageName, imagePath, dockerfileName, podmanSave, secrets, secretsPath, kindLoad, noCache } =
|
|
32
|
+
options;
|
|
33
|
+
const podManImg = `localhost/${imageName}`;
|
|
34
|
+
if (imagePath && typeof imagePath === 'string' && !fs.existsSync(imagePath))
|
|
35
|
+
fs.mkdirSync(imagePath, { recursive: true });
|
|
36
|
+
const tarFile = `${imagePath}/${imageName.replace(':', '_')}.tar`;
|
|
37
|
+
let secretsInput = ' ';
|
|
38
38
|
let secretDockerInput = '';
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
let cache = '';
|
|
40
|
+
if (secrets === true) {
|
|
41
|
+
const envObj = dotenv.parse(
|
|
42
|
+
fs.readFileSync(
|
|
43
|
+
secretsPath && typeof secretsPath === 'string' ? secretsPath : `${getNpmRootPath()}/underpost/.env`,
|
|
44
|
+
'utf8',
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
for (const key of Object.keys(envObj)) {
|
|
48
|
+
secretsInput += ` && export ${key}="${envObj[key]}" `; // $(cat gitlab-token.txt)
|
|
49
|
+
secretDockerInput += ` --secret id=${key},env=${key} \ `;
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
|
-
|
|
48
|
-
if (
|
|
52
|
+
if (noCache === true) cache += ' --rm --no-cache';
|
|
53
|
+
if (path && typeof path === 'string')
|
|
49
54
|
shellExec(
|
|
50
|
-
`cd ${path}${
|
|
55
|
+
`cd ${path}${secretsInput}&& sudo podman build -f ./${
|
|
56
|
+
dockerfileName && typeof dockerfileName === 'string' ? dockerfileName : 'Dockerfile'
|
|
57
|
+
} -t ${imageName} --pull=never --cap-add=CAP_AUDIT_WRITE${cache}${secretDockerInput}`,
|
|
51
58
|
);
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
shellExec(`cd ${path} && sudo kind load image-archive ${tarFile}`);
|
|
59
|
+
|
|
60
|
+
if (podmanSave === true) shellExec(`podman save -o ${tarFile} ${podManImg}`);
|
|
61
|
+
if (kindLoad === true) shellExec(`sudo kind load image-archive ${tarFile}`);
|
|
56
62
|
},
|
|
57
63
|
async script(deployId = 'default', env = 'development', options = { run: false, build: false }) {
|
|
58
64
|
if (options.build === true) {
|
|
@@ -63,7 +69,8 @@ class UnderpostImage {
|
|
|
63
69
|
shellExec(`cd ${buildBasePath}/engine && underpost clone underpostnet/${repoName}-private`);
|
|
64
70
|
shellExec(`cd ${buildBasePath}/engine && sudo mv ./${repoName}-private ./engine-private`);
|
|
65
71
|
shellCd(`${buildBasePath}/engine`);
|
|
66
|
-
shellExec(`
|
|
72
|
+
shellExec(`npm install`);
|
|
73
|
+
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
67
74
|
if (fs.existsSync('./engine-private/itc-scripts')) {
|
|
68
75
|
const itcScripts = await fs.readdir('./engine-private/itc-scripts');
|
|
69
76
|
for (const itcScript of itcScripts)
|
|
@@ -102,7 +109,6 @@ class UnderpostImage {
|
|
|
102
109
|
}
|
|
103
110
|
break;
|
|
104
111
|
}
|
|
105
|
-
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
106
112
|
shellExec(`node bin/deploy build-full-client ${deployId}`);
|
|
107
113
|
}
|
|
108
114
|
if (options.run === true) {
|