underpost 2.8.41 → 2.8.43
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 +1 -1
- package/bin/build.js +22 -17
- package/bin/deploy.js +2 -7
- package/bin/index.js +31 -9
- package/docker-compose.yml +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -3
- package/src/server/conf.js +58 -1
- package/src/server/runtime.js +8 -22
- package/src/server/project.js +0 -39
package/Dockerfile
CHANGED
|
@@ -32,7 +32,7 @@ COPY supervisord-openssh-server.conf /etc/supervisor/conf.d/supervisord-openssh-
|
|
|
32
32
|
RUN apt-get install -yq --no-install-recommends libssl-dev curl wget git gnupg
|
|
33
33
|
|
|
34
34
|
# install nodejs https://github.com/nodesource/distributions/blob/master/README.md#deb
|
|
35
|
-
RUN curl -fsSL https://deb.nodesource.com/
|
|
35
|
+
RUN curl -fsSL https://deb.nodesource.com/setup_23.x | bash -
|
|
36
36
|
RUN apt-get install -y nodejs build-essential
|
|
37
37
|
RUN node --version
|
|
38
38
|
RUN npm --version
|
package/bin/build.js
CHANGED
|
@@ -19,16 +19,17 @@ const logger = loggerFactory(import.meta);
|
|
|
19
19
|
|
|
20
20
|
const confName = process.argv[2];
|
|
21
21
|
const basePath = '../pwa-microservices-template';
|
|
22
|
-
const repoName = `engine-${confName.split('dd-')[1]}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
22
|
+
const repoName = `engine-${confName.split('dd-')[1]}`;
|
|
23
|
+
const privateRepoName = `${repoName}-private`;
|
|
24
|
+
const privateRepoNameBackUp = `${repoName}-cron-backups`;
|
|
25
|
+
const gitPrivateUrl = `https://${process.env.GITHUB_TOKEN}@github.com/underpostnet/${privateRepoName}.git`;
|
|
26
|
+
const gitPrivateBackUpUrl = `https://${process.env.GITHUB_TOKEN}@github.com/underpostnet/${privateRepoNameBackUp}.git`;
|
|
26
27
|
|
|
27
28
|
logger.info('', {
|
|
28
29
|
confName,
|
|
29
|
-
// gitUrl,
|
|
30
30
|
repoName,
|
|
31
|
-
|
|
31
|
+
privateRepoName,
|
|
32
|
+
privateRepoNameBackUp,
|
|
32
33
|
basePath,
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -150,17 +151,17 @@ spec:
|
|
|
150
151
|
process.exit(0);
|
|
151
152
|
}
|
|
152
153
|
if (process.argv.includes('conf')) {
|
|
153
|
-
if (!fs.existsSync(`../${
|
|
154
|
-
shellExec(`cd .. && git clone ${
|
|
154
|
+
if (!fs.existsSync(`../${privateRepoName}`)) {
|
|
155
|
+
shellExec(`cd .. && git clone ${gitPrivateUrl}`, { silent: true });
|
|
155
156
|
} else {
|
|
156
|
-
shellExec(`cd ../${
|
|
157
|
+
shellExec(`cd ../${privateRepoName} && git pull`);
|
|
157
158
|
}
|
|
158
|
-
const toPath = `../${
|
|
159
|
+
const toPath = `../${privateRepoName}/conf/${confName}`;
|
|
159
160
|
fs.removeSync(toPath);
|
|
160
161
|
fs.mkdirSync(toPath, { recursive: true });
|
|
161
162
|
fs.copySync(`./engine-private/conf/${confName}`, toPath);
|
|
162
163
|
shellExec(
|
|
163
|
-
`cd ../${
|
|
164
|
+
`cd ../${privateRepoName}` +
|
|
164
165
|
` && git add .` +
|
|
165
166
|
` && git commit -m "ci(engine-core-conf): ⚙️ Update ${confName} conf"` +
|
|
166
167
|
` && git push`,
|
|
@@ -169,16 +170,16 @@ if (process.argv.includes('conf')) {
|
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
if (process.argv.includes('cron-backups')) {
|
|
172
|
-
if (!fs.existsSync(`../${
|
|
173
|
-
shellExec(`cd .. && git clone ${
|
|
173
|
+
if (!fs.existsSync(`../${privateRepoNameBackUp}`)) {
|
|
174
|
+
shellExec(`cd .. && git clone ${gitPrivateBackUpUrl}`, { silent: true });
|
|
174
175
|
} else {
|
|
175
|
-
shellExec(`cd ../${
|
|
176
|
+
shellExec(`cd ../${privateRepoNameBackUp} && git pull`);
|
|
176
177
|
}
|
|
177
178
|
const serverConf = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.server.json`, 'utf8'));
|
|
178
179
|
for (const host of Object.keys(serverConf)) {
|
|
179
180
|
for (let path of Object.keys(serverConf[host])) {
|
|
180
181
|
path = path.replaceAll('/', '-');
|
|
181
|
-
const toPath = `../${
|
|
182
|
+
const toPath = `../${privateRepoNameBackUp}/${host}${path}`;
|
|
182
183
|
const fromPath = `./engine-private/cron-backups/${host}${path}`;
|
|
183
184
|
if (fs.existsSync(fromPath)) {
|
|
184
185
|
if (fs.existsSync(toPath)) fs.removeSync(toPath);
|
|
@@ -188,7 +189,7 @@ if (process.argv.includes('cron-backups')) {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
shellExec(
|
|
191
|
-
`cd ../${
|
|
192
|
+
`cd ../${privateRepoNameBackUp}` +
|
|
192
193
|
` && git add .` +
|
|
193
194
|
` && git commit -m "ci(engine-core-cron-backups): ⚙️ Update ${confName} cron backups"` +
|
|
194
195
|
` && git push`,
|
|
@@ -274,5 +275,9 @@ const { DefaultConf } = await import(`../conf.${confName}.js`);
|
|
|
274
275
|
|
|
275
276
|
const packageJson = JSON.parse(fs.readFileSync(`${basePath}/package.json`, 'utf8'));
|
|
276
277
|
packageJson.name = repoName;
|
|
277
|
-
fs.writeFileSync(
|
|
278
|
+
fs.writeFileSync(
|
|
279
|
+
`${basePath}/package.json`,
|
|
280
|
+
JSON.stringify(packageJson, null, 4).replaceAll('pwa-microservices-template', repoName),
|
|
281
|
+
'utf8',
|
|
282
|
+
);
|
|
278
283
|
}
|
package/bin/deploy.js
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
restoreMacroDb,
|
|
27
27
|
fixDependencies,
|
|
28
28
|
setUpProxyMaintenanceServer,
|
|
29
|
+
writeEnv,
|
|
29
30
|
} from '../src/server/conf.js';
|
|
30
31
|
import { buildClient } from '../src/server/client-build.js';
|
|
31
32
|
import { range, setPad, timer, uniqueArray } from '../src/client/components/core/CommonJs.js';
|
|
@@ -546,13 +547,7 @@ try {
|
|
|
546
547
|
? envInstanceObj.port
|
|
547
548
|
: envInstanceObj.port + port - singleReplicaHosts.length - (replicaHost ? 1 : 0);
|
|
548
549
|
|
|
549
|
-
|
|
550
|
-
envPath,
|
|
551
|
-
Object.keys(envObj)
|
|
552
|
-
.map((key) => `${key}=${envObj[key]}`)
|
|
553
|
-
.join(`\n`),
|
|
554
|
-
'utf8',
|
|
555
|
-
);
|
|
550
|
+
writeEnv(envPath, envObj);
|
|
556
551
|
}
|
|
557
552
|
const serverConf = loadReplicas(
|
|
558
553
|
JSON.parse(fs.readFileSync(`${baseConfPath}/${deployId}/conf.server.json`, 'utf8')),
|
package/bin/index.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
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 {
|
|
8
|
+
getNpmRootPath,
|
|
9
|
+
loadConf,
|
|
10
|
+
newProject,
|
|
11
|
+
repoClone,
|
|
12
|
+
repoCommit,
|
|
13
|
+
repoPull,
|
|
14
|
+
repoPush,
|
|
15
|
+
UnderpostRootEnv,
|
|
16
|
+
} from '../src/server/conf.js';
|
|
17
|
+
import fs from 'fs-extra';
|
|
8
18
|
|
|
9
|
-
|
|
19
|
+
const npmRoot = getNpmRootPath();
|
|
20
|
+
const underpostRoot = `${npmRoot}/underpost/.env`;
|
|
21
|
+
fs.existsSync(underpostRoot) ? dotenv.config({ path: underpostRoot, override: true }) : dotenv.config();
|
|
10
22
|
|
|
11
23
|
const logger = loggerFactory(import.meta);
|
|
12
24
|
|
|
@@ -17,17 +29,17 @@ program.name('underpost').description(`underpost.net ci/cd cli ${Underpost.versi
|
|
|
17
29
|
program
|
|
18
30
|
.command('new <app-name>')
|
|
19
31
|
.description('Create a new project')
|
|
20
|
-
.action((...args) => ((args[1] = Underpost.version),
|
|
32
|
+
.action((...args) => ((args[1] = Underpost.version), newProject(...args)));
|
|
21
33
|
|
|
22
34
|
program
|
|
23
35
|
.command('clone <uri>')
|
|
24
36
|
.description('Clone github repository, if your GITHUB_TOKEN environment exists, it will be used')
|
|
25
|
-
.action(
|
|
37
|
+
.action(repoClone);
|
|
26
38
|
|
|
27
39
|
program
|
|
28
40
|
.command('pull <path> <uri>')
|
|
29
41
|
.description('Pull github repository, if your GITHUB_TOKEN environment exists, it will be used')
|
|
30
|
-
.action(
|
|
42
|
+
.action(repoPull);
|
|
31
43
|
|
|
32
44
|
program
|
|
33
45
|
.option('--copy')
|
|
@@ -37,17 +49,27 @@ program
|
|
|
37
49
|
.description(
|
|
38
50
|
'Commit github repository, if your GITHUB_TOKEN environment exists, it will be used, use --copy will copy to clipboard message, use --info will see info commit types, use --empty will allow empty files',
|
|
39
51
|
)
|
|
40
|
-
.action((...args) => ((args[4] = options),
|
|
52
|
+
.action((...args) => ((args[4] = options), repoCommit(...args)));
|
|
41
53
|
|
|
42
54
|
program
|
|
43
55
|
.command('push <path> <uri>')
|
|
44
56
|
.description('Push github repository, if your GITHUB_TOKEN environment exists, it will be used')
|
|
45
|
-
.action(
|
|
57
|
+
.action(repoPush);
|
|
46
58
|
|
|
47
59
|
program
|
|
48
60
|
.command('env <deploy-id> [env]')
|
|
49
61
|
.description('Set environment variables files and conf related to <deploy-id>')
|
|
50
|
-
.action(
|
|
62
|
+
.action(loadConf);
|
|
63
|
+
|
|
64
|
+
program
|
|
65
|
+
.command('config <operator> [key] [value]')
|
|
66
|
+
.description(`Manage configuration, operators available: ${Object.keys(UnderpostRootEnv)}`)
|
|
67
|
+
.action((...args) => UnderpostRootEnv[args[0]](args[1], args[2]));
|
|
68
|
+
|
|
69
|
+
program
|
|
70
|
+
.command('root')
|
|
71
|
+
.description('Set environment variables files and conf related to <deploy-id>')
|
|
72
|
+
.action(getNpmRootPath);
|
|
51
73
|
|
|
52
74
|
program.command('test').description('Run tests').action(Underpost.runTest);
|
|
53
75
|
|
package/docker-compose.yml
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
import { runTest } from './server/conf.js';
|
|
8
8
|
import { loggerFactory, setUpInfo } from './server/logger.js';
|
|
9
|
-
import Project from './server/project.js';
|
|
10
9
|
|
|
11
10
|
const logger = loggerFactory(import.meta);
|
|
12
11
|
|
|
@@ -22,8 +21,7 @@ class Underpost {
|
|
|
22
21
|
* @type {String}
|
|
23
22
|
* @memberof Underpost
|
|
24
23
|
*/
|
|
25
|
-
static version = 'v2.8.
|
|
26
|
-
static project = Project;
|
|
24
|
+
static version = 'v2.8.43';
|
|
27
25
|
|
|
28
26
|
constructor() {}
|
|
29
27
|
|
package/src/server/conf.js
CHANGED
|
@@ -127,7 +127,11 @@ const loadConf = (deployId, envInput) => {
|
|
|
127
127
|
...env,
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
const originPackageJson = JSON.parse(fs.readFileSync(`./package.json`, 'utf8'));
|
|
131
|
+
const packageJson = JSON.parse(fs.readFileSync(`${folder}/package.json`, 'utf8'));
|
|
132
|
+
originPackageJson.scripts.start = packageJson.scripts.start;
|
|
133
|
+
packageJson.scripts = originPackageJson.scripts;
|
|
134
|
+
fs.writeFileSync(`./package.json`, JSON.stringify(packageJson, null, 4), 'utf8');
|
|
131
135
|
return { folder, deployId };
|
|
132
136
|
};
|
|
133
137
|
|
|
@@ -1164,6 +1168,8 @@ const repoPush = (repoPath = './', gitUri = 'underpostnet/pwa-microservices-temp
|
|
|
1164
1168
|
const getNpmRootPath = () =>
|
|
1165
1169
|
shellExec(`npm root -g`, {
|
|
1166
1170
|
stdout: true,
|
|
1171
|
+
disableLog: true,
|
|
1172
|
+
silent: true,
|
|
1167
1173
|
}).trim();
|
|
1168
1174
|
|
|
1169
1175
|
const newProject = (repositoryName, version) => {
|
|
@@ -1197,6 +1203,55 @@ const runTest = (version) => {
|
|
|
1197
1203
|
shellExec(`cd ${getNpmRootPath()}/underpost && npm run test`);
|
|
1198
1204
|
};
|
|
1199
1205
|
|
|
1206
|
+
const writeEnv = (envPath, envObj) =>
|
|
1207
|
+
fs.writeFileSync(
|
|
1208
|
+
envPath,
|
|
1209
|
+
Object.keys(envObj)
|
|
1210
|
+
.map((key) => `${key}=${envObj[key]}`)
|
|
1211
|
+
.join(`\n`),
|
|
1212
|
+
'utf8',
|
|
1213
|
+
);
|
|
1214
|
+
|
|
1215
|
+
const UnderpostRootEnv = {
|
|
1216
|
+
set: (key, value) => {
|
|
1217
|
+
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
1218
|
+
const envPath = `${exeRootPath}/.env`;
|
|
1219
|
+
let env = {};
|
|
1220
|
+
if (fs.existsSync(envPath)) env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
|
|
1221
|
+
env[key] = value;
|
|
1222
|
+
writeEnv(envPath, env);
|
|
1223
|
+
},
|
|
1224
|
+
delete: (key, value) => {
|
|
1225
|
+
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
1226
|
+
const envPath = `${exeRootPath}/.env`;
|
|
1227
|
+
let env = {};
|
|
1228
|
+
if (fs.existsSync(envPath)) env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
|
|
1229
|
+
delete env[key];
|
|
1230
|
+
writeEnv(envPath, env);
|
|
1231
|
+
},
|
|
1232
|
+
get: (key) => {
|
|
1233
|
+
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
1234
|
+
const envPath = `${exeRootPath}/.env`;
|
|
1235
|
+
if (!fs.existsSync(envPath)) return logger.error(`Unable to find underpost root environment`);
|
|
1236
|
+
const env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
|
|
1237
|
+
logger.info('underpost root', { [key]: env[key] });
|
|
1238
|
+
return env[key];
|
|
1239
|
+
},
|
|
1240
|
+
list: () => {
|
|
1241
|
+
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
1242
|
+
const envPath = `${exeRootPath}/.env`;
|
|
1243
|
+
if (!fs.existsSync(envPath)) return logger.error(`Unable to find underpost root environment`);
|
|
1244
|
+
const env = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
|
|
1245
|
+
logger.info('underpost root', env);
|
|
1246
|
+
return env;
|
|
1247
|
+
},
|
|
1248
|
+
clean: () => {
|
|
1249
|
+
const exeRootPath = `${getNpmRootPath()}/underpost`;
|
|
1250
|
+
const envPath = `${exeRootPath}/.env`;
|
|
1251
|
+
fs.removeSync(envPath);
|
|
1252
|
+
},
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1200
1255
|
export {
|
|
1201
1256
|
Cmd,
|
|
1202
1257
|
Config,
|
|
@@ -1239,4 +1294,6 @@ export {
|
|
|
1239
1294
|
newProject,
|
|
1240
1295
|
runTest,
|
|
1241
1296
|
getNpmRootPath,
|
|
1297
|
+
writeEnv,
|
|
1298
|
+
UnderpostRootEnv,
|
|
1242
1299
|
};
|
package/src/server/runtime.js
CHANGED
|
@@ -15,7 +15,7 @@ import { getCapVariableName, newInstance } from '../client/components/core/Commo
|
|
|
15
15
|
import { Xampp } from '../runtime/xampp/Xampp.js';
|
|
16
16
|
import { MailerProvider } from '../mailer/MailerProvider.js';
|
|
17
17
|
import { DataBaseProvider } from '../db/DataBaseProvider.js';
|
|
18
|
-
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
18
|
+
// import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
19
19
|
import { createPeerServer } from './peer.js';
|
|
20
20
|
import { Lampp } from '../runtime/lampp/Lampp.js';
|
|
21
21
|
import { getDeployId } from './conf.js';
|
|
@@ -31,20 +31,6 @@ const buildRuntime = async () => {
|
|
|
31
31
|
const collectDefaultMetrics = promClient.collectDefaultMetrics;
|
|
32
32
|
collectDefaultMetrics();
|
|
33
33
|
|
|
34
|
-
if (fs.existsSync(`/root/.bashrc`) && !fs.readFileSync(`/root/.bashrc`, 'utf8').match(`underpost-engine`)) {
|
|
35
|
-
fs.writeFileSync(
|
|
36
|
-
`/root/.bashrc`,
|
|
37
|
-
`${fs.readFileSync(`/root/.bashrc`, 'utf8')}
|
|
38
|
-
` +
|
|
39
|
-
`export NVM_DIR="$HOME/.nvm"
|
|
40
|
-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
|
41
|
-
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm underpost-engine bash_completion
|
|
42
|
-
|
|
43
|
-
export PATH=$PATH:/opt/lampp/bin`,
|
|
44
|
-
'utf8',
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
34
|
const promCounterOption = {
|
|
49
35
|
name: `${deployId.replaceAll('-', '_')}_http_requests_total`,
|
|
50
36
|
help: 'Total number of HTTP requests',
|
|
@@ -54,7 +40,6 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
54
40
|
// logger.info('promCounterOption', promCounterOption);
|
|
55
41
|
|
|
56
42
|
const requestCounter = new promClient.Counter(promCounterOption);
|
|
57
|
-
|
|
58
43
|
const ipInstance = ''; // await ip.public.ipv4();
|
|
59
44
|
const initPort = parseInt(process.env.PORT) + 1;
|
|
60
45
|
let currentPort = initPort;
|
|
@@ -101,12 +86,13 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
101
86
|
apis,
|
|
102
87
|
};
|
|
103
88
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
89
|
+
const redirectTarget = redirect
|
|
90
|
+
? redirect[redirect.length - 1] === '/'
|
|
91
|
+
? redirect.slice(0, -1)
|
|
92
|
+
: redirect
|
|
93
|
+
: undefined;
|
|
94
|
+
|
|
95
|
+
// if (redirect) logger.info('redirect', new URL(redirect));
|
|
110
96
|
|
|
111
97
|
switch (runtime) {
|
|
112
98
|
case 'lampp':
|
package/src/server/project.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { loadConf, newProject, repoClone, repoCommit, repoPull, repoPush } from './conf.js';
|
|
2
|
-
|
|
3
|
-
class Project {
|
|
4
|
-
constructor(repositoryName, version) {
|
|
5
|
-
return newProject(repositoryName, version);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static clone(gitUri = 'underpostnet/pwa-microservices-template') {
|
|
9
|
-
return repoClone(gitUri);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static useEnv(deployId = 'default', env = 'production') {
|
|
13
|
-
return loadConf(deployId, env);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static pull(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') {
|
|
17
|
-
return repoPull(repoPath, gitUri);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static commit(
|
|
21
|
-
repoPath = './',
|
|
22
|
-
commitType = 'feat',
|
|
23
|
-
subModule = '',
|
|
24
|
-
message = '',
|
|
25
|
-
options = {
|
|
26
|
-
copy: false,
|
|
27
|
-
info: false,
|
|
28
|
-
empty: false,
|
|
29
|
-
},
|
|
30
|
-
) {
|
|
31
|
-
return repoCommit(repoPath, commitType, subModule, message, options);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static push(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template') {
|
|
35
|
-
return repoPush(repoPath, gitUri);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default Project;
|