@underpostnet/underpost 2.99.5 → 2.99.7

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.
Files changed (37) hide show
  1. package/.github/workflows/ghpkg.ci.yml +10 -25
  2. package/.github/workflows/npmpkg.ci.yml +13 -2
  3. package/CHANGELOG.md +496 -0
  4. package/README.md +4 -4
  5. package/baremetal/commission-workflows.json +43 -6
  6. package/bin/deploy.js +13 -0
  7. package/cli.md +84 -42
  8. package/examples/static-page/README.md +80 -13
  9. package/jsdoc.json +26 -5
  10. package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +47 -0
  11. package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +47 -0
  12. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  13. package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
  14. package/package.json +2 -4
  15. package/scripts/maas-setup.sh +13 -9
  16. package/scripts/rocky-kickstart.sh +294 -0
  17. package/src/cli/baremetal.js +237 -555
  18. package/src/cli/cloud-init.js +27 -45
  19. package/src/cli/index.js +52 -6
  20. package/src/cli/kickstart.js +149 -0
  21. package/src/cli/repository.js +166 -13
  22. package/src/cli/run.js +26 -19
  23. package/src/cli/ssh.js +1 -1
  24. package/src/cli/static.js +27 -1
  25. package/src/cli/system.js +332 -0
  26. package/src/client/components/core/Docs.js +22 -3
  27. package/src/db/DataBaseProvider.js +3 -3
  28. package/src/db/mariadb/MariaDB.js +3 -3
  29. package/src/db/mongo/MongooseDB.js +3 -3
  30. package/src/index.js +28 -5
  31. package/src/mailer/EmailRender.js +3 -3
  32. package/src/mailer/MailerProvider.js +4 -4
  33. package/src/server/backup.js +23 -5
  34. package/src/server/client-build-docs.js +29 -3
  35. package/src/server/conf.js +6 -27
  36. package/src/server/cron.js +354 -135
  37. package/src/server/dns.js +2 -0
package/src/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  import UnderpostBaremetal from './cli/baremetal.js';
8
8
  import UnderpostCloudInit from './cli/cloud-init.js';
9
+ import UnderpostKickStart from './cli/kickstart.js';
9
10
  import UnderpostCluster from './cli/cluster.js';
10
11
  import UnderpostDB from './cli/db.js';
11
12
  import UnderpostDeploy from './cli/deploy.js';
@@ -20,6 +21,7 @@ import UnderpostSecret from './cli/secrets.js';
20
21
  import UnderpostSSH from './cli/ssh.js';
21
22
  import UnderpostStatic from './cli/static.js';
22
23
  import UnderpostTest from './cli/test.js';
24
+ import UnderpostSystemProvisionig from './cli/system.js';
23
25
 
24
26
  import UnderpostDns from './server/dns.js';
25
27
  import UnderpostBackup from './server/backup.js';
@@ -39,7 +41,7 @@ class Underpost {
39
41
  * @type {String}
40
42
  * @memberof Underpost
41
43
  */
42
- static version = 'v2.99.5';
44
+ static version = 'v2.99.7';
43
45
 
44
46
  /**
45
47
  * Required Node.js major version
@@ -179,6 +181,16 @@ class Underpost {
179
181
  return UnderpostCloudInit.API;
180
182
  }
181
183
 
184
+ /**
185
+ * KickStart cli API
186
+ * @static
187
+ * @type {UnderpostKickStart.API}
188
+ * @memberof Underpost
189
+ */
190
+ static get kickstart() {
191
+ return UnderpostKickStart.API;
192
+ }
193
+
182
194
  /**
183
195
  * Run cli API
184
196
  * @static
@@ -200,7 +212,17 @@ class Underpost {
200
212
  }
201
213
 
202
214
  /**
203
- * Dns cli API
215
+ * System Provisioning cli API
216
+ * @static
217
+ * @type {UnderpostSystemProvisionig.API}
218
+ * @memberof Underpost
219
+ */
220
+ static get system() {
221
+ return UnderpostSystemProvisionig.API;
222
+ }
223
+
224
+ /**
225
+ * Dns server API
204
226
  * @static
205
227
  * @type {UnderpostDns.API}
206
228
  * @memberof Underpost
@@ -210,7 +232,7 @@ class Underpost {
210
232
  }
211
233
 
212
234
  /**
213
- * BackUp cli API
235
+ * BackUp server API
214
236
  * @static
215
237
  * @type {UnderpostBackup.API}
216
238
  * @memberof Underpost
@@ -220,7 +242,7 @@ class Underpost {
220
242
  }
221
243
 
222
244
  /**
223
- * Cron cli API
245
+ * Cron server API
224
246
  * @static
225
247
  * @type {UnderpostCron.API}
226
248
  * @memberof Underpost
@@ -230,7 +252,7 @@ class Underpost {
230
252
  }
231
253
 
232
254
  /**
233
- * Start Up cli API
255
+ * Start Up server API
234
256
  * @static
235
257
  * @type {UnderpostStartUp.API}
236
258
  * @memberof Underpost
@@ -273,6 +295,7 @@ export {
273
295
  UnderpostImage,
274
296
  UnderpostStatic,
275
297
  UnderpostLxd,
298
+ UnderpostKickStart,
276
299
  UnderpostMonitor,
277
300
  UnderpostRepository,
278
301
  UnderpostRun,
@@ -3,13 +3,13 @@ import { ssrFactory } from '../server/ssr.js';
3
3
  /**
4
4
  * Module for handling the rendering and styling of HTML emails using SSR components.
5
5
  * @module src/mailer/EmailRender.js
6
- * @namespace EmailRenderNamespace
6
+ * @namespace EmailRenderService
7
7
  */
8
8
 
9
9
  /**
10
10
  * @class
11
11
  * @alias EmailRenderService
12
- * @memberof EmailRenderNamespace
12
+ * @memberof EmailRenderService
13
13
  * @classdesc Utility class for managing CSS styles and rendering email templates using
14
14
  * Server-Side Rendering (SSR) components.
15
15
  */
@@ -108,7 +108,7 @@ class EmailRenderService {
108
108
  /**
109
109
  * Singleton instance of the EmailRenderService class for backward compatibility.
110
110
  * @alias EmailRender
111
- * @memberof EmailRenderNamespace
111
+ * @memberof EmailRenderService
112
112
  * @type {EmailRenderService}
113
113
  */
114
114
  const EmailRender = new EmailRenderService();
@@ -5,7 +5,7 @@ import { EmailRender } from './EmailRender.js';
5
5
  /**
6
6
  * Module for configuring and sending emails using Nodemailer.
7
7
  * @module src/mailer/MailerProvider.js
8
- * @namespace MailerProviderNamespace
8
+ * @namespace MailerProviderService
9
9
  */
10
10
 
11
11
  const logger = loggerFactory(import.meta);
@@ -27,13 +27,13 @@ const logger = loggerFactory(import.meta);
27
27
  * @property {string} [host=''] - Application host for context.
28
28
  * @property {string} [path=''] - Application path for context.
29
29
  * @property {object.<string, string>} templates - Map of template keys to SSR component file names.
30
- * @memberof MailerProviderNamespace
30
+ * @memberof MailerProviderService
31
31
  */
32
32
 
33
33
  /**
34
34
  * @class
35
35
  * @alias MailerProviderService
36
- * @memberof MailerProviderNamespace
36
+ * @memberof MailerProviderService
37
37
  * @classdesc Manages multiple Nodemailer transporter instances and handles loading of
38
38
  * email templates and sending emails.
39
39
  */
@@ -205,7 +205,7 @@ class MailerProviderService {
205
205
  /**
206
206
  * Singleton instance of the MailerProviderService class for backward compatibility.
207
207
  * @alias MailerProvider
208
- * @memberof MailerProviderNamespace
208
+ * @memberof MailerProviderService
209
209
  * @type {MailerProviderService}
210
210
  */
211
211
  const MailerProvider = new MailerProviderService();
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * Manages backup operations for deployments.
3
3
  * @module src/server/backup.js
4
- * @namespace BackUp
4
+ * @namespace UnderpostBakcUp
5
5
  */
6
6
 
7
7
  import fs from 'fs-extra';
8
8
  import { loggerFactory } from './logger.js';
9
9
  import { shellExec } from './process.js';
10
10
  import dotenv from 'dotenv';
11
+ import Underpost from '../index.js';
11
12
 
12
13
  dotenv.config();
13
14
 
@@ -16,7 +17,7 @@ const logger = loggerFactory(import.meta);
16
17
  /**
17
18
  * @class BackUp
18
19
  * @description Manages backup operations for deployments.
19
- * @memberof BackUp
20
+ * @memberof UnderpostBakcUp
20
21
  */
21
22
  class BackUp {
22
23
  /**
@@ -25,7 +26,11 @@ class BackUp {
25
26
  * @param {string} deployList - The list of deployments to backup.
26
27
  * @param {Object} options - The options for the backup operation.
27
28
  * @param {boolean} options.git - Whether to backup data using Git.
28
- * @memberof BackUp
29
+ * @param {boolean} [options.k3s] - Use k3s cluster context.
30
+ * @param {boolean} [options.kind] - Use kind cluster context.
31
+ * @param {boolean} [options.kubeadm] - Use kubeadm cluster context.
32
+ * @param {boolean} [options.ssh] - Execute backup commands via SSH on the remote node.
33
+ * @memberof UnderpostBakcUp
29
34
  */
30
35
  static callback = async function (deployList, options = { git: false }) {
31
36
  if ((!deployList || deployList === 'dd') && fs.existsSync(`./engine-private/deploy/dd.router`))
@@ -34,12 +39,25 @@ class BackUp {
34
39
  logger.info('init backups callback', deployList);
35
40
  await logger.setUpInfo();
36
41
 
42
+ const clusterFlag = options.k3s ? ' --k3s' : options.kind ? ' --kind' : options.kubeadm ? ' --kubeadm' : '';
43
+
37
44
  for (const _deployId of deployList.split(',')) {
38
45
  const deployId = _deployId.trim();
39
46
  if (!deployId) continue;
40
47
 
41
- logger.info('Executing database export for', deployId);
42
- shellExec(`node bin db ${options.git ? '--git ' : ''}--export ${deployId}`);
48
+ const command = `node bin db ${options.git ? '--git --force-clone ' : ''}--export --primary-pod${clusterFlag} ${deployId}`;
49
+
50
+ if (options.ssh) {
51
+ logger.info('Executing database export via SSH for', deployId);
52
+ await Underpost.ssh.sshRemoteRunner(command, {
53
+ remote: true,
54
+ useSudo: true,
55
+ cd: '/home/dd/engine',
56
+ });
57
+ } else {
58
+ logger.info('Executing database export for', deployId);
59
+ shellExec(command);
60
+ }
43
61
  }
44
62
  };
45
63
  }
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * Module for building project documentation (JSDoc, Swagger, Coverage).
5
+ * @module src/server/client-build-docs.js
6
+ * @namespace clientBuildDocs
7
+ */
8
+
3
9
  import fs from 'fs-extra';
4
10
  import swaggerAutoGen from 'swagger-autogen';
5
11
  import { shellExec } from './process.js';
@@ -8,6 +14,8 @@ import { JSONweb } from './client-formatted.js';
8
14
 
9
15
  /**
10
16
  * Builds API documentation using Swagger
17
+ * @function buildApiDocs
18
+ * @memberof clientBuildDocs
11
19
  * @param {Object} options - Documentation build options
12
20
  * @param {string} options.host - The hostname for the API
13
21
  * @param {string} options.path - The base path for the API
@@ -126,18 +134,32 @@ const buildApiDocs = async ({
126
134
 
127
135
  /**
128
136
  * Builds JSDoc documentation
137
+ * @function buildJsDocs
138
+ * @memberof clientBuildDocs
129
139
  * @param {Object} options - JSDoc build options
130
140
  * @param {string} options.host - The hostname for the documentation
131
141
  * @param {string} options.path - The base path for the documentation
132
142
  * @param {Object} options.metadata - Metadata for the documentation
143
+ * @param {string} options.publicClientId - Client ID used to resolve the tutorials/references directory
133
144
  */
134
- const buildJsDocs = async ({ host, path, metadata = {} }) => {
145
+ const buildJsDocs = async ({ host, path, metadata = {}, publicClientId }) => {
135
146
  const logger = loggerFactory(import.meta);
136
147
  const jsDocsConfig = JSON.parse(fs.readFileSync(`./jsdoc.json`, 'utf8'));
137
148
 
138
149
  jsDocsConfig.opts.destination = `./public/${host}${path === '/' ? path : `${path}/`}docs/`;
139
150
  jsDocsConfig.opts.theme_opts.title = metadata?.title ? metadata.title : undefined;
140
- jsDocsConfig.opts.theme_opts.favicon = `./public/${host}${path === '/' ? path : `${path}/favicon.ico`}`;
151
+ jsDocsConfig.opts.theme_opts.favicon = `./public/${host}${path === '/' ? '/' : `${path}/`}favicon.ico`;
152
+
153
+ const tutorialsPath = `./src/client/public/${publicClientId}/docs/references`;
154
+ if (fs.existsSync(tutorialsPath)) {
155
+ jsDocsConfig.opts.tutorials = tutorialsPath;
156
+ if (jsDocsConfig.opts.theme_opts.sections && !jsDocsConfig.opts.theme_opts.sections.includes('Tutorials')) {
157
+ jsDocsConfig.opts.theme_opts.sections.push('Tutorials');
158
+ }
159
+ logger.info('build jsdoc tutorials', tutorialsPath);
160
+ } else {
161
+ delete jsDocsConfig.opts.tutorials;
162
+ }
141
163
 
142
164
  fs.writeFileSync(`./jsdoc.json`, JSON.stringify(jsDocsConfig, null, 4), 'utf8');
143
165
  logger.warn('build jsdoc view', jsDocsConfig.opts.destination);
@@ -147,6 +169,8 @@ const buildJsDocs = async ({ host, path, metadata = {} }) => {
147
169
 
148
170
  /**
149
171
  * Builds test coverage documentation
172
+ * @function buildCoverage
173
+ * @memberof clientBuildDocs
150
174
  * @param {Object} options - Coverage build options
151
175
  * @param {string} options.host - The hostname for the coverage
152
176
  * @param {string} options.path - The base path for the coverage
@@ -168,6 +192,8 @@ const buildCoverage = async ({ host, path }) => {
168
192
 
169
193
  /**
170
194
  * Main function to build all documentation
195
+ * @function buildDocs
196
+ * @memberof clientBuildDocs
171
197
  * @param {Object} options - Documentation build options
172
198
  * @param {string} options.host - The hostname
173
199
  * @param {string} options.path - The base path
@@ -188,7 +214,7 @@ const buildDocs = async ({
188
214
  rootClientPath,
189
215
  packageData,
190
216
  }) => {
191
- await buildJsDocs({ host, path, metadata });
217
+ await buildJsDocs({ host, path, metadata, publicClientId });
192
218
  await buildCoverage({ host, path });
193
219
  await buildApiDocs({
194
220
  host,
@@ -1167,19 +1167,12 @@ const getPathsSSR = (conf) => {
1167
1167
  };
1168
1168
 
1169
1169
  /**
1170
- * @method Cmd
1170
+ * @method CmdUnderpost
1171
1171
  * @description The command factory.
1172
1172
  * @memberof ServerConfBuilder
1173
+ * @namespace CmdUnderpost
1173
1174
  */
1174
1175
  const Cmd = {
1175
- /**
1176
- * @method delete
1177
- * @description Deletes the deploy.
1178
- * @param {string} deployId - The deploy ID.
1179
- * @returns {string} - The delete command.
1180
- * @memberof Cmd
1181
- */
1182
- delete: (deployId) => `pm2 delete ${deployId}`,
1183
1176
  /**
1184
1177
  * @method run
1185
1178
  * @description Runs the deploy.
@@ -1192,7 +1185,7 @@ const Cmd = {
1192
1185
  * @description Builds the deploy.
1193
1186
  * @param {string} deployId - The deploy ID.
1194
1187
  * @returns {string} - The build command.
1195
- * @memberof Cmd
1188
+ * @memberof CmdUnderpost
1196
1189
  */
1197
1190
  build: (deployId) => `node bin/deploy build-full-client ${deployId}`,
1198
1191
  /**
@@ -1201,7 +1194,7 @@ const Cmd = {
1201
1194
  * @param {string} deployId - The deploy ID.
1202
1195
  * @param {string} env - The environment.
1203
1196
  * @returns {string} - The conf command.
1204
- * @memberof Cmd
1197
+ * @memberof CmdUnderpost
1205
1198
  */
1206
1199
  conf: (deployId, env) => `node bin/deploy conf ${deployId} ${env ? env : 'production'}`,
1207
1200
  /**
@@ -1211,30 +1204,16 @@ const Cmd = {
1211
1204
  * @param {string} host - The host.
1212
1205
  * @param {string} path - The path.
1213
1206
  * @returns {string} - The replica command.
1214
- * @memberof Cmd
1207
+ * @memberof CmdUnderpost
1215
1208
  */
1216
1209
  replica: (deployId, host, path) => `node bin/deploy build-single-replica ${deployId} ${host} ${path}`,
1217
1210
  /**
1218
1211
  * @method syncPorts
1219
1212
  * @description Syncs the ports.
1220
1213
  * @returns {string} - The sync ports command.
1221
- * @memberof Cmd
1214
+ * @memberof CmdUnderpost
1222
1215
  */
1223
1216
  syncPorts: () => `node bin/deploy sync-env-port`,
1224
- /**
1225
- * @method cron
1226
- * @description Creates a cron job.
1227
- * @param {string} deployList - The deploy list.
1228
- * @param {string} jobList - The job list.
1229
- * @param {string} name - The name.
1230
- * @param {string} expression - The expression.
1231
- * @param {object} options - The options.
1232
- * @param {number} instances - The number of PM2 instances (default: 1).
1233
- * @returns {string} - The cron command.
1234
- * @memberof Cmd
1235
- */
1236
- cron: (deployList, jobList, name, expression, options, instances = 1) =>
1237
- `pm2 start ./bin/index.js --no-autorestart --instances ${instances} --cron "${expression}" --name ${name} -- cron ${options?.git ? `--git ` : ''}${deployList} ${jobList}`,
1238
1217
  };
1239
1218
 
1240
1219
  /**