underpost 3.1.3 → 3.2.2
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/.env.example +0 -2
- package/.github/workflows/ghpkg.ci.yml +4 -4
- package/.github/workflows/npmpkg.ci.yml +28 -11
- package/.github/workflows/publish.ci.yml +6 -0
- package/.github/workflows/pwa-microservices-template-page.cd.yml +4 -5
- package/.github/workflows/pwa-microservices-template-test.ci.yml +3 -3
- package/.github/workflows/release.cd.yml +13 -8
- package/CHANGELOG.md +396 -1
- package/CLI-HELP.md +53 -6
- package/Dockerfile +4 -2
- package/README.md +3 -2
- package/bin/build.js +18 -12
- package/bin/deploy.js +177 -124
- package/bin/file.js +3 -0
- package/conf.js +3 -2
- package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +5 -2
- package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +5 -2
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +88 -74
- package/manifests/deployment/dd-test-development/proxy.yaml +13 -4
- package/manifests/deployment/playwright/deployment.yaml +1 -1
- package/nodemon.json +1 -1
- package/package.json +22 -15
- package/scripts/rhel-grpc-setup.sh +56 -0
- package/src/api/file/file.ref.json +18 -0
- package/src/api/user/user.service.js +8 -7
- package/src/cli/cluster.js +7 -7
- package/src/cli/db.js +726 -825
- package/src/cli/deploy.js +151 -93
- package/src/cli/env.js +19 -0
- package/src/cli/fs.js +5 -2
- package/src/cli/index.js +45 -2
- package/src/cli/kubectl.js +211 -0
- package/src/cli/release.js +284 -0
- package/src/cli/repository.js +434 -75
- package/src/cli/run.js +189 -34
- package/src/cli/secrets.js +73 -0
- package/src/cli/test.js +3 -3
- package/src/client/Default.index.js +3 -4
- package/src/client/components/core/AppStore.js +69 -0
- package/src/client/components/core/CalendarCore.js +2 -2
- package/src/client/components/core/DropDown.js +137 -17
- package/src/client/components/core/Keyboard.js +2 -2
- package/src/client/components/core/LogIn.js +2 -2
- package/src/client/components/core/LogOut.js +2 -2
- package/src/client/components/core/Modal.js +0 -1
- package/src/client/components/core/Panel.js +0 -1
- package/src/client/components/core/PanelForm.js +19 -19
- package/src/client/components/core/SocketIo.js +82 -29
- package/src/client/components/core/SocketIoHandler.js +75 -0
- package/src/client/components/core/Stream.js +143 -95
- package/src/client/components/core/Webhook.js +40 -7
- package/src/client/components/default/AppStoreDefault.js +5 -0
- package/src/client/components/default/LogInDefault.js +3 -3
- package/src/client/components/default/LogOutDefault.js +2 -2
- package/src/client/components/default/MenuDefault.js +5 -5
- package/src/client/components/default/SocketIoDefault.js +3 -51
- package/src/client/services/core/core.service.js +20 -8
- package/src/client/services/user/user.management.js +2 -2
- package/src/index.js +24 -1
- package/src/runtime/express/Dockerfile +4 -0
- package/src/runtime/express/Express.js +18 -1
- package/src/runtime/lampp/Dockerfile +13 -2
- package/src/runtime/lampp/Lampp.js +27 -4
- package/src/runtime/wp/Dockerfile +68 -0
- package/src/runtime/wp/Wp.js +639 -0
- package/src/server/auth.js +24 -1
- package/src/server/backup.js +57 -23
- package/src/server/client-build-docs.js +9 -2
- package/src/server/client-build.js +31 -31
- package/src/server/client-formatted.js +109 -57
- package/src/server/cron.js +23 -18
- package/src/server/ipfs-client.js +24 -1
- package/src/server/peer.js +8 -0
- package/src/server/runtime.js +25 -1
- package/src/server/start.js +3 -2
- package/src/ws/IoInterface.js +1 -10
- package/src/ws/IoServer.js +14 -33
- package/src/ws/core/channels/core.ws.chat.js +65 -20
- package/src/ws/core/channels/core.ws.mailer.js +113 -32
- package/src/ws/core/channels/core.ws.stream.js +90 -31
- package/src/ws/core/core.ws.connection.js +12 -33
- package/src/ws/core/core.ws.emit.js +10 -26
- package/src/ws/core/core.ws.server.js +25 -58
- package/src/ws/default/channels/default.ws.main.js +53 -12
- package/src/ws/default/default.ws.connection.js +26 -13
- package/src/ws/default/default.ws.server.js +30 -12
- package/src/client/components/default/ElementsDefault.js +0 -38
- package/src/ws/core/management/core.ws.chat.js +0 -8
- package/src/ws/core/management/core.ws.mailer.js +0 -16
- package/src/ws/core/management/core.ws.stream.js +0 -8
- package/src/ws/default/management/default.ws.main.js +0 -8
package/src/server/backup.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
import fs from 'fs-extra';
|
|
8
8
|
import { loggerFactory } from './logger.js';
|
|
9
|
-
import { shellExec } from './process.js';
|
|
10
9
|
import Underpost from '../index.js';
|
|
11
10
|
import { loadCronDeployEnv } from './conf.js';
|
|
12
11
|
|
|
@@ -21,42 +20,77 @@ class BackUp {
|
|
|
21
20
|
/**
|
|
22
21
|
* @method callback
|
|
23
22
|
* @description Initiates a backup operation for the specified deployment list.
|
|
24
|
-
*
|
|
23
|
+
* Orchestrates two backup phases per deployment:
|
|
24
|
+
* 1. Database export (MariaDB / MongoDB dump via `node bin db --export`).
|
|
25
|
+
* 2. Repository backup (git commit+push inside the deployment pod via `node bin db --repo-backup`).
|
|
26
|
+
*
|
|
27
|
+
* Commands are always forwarded to the host node via SSH because the CronJob
|
|
28
|
+
* container itself has no kubectl access. GITHUB_TOKEN and GITHUB_USERNAME
|
|
29
|
+
* are passed as ephemeral inline env vars so they never touch the host filesystem.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} deployList - Comma-separated list of deployment IDs.
|
|
25
32
|
* @param {Object} options - The options for the backup operation.
|
|
26
33
|
* @param {boolean} options.git - Whether to backup data using Git.
|
|
27
34
|
* @param {boolean} [options.k3s] - Use k3s cluster context.
|
|
28
35
|
* @param {boolean} [options.kind] - Use kind cluster context.
|
|
29
36
|
* @param {boolean} [options.kubeadm] - Use kubeadm cluster context.
|
|
30
|
-
* @param {boolean} [options.ssh] - Execute backup commands via SSH on the remote node.
|
|
31
37
|
* @memberof UnderpostBakcUp
|
|
32
38
|
*/
|
|
33
39
|
static callback = async function (deployList, options = { git: false }) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
const firstDeployId = deployList && deployList !== 'dd' ? deployList.split(',')[0].trim() : '';
|
|
41
|
+
const { ephemeral } = Underpost.repo.privateEngineRepoFactory(firstDeployId || undefined);
|
|
42
|
+
try {
|
|
43
|
+
loadCronDeployEnv();
|
|
44
|
+
if ((!deployList || deployList === 'dd') && fs.existsSync(`./engine-private/deploy/dd.router`))
|
|
45
|
+
deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8').trim();
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
logger.info('init backups callback', deployList);
|
|
48
|
+
await logger.setUpInfo();
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
const clusterFlag = options.k3s ? ' --k3s' : options.kind ? ' --kind' : options.kubeadm ? ' --kubeadm' : '';
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
for (const _deployId of deployList.split(',')) {
|
|
53
|
+
const deployId = _deployId.trim();
|
|
54
|
+
if (!deployId) continue;
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
const dbCommand = `node bin db ${options.git ? '--git --force-clone ' : ''}--export --primary-pod${clusterFlag} ${deployId}`;
|
|
57
|
+
const repoCommand = `node bin db --repo-backup${clusterFlag} ${deployId}`;
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
// Pass GITHUB_TOKEN and GITHUB_USERNAME ephemerally through the SSH command
|
|
60
|
+
// so git operations can push backups without relying on host env files.
|
|
61
|
+
const envPrefix = [
|
|
62
|
+
process.env.GITHUB_TOKEN ? `GITHUB_TOKEN=${process.env.GITHUB_TOKEN}` : '',
|
|
63
|
+
process.env.GITHUB_USERNAME ? `GITHUB_USERNAME=${process.env.GITHUB_USERNAME}` : '',
|
|
64
|
+
]
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join(' ');
|
|
67
|
+
const prefixCmd = (cmd) => (envPrefix ? `${envPrefix} ${cmd}` : cmd);
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
logger.info('Executing database export via SSH for', deployId);
|
|
71
|
+
await Underpost.ssh.sshRemoteRunner(prefixCmd(dbCommand), {
|
|
72
|
+
remote: true,
|
|
73
|
+
useSudo: true,
|
|
74
|
+
cd: '/home/dd/engine',
|
|
75
|
+
});
|
|
76
|
+
} catch (err) {
|
|
77
|
+
logger.error(`Error during database export for ${deployId}:`, err);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Repository backup: Cron container → SSH to host → host finds pod → kubectl exec git backup
|
|
81
|
+
try {
|
|
82
|
+
logger.info('Executing repository backup via SSH for', deployId);
|
|
83
|
+
await Underpost.ssh.sshRemoteRunner(prefixCmd(repoCommand), {
|
|
84
|
+
remote: true,
|
|
85
|
+
useSudo: true,
|
|
86
|
+
cd: '/home/dd/engine',
|
|
87
|
+
});
|
|
88
|
+
} catch (err) {
|
|
89
|
+
logger.error(`Error during repository backup for ${deployId}:`, err);
|
|
90
|
+
}
|
|
59
91
|
}
|
|
92
|
+
} finally {
|
|
93
|
+
if (ephemeral) Underpost.repo.cleanupPrivateEngineRepo();
|
|
60
94
|
}
|
|
61
95
|
};
|
|
62
96
|
}
|
|
@@ -394,6 +394,7 @@ const buildCoverage = async ({ host, path, docs }) => {
|
|
|
394
394
|
const jsDocSourcePath = docs.jsJsonPath;
|
|
395
395
|
const jsDocsConfig = JSON.parse(fs.readFileSync(jsDocSourcePath, 'utf8'));
|
|
396
396
|
const coveragePath = docs.coveragePath;
|
|
397
|
+
const coverageOutputDir = docs.coverageOutputDir || 'coverage';
|
|
397
398
|
|
|
398
399
|
const coverageOutputPath = `${coveragePath}/coverage`;
|
|
399
400
|
if (!fs.existsSync(coverageOutputPath)) {
|
|
@@ -411,9 +412,15 @@ const buildCoverage = async ({ host, path, docs }) => {
|
|
|
411
412
|
}
|
|
412
413
|
|
|
413
414
|
if (fs.existsSync(coverageOutputPath) && fs.readdirSync(coverageOutputPath).length > 0) {
|
|
414
|
-
const coverageBuildPath = `${jsDocsConfig.opts.destination}
|
|
415
|
+
const coverageBuildPath = `${jsDocsConfig.opts.destination}${coverageOutputDir}`;
|
|
415
416
|
fs.mkdirSync(coverageBuildPath, { recursive: true });
|
|
416
|
-
|
|
417
|
+
// Hardhat 3 outputs HTML to coverage/html/; Hardhat 2 / c8 output directly to coverage/
|
|
418
|
+
const coverageHtmlSubdir = `${coverageOutputPath}/html`;
|
|
419
|
+
if (fs.existsSync(coverageHtmlSubdir) && fs.existsSync(`${coverageHtmlSubdir}/index.html`)) {
|
|
420
|
+
fs.copySync(coverageHtmlSubdir, coverageBuildPath);
|
|
421
|
+
} else {
|
|
422
|
+
fs.copySync(coverageOutputPath, coverageBuildPath);
|
|
423
|
+
}
|
|
417
424
|
logger.warn('build coverage', coverageBuildPath);
|
|
418
425
|
} else {
|
|
419
426
|
logger.warn('no coverage output found, skipping', coverageOutputPath);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
|
-
import {
|
|
10
|
+
import { transformClientJs, JSONweb } from './client-formatted.js';
|
|
11
11
|
import { loggerFactory } from './logger.js';
|
|
12
12
|
import {
|
|
13
13
|
getCapVariableName,
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
uniqueArray,
|
|
17
17
|
} from '../client/components/core/CommonJs.js';
|
|
18
18
|
import { readConfJson } from './conf.js';
|
|
19
|
-
import UglifyJS from 'uglify-js';
|
|
20
19
|
import { minify } from 'html-minifier-terser';
|
|
21
20
|
import AdmZip from 'adm-zip';
|
|
22
21
|
import * as dir from 'path';
|
|
@@ -317,7 +316,8 @@ const buildClient = async (
|
|
|
317
316
|
shellExec(`cd /home/dd && git clone https://github.com/designmodo/html-website-templates.git`);
|
|
318
317
|
if (!fs.existsSync(`${rootClientPath}/index.php`)) {
|
|
319
318
|
fs.copySync(`/home/dd/html-website-templates/${publicClientId.split('-publicClientId-')[1]}`, rootClientPath);
|
|
320
|
-
|
|
319
|
+
Underpost.repo.initLocalRepo({ path: rootClientPath });
|
|
320
|
+
shellExec(`cd ${rootClientPath} && git add . && git commit -m "Base template implementation"`);
|
|
321
321
|
// git remote add origin git@github.com:<username>/<repo>.git
|
|
322
322
|
fs.writeFileSync(`${rootClientPath}/.git/.htaccess`, `Deny from all`, 'utf8');
|
|
323
323
|
}
|
|
@@ -447,15 +447,15 @@ const buildClient = async (
|
|
|
447
447
|
|
|
448
448
|
if (enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath)) continue;
|
|
449
449
|
|
|
450
|
-
const jsSrc =
|
|
451
|
-
await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')),
|
|
452
|
-
module,
|
|
450
|
+
const jsSrc = await transformClientJs(jsSrcPath, {
|
|
453
451
|
dists,
|
|
454
|
-
path,
|
|
455
|
-
'components',
|
|
452
|
+
proxyPath: path,
|
|
453
|
+
basePath: 'components',
|
|
454
|
+
module,
|
|
456
455
|
baseHost,
|
|
457
|
-
|
|
458
|
-
|
|
456
|
+
minify: minifyBuild,
|
|
457
|
+
});
|
|
458
|
+
fs.writeFileSync(jsPublicPath, jsSrc, 'utf8');
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
|
|
@@ -469,15 +469,15 @@ const buildClient = async (
|
|
|
469
469
|
const jsPublicPath = `${rootClientPath}/services/${module}/${module}.service.js`;
|
|
470
470
|
if (enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath)) continue;
|
|
471
471
|
|
|
472
|
-
|
|
473
|
-
await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')),
|
|
474
|
-
module,
|
|
472
|
+
const jsSrc = await transformClientJs(jsSrcPath, {
|
|
475
473
|
dists,
|
|
476
|
-
path,
|
|
477
|
-
'services',
|
|
474
|
+
proxyPath: path,
|
|
475
|
+
basePath: 'services',
|
|
476
|
+
module,
|
|
478
477
|
baseHost,
|
|
479
|
-
|
|
480
|
-
|
|
478
|
+
minify: minifyBuild,
|
|
479
|
+
});
|
|
480
|
+
fs.writeFileSync(jsPublicPath, jsSrc, 'utf8');
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
483
|
|
|
@@ -487,15 +487,15 @@ const buildClient = async (
|
|
|
487
487
|
const jsPublicPath = `${rootClientPath}/services/${module}/${module}.management.js`;
|
|
488
488
|
if (enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath)) continue;
|
|
489
489
|
|
|
490
|
-
const jsSrc =
|
|
491
|
-
await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')),
|
|
492
|
-
module,
|
|
490
|
+
const jsSrc = await transformClientJs(jsSrcPath, {
|
|
493
491
|
dists,
|
|
494
|
-
path,
|
|
495
|
-
'services',
|
|
492
|
+
proxyPath: path,
|
|
493
|
+
basePath: 'services',
|
|
494
|
+
module,
|
|
496
495
|
baseHost,
|
|
497
|
-
|
|
498
|
-
|
|
496
|
+
minify: minifyBuild,
|
|
497
|
+
});
|
|
498
|
+
fs.writeFileSync(jsPublicPath, jsSrc, 'utf8');
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
}
|
|
@@ -513,9 +513,9 @@ const buildClient = async (
|
|
|
513
513
|
const jsPublicPath = `${rootClientPath}/sw.js`;
|
|
514
514
|
|
|
515
515
|
if (!(enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath))) {
|
|
516
|
-
const jsSrc =
|
|
516
|
+
const jsSrc = await transformClientJs(jsSrcPath, { dists, proxyPath: path, baseHost, minify: minifyBuild });
|
|
517
517
|
|
|
518
|
-
fs.writeFileSync(jsPublicPath,
|
|
518
|
+
fs.writeFileSync(jsPublicPath, jsSrc, 'utf8');
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
if (
|
|
@@ -535,14 +535,14 @@ const buildClient = async (
|
|
|
535
535
|
|
|
536
536
|
logger.info('View build', buildPath);
|
|
537
537
|
|
|
538
|
-
const jsSrc =
|
|
539
|
-
await srcFormatted(fs.readFileSync(`./src/client/${view.client}.index.js`, 'utf8')),
|
|
538
|
+
const jsSrc = await transformClientJs(`./src/client/${view.client}.index.js`, {
|
|
540
539
|
dists,
|
|
541
|
-
path,
|
|
540
|
+
proxyPath: path,
|
|
542
541
|
baseHost,
|
|
543
|
-
|
|
542
|
+
minify: minifyBuild,
|
|
543
|
+
});
|
|
544
544
|
|
|
545
|
-
fs.writeFileSync(`${buildPath}${buildId}.js`,
|
|
545
|
+
fs.writeFileSync(`${buildPath}${buildId}.js`, jsSrc, 'utf8');
|
|
546
546
|
const title = metadata.title ? metadata.title : title;
|
|
547
547
|
|
|
548
548
|
const canonicalURL = `https://${host}${path}${
|
|
@@ -1,87 +1,139 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Module for formatting client-side code
|
|
2
|
+
* Module for formatting client-side code using esbuild for import rewriting and minification.
|
|
3
3
|
* @module src/server/client-formatted.js
|
|
4
4
|
* @namespace clientFormatted
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
import * as esbuild from 'esbuild';
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Escapes a string for safe use inside a RegExp.
|
|
15
|
+
* @param {string} s - The string to escape.
|
|
16
|
+
* @returns {string} The escaped string.
|
|
17
|
+
* @memberof clientFormatted
|
|
18
|
+
*/
|
|
19
|
+
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
20
|
+
|
|
9
21
|
/**
|
|
10
|
-
* Formats a source code string by removing 'html`' and 'css`'
|
|
22
|
+
* Formats a source code string by removing 'html`' and 'css`' tagged template prefixes.
|
|
23
|
+
* Used for SSR VM execution where the full esbuild pipeline is not needed.
|
|
11
24
|
* @param {string} src - The source code string.
|
|
12
25
|
* @returns {string} The formatted source code.
|
|
13
26
|
* @memberof clientFormatted
|
|
14
27
|
*/
|
|
15
|
-
const srcFormatted = (src) =>
|
|
16
|
-
src
|
|
17
|
-
.replaceAll(' html`', '`')
|
|
18
|
-
.replaceAll(' css`', '`')
|
|
19
|
-
.replaceAll('{html`', '{`')
|
|
20
|
-
.replaceAll('{css`', '{`')
|
|
21
|
-
.replaceAll('(html`', '(`')
|
|
22
|
-
.replaceAll('(css`', '(`')
|
|
23
|
-
.replaceAll('[html`', '[`')
|
|
24
|
-
.replaceAll('[css`', '[`');
|
|
28
|
+
const srcFormatted = (src) => src.replace(/(?<=[\s({[,;=+!?:^])(html|css)`/g, '`');
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* Converts a JavaScript object into a string that can be embedded in client-side code
|
|
28
32
|
* and parsed back into an object (e.g., 'JSON.parse(`{...}`)').
|
|
33
|
+
* Escapes backticks and template expression markers for safe template literal embedding.
|
|
29
34
|
* @param {*} data - The data to be stringified.
|
|
30
35
|
* @returns {string} A string representing the code to parse the JSON data.
|
|
31
36
|
* @memberof clientFormatted
|
|
32
37
|
*/
|
|
33
|
-
const JSONweb = (data) =>
|
|
38
|
+
const JSONweb = (data) => {
|
|
39
|
+
const json = JSON.stringify(data).replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
|
|
40
|
+
return 'JSON.parse(`' + json + '`)';
|
|
41
|
+
};
|
|
34
42
|
|
|
35
43
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @param {Array<object>} dists -
|
|
40
|
-
* @param {string} proxyPath - The proxy path for the application.
|
|
41
|
-
* @param {string} [
|
|
42
|
-
* @param {string} [
|
|
43
|
-
* @
|
|
44
|
+
* Creates an esbuild plugin that rewrites import paths for browser consumption.
|
|
45
|
+
* Handles dist library imports, relative imports, and marks all remaining imports as external.
|
|
46
|
+
* @param {object} options
|
|
47
|
+
* @param {Array<object>} [options.dists=[]] - Distribution objects with import_name and import_name_build.
|
|
48
|
+
* @param {string} options.proxyPath - The proxy path for the application.
|
|
49
|
+
* @param {string} [options.basePath=''] - The base path for the module type (e.g., 'components', 'services').
|
|
50
|
+
* @param {string} [options.module=''] - The module/component name for relative import resolution.
|
|
51
|
+
* @param {string} [options.baseHost=''] - The base host URL.
|
|
52
|
+
* @returns {import('esbuild').Plugin}
|
|
44
53
|
* @memberof clientFormatted
|
|
45
54
|
*/
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}${
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
const importRewritePlugin = ({ dists = [], proxyPath, basePath = '', module = '', baseHost = '' }) => ({
|
|
56
|
+
name: 'import-rewrite',
|
|
57
|
+
setup(build) {
|
|
58
|
+
const prefix = `${baseHost}${proxyPath !== '/' ? `${proxyPath}/` : '/'}`;
|
|
59
|
+
|
|
60
|
+
// Rewrite dist library imports (e.g., '@neodrag/vanilla' → '/proxyPath/dist/@neodrag-vanilla/index.js')
|
|
61
|
+
if (dists) {
|
|
62
|
+
for (const dist of dists) {
|
|
63
|
+
if (!dist.import_name) continue;
|
|
64
|
+
const filter = new RegExp(`^${escapeRegExp(dist.import_name)}$`);
|
|
65
|
+
build.onResolve({ filter }, () => ({
|
|
66
|
+
path: `${baseHost}${proxyPath !== '/' ? proxyPath : ''}${dist.import_name_build}`,
|
|
67
|
+
external: true,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Rewrite relative imports to absolute paths based on proxy path and module
|
|
73
|
+
build.onResolve({ filter: /^\.\.?\// }, (args) => {
|
|
74
|
+
const basePrefix = `${prefix}${basePath ? `${basePath}/` : ''}`;
|
|
75
|
+
if (args.path.startsWith('./')) {
|
|
76
|
+
return {
|
|
77
|
+
path: `${basePrefix}${module ? `${module}/` : ''}${args.path.slice(2)}`,
|
|
78
|
+
external: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (args.path.startsWith('../')) {
|
|
82
|
+
return {
|
|
83
|
+
path: `${basePrefix}${args.path.slice(3)}`,
|
|
84
|
+
external: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Mark any remaining imports as external
|
|
90
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
91
|
+
if (args.kind === 'entry-point') return;
|
|
92
|
+
return { path: args.path, external: true };
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
});
|
|
68
96
|
|
|
69
97
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @param {string}
|
|
74
|
-
* @param {
|
|
75
|
-
* @
|
|
98
|
+
* Transforms a JavaScript source file using esbuild with import path rewriting,
|
|
99
|
+
* tagged template stripping, and optional minification.
|
|
100
|
+
* Replaces the previous srcFormatted + componentFormatted/viewFormatted + UglifyJS pipeline.
|
|
101
|
+
* @param {string} srcPath - Path to the source file.
|
|
102
|
+
* @param {object} options
|
|
103
|
+
* @param {Array<object>} [options.dists=[]] - Distribution objects with import names.
|
|
104
|
+
* @param {string} options.proxyPath - The proxy path for the application.
|
|
105
|
+
* @param {string} [options.basePath=''] - Base path for the module type (e.g., 'components', 'services').
|
|
106
|
+
* @param {string} [options.module=''] - Module name for relative import resolution.
|
|
107
|
+
* @param {string} [options.baseHost=''] - Base host URL.
|
|
108
|
+
* @param {boolean} [options.minify=false] - Whether to minify the output.
|
|
109
|
+
* @returns {Promise<string>} The transformed source code.
|
|
76
110
|
* @memberof clientFormatted
|
|
77
111
|
*/
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
const
|
|
84
|
-
|
|
112
|
+
const transformClientJs = async (
|
|
113
|
+
srcPath,
|
|
114
|
+
{ dists = [], proxyPath, basePath = '', module = '', baseHost = '', minify: shouldMinify = false } = {},
|
|
115
|
+
) => {
|
|
116
|
+
const src = fs.readFileSync(srcPath, 'utf8');
|
|
117
|
+
const stripped = srcFormatted(src);
|
|
118
|
+
|
|
119
|
+
const result = await esbuild.build({
|
|
120
|
+
stdin: {
|
|
121
|
+
contents: stripped,
|
|
122
|
+
loader: 'js',
|
|
123
|
+
resolveDir: path.dirname(path.resolve(srcPath)),
|
|
124
|
+
sourcefile: srcPath,
|
|
125
|
+
},
|
|
126
|
+
bundle: true,
|
|
127
|
+
write: false,
|
|
128
|
+
format: 'esm',
|
|
129
|
+
platform: 'browser',
|
|
130
|
+
target: 'esnext',
|
|
131
|
+
minify: shouldMinify,
|
|
132
|
+
logLevel: 'warning',
|
|
133
|
+
plugins: [importRewritePlugin({ dists, proxyPath, basePath, module, baseHost })],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return result.outputFiles[0].text;
|
|
85
137
|
};
|
|
86
138
|
|
|
87
|
-
export { srcFormatted, JSONweb,
|
|
139
|
+
export { srcFormatted, JSONweb, transformClientJs };
|
package/src/server/cron.js
CHANGED
|
@@ -33,7 +33,9 @@ const underpostContainerEnvPath = '/usr/lib/node_modules/underpost/.env';
|
|
|
33
33
|
* @param {string} [params.cmd] - Optional pre-script commands to run before cron execution
|
|
34
34
|
* @param {boolean} [params.suspend=false] - Whether the CronJob is suspended
|
|
35
35
|
* @param {boolean} [params.dryRun=false] - Pass --dry-run flag to the cron command inside the container
|
|
36
|
-
* @param {boolean} [params.
|
|
36
|
+
* @param {boolean} [params.k3s=false] - Pass --k3s flag to the cron command inside the container
|
|
37
|
+
* @param {boolean} [params.kind=false] - Pass --kind flag to the cron command inside the container
|
|
38
|
+
* @param {boolean} [params.kubeadm=false] - Pass --kubeadm flag to the cron command inside the container
|
|
37
39
|
* @returns {string} Kubernetes CronJob YAML manifest
|
|
38
40
|
* @memberof UnderpostCron
|
|
39
41
|
*/
|
|
@@ -49,7 +51,9 @@ const cronJobYamlFactory = ({
|
|
|
49
51
|
cmd,
|
|
50
52
|
suspend = false,
|
|
51
53
|
dryRun = false,
|
|
52
|
-
|
|
54
|
+
k3s = false,
|
|
55
|
+
kind = false,
|
|
56
|
+
kubeadm = false,
|
|
53
57
|
}) => {
|
|
54
58
|
const containerImage = image || `underpost/underpost-engine:${Underpost.version}`;
|
|
55
59
|
|
|
@@ -60,10 +64,12 @@ const cronJobYamlFactory = ({
|
|
|
60
64
|
.replace(/^-|-$/g, '')
|
|
61
65
|
.substring(0, 52);
|
|
62
66
|
|
|
63
|
-
const cmdPart = cmd ? `${cmd} && ` : '';
|
|
64
67
|
const cronBin = dev ? 'node bin' : 'underpost';
|
|
65
|
-
const flags = `${git ? '--git ' : ''}${dev ? '--dev ' : ''}${dryRun ? '--dry-run ' : ''}${
|
|
66
|
-
const
|
|
68
|
+
const flags = `${git ? '--git ' : ''}${dev ? '--dev ' : ''}${dryRun ? '--dry-run ' : ''}${k3s ? '--k3s ' : ''}${kind ? '--kind ' : ''}${kubeadm ? '--kubeadm ' : ''}`;
|
|
69
|
+
const commands = [`cd ${enginePath}`, `node bin run secret`];
|
|
70
|
+
if (cmd) commands.push(cmd);
|
|
71
|
+
commands.push(`${cronBin} cron ${flags}${deployList} ${jobList}`);
|
|
72
|
+
const fullCommand = commands.join(' &&\n ');
|
|
67
73
|
|
|
68
74
|
return `apiVersion: batch/v1
|
|
69
75
|
kind: CronJob
|
|
@@ -95,7 +101,7 @@ spec:
|
|
|
95
101
|
- /bin/sh
|
|
96
102
|
- -c
|
|
97
103
|
- >
|
|
98
|
-
${
|
|
104
|
+
${fullCommand}
|
|
99
105
|
volumeMounts:
|
|
100
106
|
- mountPath: ${enginePath}
|
|
101
107
|
name: ${cronVolumeName}
|
|
@@ -183,7 +189,6 @@ class UnderpostCron {
|
|
|
183
189
|
* @param {boolean} [options.kubeadm] - Use kubeadm cluster context (apply directly on host)
|
|
184
190
|
* @param {boolean} [options.dryRun] - Preview cron jobs without executing them
|
|
185
191
|
* @param {boolean} [options.createJobNow] - After applying, immediately create a Job from each CronJob (requires --apply)
|
|
186
|
-
* @param {boolean} [options.ssh] - Execute backup commands via SSH on the remote node
|
|
187
192
|
* @memberof UnderpostCron
|
|
188
193
|
*/
|
|
189
194
|
callback: async function (
|
|
@@ -227,7 +232,6 @@ class UnderpostCron {
|
|
|
227
232
|
* @param {boolean} [options.k3s] - k3s cluster context (apply directly on host)
|
|
228
233
|
* @param {boolean} [options.kind] - kind cluster context (apply via kind-worker container)
|
|
229
234
|
* @param {boolean} [options.kubeadm] - kubeadm cluster context (apply directly on host)
|
|
230
|
-
* @param {boolean} [options.ssh] - Execute backup commands via SSH on the remote node
|
|
231
235
|
* @memberof UnderpostCron
|
|
232
236
|
*/
|
|
233
237
|
setupDeployStart: async function (deployId, options = {}) {
|
|
@@ -270,20 +274,20 @@ class UnderpostCron {
|
|
|
270
274
|
}
|
|
271
275
|
|
|
272
276
|
// Generate and apply cron job manifests for this deploy-id
|
|
277
|
+
const hasExplicitCluster = options.k3s || options.kind || options.kubeadm;
|
|
273
278
|
await Underpost.cron.generateK8sCronJobs({
|
|
274
279
|
deployId,
|
|
275
280
|
namespace: options.namespace,
|
|
276
281
|
image: options.image,
|
|
277
282
|
apply: options.apply,
|
|
278
283
|
createJobNow: options.createJobNow,
|
|
279
|
-
git: true,
|
|
280
|
-
dev: true,
|
|
281
|
-
kubeadm: true,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
dryRun: false,
|
|
284
|
+
git: options.git !== undefined ? options.git : true,
|
|
285
|
+
dev: options.dev !== undefined ? options.dev : true,
|
|
286
|
+
kubeadm: hasExplicitCluster ? !!options.kubeadm : true,
|
|
287
|
+
cmd: options.cmd || `node bin env ${deployId} production`,
|
|
288
|
+
k3s: !!options.k3s,
|
|
289
|
+
kind: !!options.kind,
|
|
290
|
+
dryRun: !!options.dryRun,
|
|
287
291
|
});
|
|
288
292
|
},
|
|
289
293
|
|
|
@@ -305,7 +309,6 @@ class UnderpostCron {
|
|
|
305
309
|
* @param {boolean} [options.kubeadm=false] - kubeadm cluster context (apply directly on host)
|
|
306
310
|
* @param {boolean} [options.createJobNow=false] - After applying, create a Job from each CronJob immediately
|
|
307
311
|
* @param {boolean} [options.dryRun=false] - Pass --dry-run=client to kubectl commands
|
|
308
|
-
* @param {boolean} [options.ssh=false] - Execute backup commands via SSH on the remote node
|
|
309
312
|
* @memberof UnderpostCron
|
|
310
313
|
*/
|
|
311
314
|
generateK8sCronJobs: async function (options = {}) {
|
|
@@ -362,7 +365,9 @@ class UnderpostCron {
|
|
|
362
365
|
cmd: options.cmd,
|
|
363
366
|
suspend: false,
|
|
364
367
|
dryRun: !!options.dryRun,
|
|
365
|
-
|
|
368
|
+
k3s: !!options.k3s,
|
|
369
|
+
kind: !!options.kind,
|
|
370
|
+
kubeadm: !!options.kubeadm,
|
|
366
371
|
});
|
|
367
372
|
|
|
368
373
|
const yamlFilePath = `${outputDir}/${cronJobName}.yaml`;
|
|
@@ -244,7 +244,11 @@ const unpinCid = async (cid) => {
|
|
|
244
244
|
});
|
|
245
245
|
if (!clusterRes.ok) {
|
|
246
246
|
const text = await clusterRes.text();
|
|
247
|
-
|
|
247
|
+
if (clusterRes.status === 404) {
|
|
248
|
+
logger.info(`IPFS Cluster unpin – CID already not pinned: ${cid}`);
|
|
249
|
+
} else {
|
|
250
|
+
logger.warn(`IPFS Cluster unpin failed (${clusterRes.status}): ${text}`);
|
|
251
|
+
}
|
|
248
252
|
} else {
|
|
249
253
|
logger.info(`IPFS Cluster unpin OK – CID: ${cid}`);
|
|
250
254
|
}
|
|
@@ -428,6 +432,25 @@ const IpfsClient = {
|
|
|
428
432
|
listClusterPins,
|
|
429
433
|
listKuboPins,
|
|
430
434
|
removeMfsPath,
|
|
435
|
+
/**
|
|
436
|
+
* Check whether a single CID is currently pinned on the local Kubo node.
|
|
437
|
+
* Uses the pin/ls?arg=<cid> endpoint which returns only that one pin
|
|
438
|
+
* (much cheaper than fetching the full list).
|
|
439
|
+
*
|
|
440
|
+
* @param {string} cid - IPFS Content Identifier to check.
|
|
441
|
+
* @returns {Promise<boolean>} true when the CID is pinned.
|
|
442
|
+
*/
|
|
443
|
+
isCidPinned: async (cid) => {
|
|
444
|
+
const kuboUrl = getIpfsApiUrl();
|
|
445
|
+
try {
|
|
446
|
+
const res = await fetch(`${kuboUrl}/api/v0/pin/ls?arg=${encodeURIComponent(cid)}&type=all`, { method: 'POST' });
|
|
447
|
+
if (!res.ok) return false;
|
|
448
|
+
const json = await res.json();
|
|
449
|
+
return !!(json.Keys && json.Keys[cid]);
|
|
450
|
+
} catch {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
},
|
|
431
454
|
};
|
|
432
455
|
|
|
433
456
|
export { IpfsClient };
|
package/src/server/peer.js
CHANGED
|
@@ -44,6 +44,14 @@ const logger = loggerFactory(import.meta);
|
|
|
44
44
|
*/
|
|
45
45
|
const createPeerServer = async ({ port, origins, path }) => {
|
|
46
46
|
logger.info('origins', origins);
|
|
47
|
+
|
|
48
|
+
// In development, allow the local client origin (peer runs on port+1 relative to the client)
|
|
49
|
+
if (process.env.NODE_ENV === 'development') {
|
|
50
|
+
const clientPort = port - 1;
|
|
51
|
+
const devOrigin = `http://localhost:${clientPort}`;
|
|
52
|
+
if (!origins.includes(devOrigin)) origins.push(devOrigin);
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
/** @type {import('peer').IConfig} */
|
|
48
56
|
const options = {
|
|
49
57
|
port,
|