underpost 2.8.453 → 2.8.481
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 +3 -3
- package/bin/build.js +32 -191
- package/bin/deploy.js +3 -19
- package/bin/file.js +13 -2
- package/bin/index.js +29 -1
- package/docker-compose.yml +1 -1
- package/package.json +5 -1
- package/src/cli/cluster.js +3 -3
- package/src/cli/db.js +148 -0
- package/src/cli/deploy.js +277 -0
- package/src/cli/image.js +20 -13
- package/src/cli/repository.js +11 -17
- package/src/cli/test.js +52 -1
- package/src/client/components/core/Auth.js +22 -4
- package/src/client/components/core/CommonJs.js +9 -0
- package/src/client/components/core/Modal.js +0 -1
- 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/index.js +17 -1
- package/src/server/conf.js +25 -15
- package/src/server/logger.js +1 -0
- package/src/server/network.js +16 -6
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildKindPorts,
|
|
3
|
+
buildPortProxyRouter,
|
|
4
|
+
buildProxyRouter,
|
|
5
|
+
Config,
|
|
6
|
+
getDataDeploy,
|
|
7
|
+
loadReplicas,
|
|
8
|
+
} from '../server/conf.js';
|
|
9
|
+
import { loggerFactory } from '../server/logger.js';
|
|
10
|
+
import { shellExec } from '../server/process.js';
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import dotenv from 'dotenv';
|
|
13
|
+
import Underpost from '../index.js';
|
|
14
|
+
|
|
15
|
+
const logger = loggerFactory(import.meta);
|
|
16
|
+
|
|
17
|
+
class UnderpostDeploy {
|
|
18
|
+
static API = {
|
|
19
|
+
sync(deployList) {
|
|
20
|
+
const deployGroupId = '_dd';
|
|
21
|
+
fs.writeFileSync(`./engine-private/deploy/${deployGroupId}.json`, JSON.stringify(deployList.split(',')), 'utf8');
|
|
22
|
+
return getDataDeploy({
|
|
23
|
+
buildSingleReplica: true,
|
|
24
|
+
deployGroupId,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
async routerFactory(deployList, env) {
|
|
28
|
+
const initEnvPath = `./engine-private/conf/${deployList.split(',')[0]}/.env.${env}`;
|
|
29
|
+
const initEnvObj = dotenv.parse(fs.readFileSync(initEnvPath, 'utf8'));
|
|
30
|
+
process.env.PORT = initEnvObj.PORT;
|
|
31
|
+
process.env.NODE_ENV = env;
|
|
32
|
+
await Config.build(undefined, 'proxy', deployList);
|
|
33
|
+
return buildPortProxyRouter(env === 'development' ? 80 : 443, buildProxyRouter());
|
|
34
|
+
},
|
|
35
|
+
async buildManifest(deployList, env) {
|
|
36
|
+
for (const _deployId of deployList.split(',')) {
|
|
37
|
+
const deployId = _deployId.trim();
|
|
38
|
+
if (!deployId) continue;
|
|
39
|
+
|
|
40
|
+
const router = await UnderpostDeploy.API.routerFactory(deployId, env);
|
|
41
|
+
const ports = Object.values(router).map((p) => parseInt(p.split(':')[2]));
|
|
42
|
+
const fromPort = Math.min(...ports);
|
|
43
|
+
const toPort = Math.max(...ports);
|
|
44
|
+
const confServer = loadReplicas(
|
|
45
|
+
JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8')),
|
|
46
|
+
'proxy',
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
fs.mkdirSync(`./engine-private/conf/${deployId}/build/${env}`, { recursive: true });
|
|
50
|
+
if (env === 'development') fs.mkdirSync(`./manifests/deployment/${deployId}-${env}`, { recursive: true });
|
|
51
|
+
|
|
52
|
+
logger.info('port range', { deployId, fromPort, toPort });
|
|
53
|
+
|
|
54
|
+
const deploymentYamlParts = `apiVersion: apps/v1
|
|
55
|
+
kind: Deployment
|
|
56
|
+
metadata:
|
|
57
|
+
name: ${deployId}-${env}
|
|
58
|
+
labels:
|
|
59
|
+
app: ${deployId}-${env}
|
|
60
|
+
spec:
|
|
61
|
+
replicas: 2
|
|
62
|
+
selector:
|
|
63
|
+
matchLabels:
|
|
64
|
+
app: ${deployId}-${env}
|
|
65
|
+
template:
|
|
66
|
+
metadata:
|
|
67
|
+
labels:
|
|
68
|
+
app: ${deployId}-${env}
|
|
69
|
+
spec:
|
|
70
|
+
containers:
|
|
71
|
+
- name: ${deployId}-${env}
|
|
72
|
+
image: localhost/${deployId}-${env}:${Underpost.version}
|
|
73
|
+
---
|
|
74
|
+
apiVersion: v1
|
|
75
|
+
kind: Service
|
|
76
|
+
metadata:
|
|
77
|
+
name: ${deployId}-${env}-service
|
|
78
|
+
spec:
|
|
79
|
+
selector:
|
|
80
|
+
app: ${deployId}-${env}
|
|
81
|
+
ports:
|
|
82
|
+
type: LoadBalancer`.split('ports:');
|
|
83
|
+
deploymentYamlParts[1] =
|
|
84
|
+
buildKindPorts(fromPort, toPort) +
|
|
85
|
+
` type: LoadBalancer
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
fs.writeFileSync(
|
|
89
|
+
`./engine-private/conf/${deployId}/build/${env}/deployment.yaml`,
|
|
90
|
+
deploymentYamlParts.join(`ports:
|
|
91
|
+
`),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
let proxyYaml = '';
|
|
95
|
+
let secretYaml = '';
|
|
96
|
+
|
|
97
|
+
for (const host of Object.keys(confServer)) {
|
|
98
|
+
if (env === 'production')
|
|
99
|
+
secretYaml += `
|
|
100
|
+
---
|
|
101
|
+
apiVersion: cert-manager.io/v1
|
|
102
|
+
kind: Certificate
|
|
103
|
+
metadata:
|
|
104
|
+
name: ${host}
|
|
105
|
+
spec:
|
|
106
|
+
commonName: ${host}
|
|
107
|
+
dnsNames:
|
|
108
|
+
- ${host}
|
|
109
|
+
issuerRef:
|
|
110
|
+
name: letsencrypt-prod
|
|
111
|
+
kind: ClusterIssuer
|
|
112
|
+
secretName: ${host}`;
|
|
113
|
+
|
|
114
|
+
const pathPortConditions = [];
|
|
115
|
+
for (const path of Object.keys(confServer[host])) {
|
|
116
|
+
const { peer } = confServer[host][path];
|
|
117
|
+
if (!router[`${host}${path === '/' ? '' : path}`]) continue;
|
|
118
|
+
const port = parseInt(router[`${host}${path === '/' ? '' : path}`].split(':')[2]);
|
|
119
|
+
// logger.info('', { host, port, path });
|
|
120
|
+
pathPortConditions.push({
|
|
121
|
+
port,
|
|
122
|
+
path,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (peer) {
|
|
126
|
+
// logger.info('', { host, port: port + 1, path: '/peer' });
|
|
127
|
+
pathPortConditions.push({
|
|
128
|
+
port: port + 1,
|
|
129
|
+
path: '/peer',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// logger.info('', { host, pathPortConditions });
|
|
135
|
+
proxyYaml += `
|
|
136
|
+
---
|
|
137
|
+
apiVersion: projectcontour.io/v1
|
|
138
|
+
kind: HTTPProxy
|
|
139
|
+
metadata:
|
|
140
|
+
name: ${host}
|
|
141
|
+
spec:
|
|
142
|
+
virtualhost:
|
|
143
|
+
fqdn: ${host}${
|
|
144
|
+
env === 'development'
|
|
145
|
+
? ''
|
|
146
|
+
: `
|
|
147
|
+
tls:
|
|
148
|
+
secretName: ${host}`
|
|
149
|
+
}
|
|
150
|
+
routes:`;
|
|
151
|
+
for (const conditionObj of pathPortConditions) {
|
|
152
|
+
const { path, port } = conditionObj;
|
|
153
|
+
proxyYaml += `
|
|
154
|
+
- conditions:
|
|
155
|
+
- prefix: ${path}
|
|
156
|
+
enableWebsockets: true
|
|
157
|
+
services:
|
|
158
|
+
- name: ${deployId}-${env}-service
|
|
159
|
+
port: ${port}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const yamlPath = `./engine-private/conf/${deployId}/build/${env}/proxy.yaml`;
|
|
163
|
+
fs.writeFileSync(yamlPath, proxyYaml, 'utf8');
|
|
164
|
+
if (env === 'production') {
|
|
165
|
+
const yamlPath = `./engine-private/conf/${deployId}/build/${env}/secret.yaml`;
|
|
166
|
+
fs.writeFileSync(yamlPath, secretYaml, 'utf8');
|
|
167
|
+
} else {
|
|
168
|
+
const deploymentsFiles = ['Dockerfile', 'proxy.yaml', 'deployment.yaml'];
|
|
169
|
+
for (const file of deploymentsFiles) {
|
|
170
|
+
if (fs.existsSync(`./engine-private/conf/${deployId}/build/${env}/${file}`)) {
|
|
171
|
+
fs.copyFileSync(
|
|
172
|
+
`./engine-private/conf/${deployId}/build/${env}/${file}`,
|
|
173
|
+
`./manifests/deployment/${deployId}-${env}/${file}`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
async callback(
|
|
181
|
+
deployList = 'default',
|
|
182
|
+
env = 'development',
|
|
183
|
+
options = { remove: false, infoRouter: false, sync: false, buildManifest: false },
|
|
184
|
+
) {
|
|
185
|
+
if (deployList === 'dd' && fs.existsSync(`./engine-private/deploy/dd-router`))
|
|
186
|
+
deployList = fs.readFileSync(`./engine-private/deploy/dd-router`, 'utf8');
|
|
187
|
+
if (options.sync) UnderpostDeploy.API.sync(deployList);
|
|
188
|
+
if (options.buildManifest === true) await UnderpostDeploy.API.buildManifest(deployList, env);
|
|
189
|
+
if (options.infoRouter === true)
|
|
190
|
+
return logger.info('router', await UnderpostDeploy.API.routerFactory(deployList, env));
|
|
191
|
+
|
|
192
|
+
for (const _deployId of deployList.split(',')) {
|
|
193
|
+
const deployId = _deployId.trim();
|
|
194
|
+
if (!deployId) continue;
|
|
195
|
+
|
|
196
|
+
shellExec(`sudo kubectl delete svc ${deployId}-${env}-service`);
|
|
197
|
+
shellExec(`sudo kubectl delete deployment ${deployId}-${env}`);
|
|
198
|
+
|
|
199
|
+
const etcHost = (
|
|
200
|
+
concat,
|
|
201
|
+
) => `127.0.0.1 ${concat} localhost localhost.localdomain localhost4 localhost4.localdomain4
|
|
202
|
+
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6`;
|
|
203
|
+
let concatHots = '';
|
|
204
|
+
|
|
205
|
+
const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
|
|
206
|
+
for (const host of Object.keys(confServer)) {
|
|
207
|
+
shellExec(`sudo kubectl delete HTTPProxy ${host}`);
|
|
208
|
+
if (!options.remove === true && env === 'development') concatHots += ` ${host}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!options.remove === true) {
|
|
212
|
+
shellExec(`sudo kubectl apply -f ./manifests/deployment/${deployId}-${env}/deployment.yaml`);
|
|
213
|
+
shellExec(`sudo kubectl apply -f ./manifests/deployment/${deployId}-${env}/proxy.yaml`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let renderHosts;
|
|
217
|
+
|
|
218
|
+
switch (process.platform) {
|
|
219
|
+
case 'linux':
|
|
220
|
+
{
|
|
221
|
+
switch (env) {
|
|
222
|
+
case 'development':
|
|
223
|
+
renderHosts = etcHost(concatHots);
|
|
224
|
+
fs.writeFileSync(`/etc/hosts`, renderHosts, 'utf8');
|
|
225
|
+
|
|
226
|
+
break;
|
|
227
|
+
|
|
228
|
+
default:
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
default:
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
logger.info(
|
|
238
|
+
`
|
|
239
|
+
` + renderHosts,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
getPods(deployId) {
|
|
244
|
+
const raw = shellExec(`sudo kubectl get pods --all-namespaces -o wide`, {
|
|
245
|
+
stdout: true,
|
|
246
|
+
disableLog: false,
|
|
247
|
+
silent: true,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const heads = raw
|
|
251
|
+
.split(`\n`)[0]
|
|
252
|
+
.split(' ')
|
|
253
|
+
.filter((_r) => _r.trim());
|
|
254
|
+
|
|
255
|
+
const pods = raw
|
|
256
|
+
.split(`\n`)
|
|
257
|
+
.filter((r) => (deployId ? r.match(deployId) : r.trim() && !r.match('NAME')))
|
|
258
|
+
.map((r) => r.split(' ').filter((_r) => _r.trim()));
|
|
259
|
+
|
|
260
|
+
const result = [];
|
|
261
|
+
|
|
262
|
+
for (const row of pods) {
|
|
263
|
+
const pod = {};
|
|
264
|
+
let index = -1;
|
|
265
|
+
for (const head of heads) {
|
|
266
|
+
index++;
|
|
267
|
+
pod[head] = row[index];
|
|
268
|
+
}
|
|
269
|
+
result.push(pod);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return result;
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default UnderpostDeploy;
|
package/src/cli/image.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import Underpost from '../index.js';
|
|
3
3
|
import { shellExec } from '../server/process.js';
|
|
4
|
-
import { MariaDB } from '../db/mariadb/MariaDB.js';
|
|
5
4
|
import dotenv from 'dotenv';
|
|
6
5
|
import { getNpmRootPath } from '../server/conf.js';
|
|
6
|
+
import { timer } from '../client/components/core/CommonJs.js';
|
|
7
7
|
|
|
8
8
|
dotenv.config();
|
|
9
9
|
|
|
@@ -40,22 +40,11 @@ class UnderpostImage {
|
|
|
40
40
|
}
|
|
41
41
|
shellExec(`cd ${path} && sudo kind load image-archive ${tarFile}`);
|
|
42
42
|
},
|
|
43
|
-
async script(deployId = 'default', env = 'development') {
|
|
43
|
+
async script(deployId = 'default', env = 'development', options = { run: false }) {
|
|
44
44
|
switch (deployId) {
|
|
45
45
|
case 'dd-lampp':
|
|
46
46
|
{
|
|
47
47
|
const lamppPublicPath = '/xampp/htdocs/online';
|
|
48
|
-
if (process.argv.includes('test')) {
|
|
49
|
-
const { MARIADB_HOST, MARIADB_USER, MARIADB_PASSWORD, DD_LAMPP_TEST_DB_0 } = process.env;
|
|
50
|
-
|
|
51
|
-
await MariaDB.query({
|
|
52
|
-
host: MARIADB_HOST,
|
|
53
|
-
user: MARIADB_USER,
|
|
54
|
-
password: MARIADB_PASSWORD,
|
|
55
|
-
query: `SHOW TABLES FROM ${DD_LAMPP_TEST_DB_0}`,
|
|
56
|
-
});
|
|
57
|
-
process.exit(0);
|
|
58
|
-
}
|
|
59
48
|
shellExec(`sudo mkdir -p ${lamppPublicPath}`);
|
|
60
49
|
|
|
61
50
|
{
|
|
@@ -111,6 +100,24 @@ class UnderpostImage {
|
|
|
111
100
|
}
|
|
112
101
|
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
113
102
|
shellExec(`node bin/deploy build-full-client ${deployId}`);
|
|
103
|
+
if (options.run === true) {
|
|
104
|
+
const runCmd = env === 'production' ? 'prod-img' : 'dev-img';
|
|
105
|
+
if (fs.existsSync(`./engine-private/replica`)) {
|
|
106
|
+
const replicas = await fs.readdir(`./engine-private/replica`);
|
|
107
|
+
for (const replica of replicas) {
|
|
108
|
+
shellExec(`node bin/deploy conf ${replica} ${env}`);
|
|
109
|
+
shellExec(`npm run ${runCmd} ${replica} deploy`, { async: true });
|
|
110
|
+
fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
|
|
111
|
+
const monitor = async () => {
|
|
112
|
+
await timer(1000);
|
|
113
|
+
if (fs.existsSync(`./tmp/await-deploy`)) return await monitor();
|
|
114
|
+
};
|
|
115
|
+
await monitor();
|
|
116
|
+
}
|
|
117
|
+
shellExec(`node bin/deploy conf ${deployId} ${env}`);
|
|
118
|
+
}
|
|
119
|
+
shellExec(`npm run ${runCmd} ${deployId} deploy`);
|
|
120
|
+
}
|
|
114
121
|
},
|
|
115
122
|
},
|
|
116
123
|
};
|
package/src/cli/repository.js
CHANGED
|
@@ -4,6 +4,7 @@ import { pbcopy, shellExec } from '../server/process.js';
|
|
|
4
4
|
import { actionInitLog, loggerFactory } from '../server/logger.js';
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
6
|
import { getNpmRootPath } from '../server/conf.js';
|
|
7
|
+
import { listenPortController, listenServerFactory } from '../server/network.js';
|
|
7
8
|
|
|
8
9
|
dotenv.config();
|
|
9
10
|
|
|
@@ -14,7 +15,7 @@ class UnderpostRepository {
|
|
|
14
15
|
clone(gitUri = 'underpostnet/pwa-microservices-template', options = { bare: false }) {
|
|
15
16
|
const repoName = gitUri.split('/').pop();
|
|
16
17
|
if (fs.existsSync(`./${repoName}`)) fs.removeSync(`./${repoName}`);
|
|
17
|
-
|
|
18
|
+
shellExec(
|
|
18
19
|
`git clone ${options?.bare === true ? ` --bare ` : ''}https://${
|
|
19
20
|
process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''
|
|
20
21
|
}github.com/${gitUri}.git`,
|
|
@@ -22,16 +23,6 @@ class UnderpostRepository {
|
|
|
22
23
|
disableLog: true,
|
|
23
24
|
},
|
|
24
25
|
);
|
|
25
|
-
if (process.env.GITHUB_TOKEN) {
|
|
26
|
-
shellExec(
|
|
27
|
-
`git clone https://${
|
|
28
|
-
process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN}@` : ''
|
|
29
|
-
}github.com/${gitUri}-private.git`,
|
|
30
|
-
);
|
|
31
|
-
fs.moveSync(`./${repoName}-private`, `./${repoName}/engine-private`, {
|
|
32
|
-
overwrite: true,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
26
|
},
|
|
36
27
|
pull(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') {
|
|
37
28
|
shellExec(
|
|
@@ -54,6 +45,10 @@ class UnderpostRepository {
|
|
|
54
45
|
empty: false,
|
|
55
46
|
},
|
|
56
47
|
) {
|
|
48
|
+
if (commitType === 'reset') {
|
|
49
|
+
shellExec(`cd ${repoPath} && git reset --soft HEAD~${isNaN(parseInt(subModule)) ? 1 : parseInt(subModule)}`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
57
52
|
if (options.info) return logger.info('', commitData);
|
|
58
53
|
const _message = `${commitType}${subModule ? `(${subModule})` : ''}${process.argv.includes('!') ? '!' : ''}: ${
|
|
59
54
|
commitData[commitType].emoji
|
|
@@ -82,19 +77,18 @@ class UnderpostRepository {
|
|
|
82
77
|
new(repositoryName) {
|
|
83
78
|
return new Promise(async (resolve, reject) => {
|
|
84
79
|
try {
|
|
85
|
-
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
86
|
-
// const exeRootPath = '/home/dd/pwa-microservices-template';
|
|
87
|
-
actionInitLog();
|
|
88
80
|
await logger.setUpInfo();
|
|
89
|
-
|
|
81
|
+
if (repositoryName === 'service') return resolve(await listenPortController(listenServerFactory(), ':'));
|
|
82
|
+
else actionInitLog();
|
|
83
|
+
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
84
|
+
const destFolder = `./${repositoryName}`;
|
|
90
85
|
logger.info('Note: This process may take several minutes to complete');
|
|
91
86
|
logger.info('build app', { destFolder });
|
|
87
|
+
if (fs.existsSync(destFolder)) fs.removeSync(destFolder);
|
|
92
88
|
fs.mkdirSync(destFolder, { recursive: true });
|
|
93
89
|
fs.copySync(exeRootPath, destFolder);
|
|
94
|
-
if (fs.existsSync(`${destFolder}/node_modules`)) fs.removeSync(`${destFolder}/node_modules`);
|
|
95
90
|
fs.writeFileSync(`${destFolder}/.gitignore`, fs.readFileSync(`${exeRootPath}/.dockerignore`, 'utf8'), 'utf8');
|
|
96
91
|
shellExec(`cd ${destFolder} && git init && git add . && git commit -m "Base template implementation"`);
|
|
97
|
-
shellExec(`cd ${destFolder} && underpost install`);
|
|
98
92
|
shellExec(`cd ${destFolder} && npm run build`);
|
|
99
93
|
shellExec(`cd ${destFolder} && npm run dev`);
|
|
100
94
|
return resolve();
|
package/src/cli/test.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { MariaDB } from '../db/mariadb/MariaDB.js';
|
|
1
2
|
import { getNpmRootPath } from '../server/conf.js';
|
|
2
3
|
import { actionInitLog, loggerFactory } from '../server/logger.js';
|
|
3
|
-
import { shellExec } from '../server/process.js';
|
|
4
|
+
import { pbcopy, shellExec } from '../server/process.js';
|
|
5
|
+
import UnderpostDeploy from './deploy.js';
|
|
4
6
|
|
|
5
7
|
const logger = loggerFactory(import.meta);
|
|
6
8
|
|
|
@@ -26,6 +28,55 @@ class UnderpostTest {
|
|
|
26
28
|
actionInitLog();
|
|
27
29
|
shellExec(`cd ${getNpmRootPath()}/underpost && npm run test`);
|
|
28
30
|
},
|
|
31
|
+
async callback(deployList = '', options = { insideContainer: false, sh: false, logs: false }) {
|
|
32
|
+
if (options.sh === true || options.logs === true) {
|
|
33
|
+
const [pod] = UnderpostDeploy.API.getPods(deployList);
|
|
34
|
+
if (pod) {
|
|
35
|
+
if (options.sh) return pbcopy(`sudo kubectl exec -it ${pod.NAME} -- sh`);
|
|
36
|
+
if (options.logs) return shellExec(`sudo kubectl logs -f ${pod.NAME}`);
|
|
37
|
+
}
|
|
38
|
+
return logger.warn(`Couldn't find pods in deployment`, deployList);
|
|
39
|
+
}
|
|
40
|
+
if (deployList) {
|
|
41
|
+
for (const _deployId of deployList.split(',')) {
|
|
42
|
+
const deployId = _deployId.trim();
|
|
43
|
+
if (!deployId) continue;
|
|
44
|
+
if (options.insideContainer === true)
|
|
45
|
+
switch (deployId) {
|
|
46
|
+
case 'dd-lampp':
|
|
47
|
+
{
|
|
48
|
+
const { MARIADB_HOST, MARIADB_USER, MARIADB_PASSWORD, DD_LAMPP_TEST_DB_0 } = process.env;
|
|
49
|
+
|
|
50
|
+
await MariaDB.query({
|
|
51
|
+
host: MARIADB_HOST,
|
|
52
|
+
user: MARIADB_USER,
|
|
53
|
+
password: MARIADB_PASSWORD,
|
|
54
|
+
query: `SHOW TABLES FROM ${DD_LAMPP_TEST_DB_0}`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
{
|
|
61
|
+
shellExec('npm run test');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const pods = UnderpostDeploy.API.getPods(deployId);
|
|
68
|
+
if (pods.length > 0)
|
|
69
|
+
for (const deployData of pods) {
|
|
70
|
+
const { NAME } = deployData;
|
|
71
|
+
shellExec(
|
|
72
|
+
`sudo kubectl exec -i ${NAME} -- sh -c "cd /home/dd/engine && underpost test ${deployId} --inside-container"`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
else logger.warn(`Couldn't find pods in deployment`, { deployId });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} else return UnderpostTest.API.run();
|
|
79
|
+
},
|
|
29
80
|
};
|
|
30
81
|
}
|
|
31
82
|
|
|
@@ -3,7 +3,10 @@ import { Account } from './Account.js';
|
|
|
3
3
|
import { loggerFactory } from './Logger.js';
|
|
4
4
|
import { LogIn } from './LogIn.js';
|
|
5
5
|
import { LogOut } from './LogOut.js';
|
|
6
|
+
import { NotificationManager } from './NotificationManager.js';
|
|
6
7
|
import { SignUp } from './SignUp.js';
|
|
8
|
+
import { Translate } from './Translate.js';
|
|
9
|
+
import { s } from './VanillaJs.js';
|
|
7
10
|
|
|
8
11
|
const logger = loggerFactory(import.meta);
|
|
9
12
|
|
|
@@ -65,6 +68,7 @@ const Auth = {
|
|
|
65
68
|
const _result = await UserService.get({ id: 'auth' });
|
|
66
69
|
return {
|
|
67
70
|
status: _result.status,
|
|
71
|
+
message: _result.message,
|
|
68
72
|
data: {
|
|
69
73
|
user: _result.data,
|
|
70
74
|
},
|
|
@@ -77,6 +81,15 @@ const Auth = {
|
|
|
77
81
|
await Account.updateForm(data.user);
|
|
78
82
|
return { user: data.user };
|
|
79
83
|
}
|
|
84
|
+
if (message && message.match('expired'))
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
s(`.main-btn-log-in`).click();
|
|
87
|
+
NotificationManager.Push({
|
|
88
|
+
html: Translate.Render(`expired-session`),
|
|
89
|
+
status: 'warning',
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return await Auth.sessionOut();
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
// anon guest session
|
|
@@ -92,20 +105,25 @@ const Auth = {
|
|
|
92
105
|
|
|
93
106
|
this.setGuestToken(guestToken);
|
|
94
107
|
let { data, status, message } = await UserService.get({ id: 'auth' });
|
|
95
|
-
if (status === 'error')
|
|
108
|
+
if (status === 'error') {
|
|
109
|
+
if (message && message.match('expired')) {
|
|
110
|
+
localStorage.removeItem('jwt.g');
|
|
111
|
+
return await Auth.sessionOut();
|
|
112
|
+
} else throw new Error(message);
|
|
113
|
+
}
|
|
96
114
|
await Account.updateForm(data);
|
|
97
115
|
return { user: data };
|
|
98
116
|
} catch (error) {
|
|
99
117
|
logger.error(error);
|
|
100
|
-
localStorage.removeItem('jwt');
|
|
101
|
-
localStorage.removeItem('jwt.g');
|
|
102
118
|
return { user: UserMock.default };
|
|
103
119
|
}
|
|
104
120
|
},
|
|
105
121
|
sessionOut: async function () {
|
|
106
122
|
this.deleteToken();
|
|
107
123
|
localStorage.removeItem('jwt');
|
|
108
|
-
|
|
124
|
+
const result = await this.sessionIn();
|
|
125
|
+
await LogOut.Trigger(result);
|
|
126
|
+
return result;
|
|
109
127
|
},
|
|
110
128
|
};
|
|
111
129
|
|
|
@@ -573,6 +573,14 @@ const isValidFormat = (value, format) => {
|
|
|
573
573
|
}
|
|
574
574
|
};
|
|
575
575
|
|
|
576
|
+
const getCurrentTrace = () => {
|
|
577
|
+
try {
|
|
578
|
+
_stack;
|
|
579
|
+
} catch (error) {
|
|
580
|
+
return error.stack.split('is not defined')[1];
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
576
584
|
/**
|
|
577
585
|
* Returns the time difference between UTC time and local time, in minutes.
|
|
578
586
|
* @memberof CommonJS
|
|
@@ -943,6 +951,7 @@ export {
|
|
|
943
951
|
commonAdminGuard,
|
|
944
952
|
commonModeratorGuard,
|
|
945
953
|
isChileanIdentityDocument,
|
|
954
|
+
getCurrentTrace,
|
|
946
955
|
userRoleEnum,
|
|
947
956
|
commitData,
|
|
948
957
|
};
|
|
@@ -508,6 +508,10 @@ const TranslateCore = {
|
|
|
508
508
|
en: 'Invalid identity document',
|
|
509
509
|
es: 'Documento de identidad inválido',
|
|
510
510
|
};
|
|
511
|
+
Translate.Data['expired-session'] = {
|
|
512
|
+
en: 'Your session has expired. Please log in again.',
|
|
513
|
+
es: 'Su sesión ha expirado. Por favor, inicie sesión de nuevo.',
|
|
514
|
+
};
|
|
511
515
|
},
|
|
512
516
|
};
|
|
513
517
|
|
|
@@ -419,14 +419,6 @@ const isActiveTab = () => document.hasFocus();
|
|
|
419
419
|
const isActiveElement = (classSearch = '') =>
|
|
420
420
|
document.activeElement?.classList?.value?.match(classSearch) ? true : false;
|
|
421
421
|
|
|
422
|
-
const getCurrentTrace = () => {
|
|
423
|
-
try {
|
|
424
|
-
_stack;
|
|
425
|
-
} catch (error) {
|
|
426
|
-
return error.stack.split('is not defined')[1];
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
|
|
430
422
|
const isDevInstance = () => location.origin.match('localhost') && location.port;
|
|
431
423
|
|
|
432
424
|
const getDataFromInputFile = async (file) => Array.from(new Uint8Array(await file.arrayBuffer()));
|
|
@@ -460,7 +452,6 @@ export {
|
|
|
460
452
|
isNavigator,
|
|
461
453
|
getTimeZone,
|
|
462
454
|
getAllChildNodes,
|
|
463
|
-
getCurrentTrace,
|
|
464
455
|
isActiveTab,
|
|
465
456
|
isActiveElement,
|
|
466
457
|
isDevInstance,
|
|
@@ -22,41 +22,44 @@ const Worker = {
|
|
|
22
22
|
setTimeout(() => {
|
|
23
23
|
if ('onLine' in navigator && navigator.onLine) window.ononline();
|
|
24
24
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
if ('serviceWorker' in navigator) {
|
|
26
|
+
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
|
27
|
+
logger.info('The controller of current browsing context has changed.');
|
|
28
|
+
});
|
|
29
|
+
navigator.serviceWorker.ready.then((worker) => {
|
|
30
|
+
logger.info('Ready', worker);
|
|
31
|
+
// event message
|
|
32
|
+
navigator.serviceWorker.addEventListener('message', (event) => {
|
|
33
|
+
logger.info('Received event message', event.data);
|
|
34
|
+
const { status } = event.data;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
switch (status) {
|
|
37
|
+
case 'loader':
|
|
38
|
+
{
|
|
39
|
+
LoadingAnimation.RenderCurrentSrcLoad(event);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
default:
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
// if (navigator.serviceWorker.controller)
|
|
49
|
+
// navigator.serviceWorker.controller.postMessage({
|
|
50
|
+
// title: 'Hello from Client event message',
|
|
51
|
+
// });
|
|
52
|
+
|
|
53
|
+
// broadcast message
|
|
54
|
+
// const channel = new BroadcastChannel('sw-messages');
|
|
55
|
+
// channel.addEventListener('message', (event) => {
|
|
56
|
+
// logger.info('Received broadcast message', event.data);
|
|
57
|
+
// });
|
|
58
|
+
// channel.postMessage({ title: 'Hello from Client broadcast message' });
|
|
59
|
+
// channel.close();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
51
62
|
|
|
52
|
-
// broadcast message
|
|
53
|
-
// const channel = new BroadcastChannel('sw-messages');
|
|
54
|
-
// channel.addEventListener('message', (event) => {
|
|
55
|
-
// logger.info('Received broadcast message', event.data);
|
|
56
|
-
// });
|
|
57
|
-
// channel.postMessage({ title: 'Hello from Client broadcast message' });
|
|
58
|
-
// channel.close();
|
|
59
|
-
});
|
|
60
63
|
this.RouterInstance = router();
|
|
61
64
|
const isInstall = await this.status();
|
|
62
65
|
if (!isInstall) await this.install();
|