underpost 2.8.884 → 2.8.885

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 (43) hide show
  1. package/README.md +4 -120
  2. package/bin/deploy.js +9 -10
  3. package/bin/file.js +4 -6
  4. package/cli.md +15 -11
  5. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  6. package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
  7. package/package.json +1 -1
  8. package/src/cli/cluster.js +21 -0
  9. package/src/cli/cron.js +8 -0
  10. package/src/cli/db.js +63 -1
  11. package/src/cli/deploy.js +156 -3
  12. package/src/cli/env.js +43 -0
  13. package/src/cli/fs.js +94 -0
  14. package/src/cli/image.js +8 -0
  15. package/src/cli/index.js +17 -4
  16. package/src/cli/monitor.js +0 -1
  17. package/src/cli/repository.js +95 -2
  18. package/src/client/components/core/Css.js +16 -0
  19. package/src/client/components/core/Docs.js +5 -13
  20. package/src/client/components/core/Modal.js +48 -29
  21. package/src/client/components/core/Router.js +6 -3
  22. package/src/client/components/core/Worker.js +205 -118
  23. package/src/client/components/default/MenuDefault.js +1 -0
  24. package/src/client.dev.js +6 -3
  25. package/src/db/DataBaseProvider.js +65 -12
  26. package/src/db/mariadb/MariaDB.js +39 -6
  27. package/src/db/mongo/MongooseDB.js +51 -133
  28. package/src/index.js +1 -1
  29. package/src/mailer/EmailRender.js +58 -9
  30. package/src/mailer/MailerProvider.js +98 -25
  31. package/src/runtime/express/Express.js +20 -34
  32. package/src/server/auth.js +9 -28
  33. package/src/server/client-build-live.js +14 -5
  34. package/src/server/client-dev-server.js +21 -8
  35. package/src/server/conf.js +78 -25
  36. package/src/server/peer.js +2 -2
  37. package/src/server/runtime.js +0 -5
  38. package/src/server/start.js +39 -0
  39. package/src/ws/IoInterface.js +132 -39
  40. package/src/ws/IoServer.js +79 -31
  41. package/src/ws/core/core.ws.connection.js +50 -16
  42. package/src/ws/core/core.ws.emit.js +47 -8
  43. package/src/ws/core/core.ws.server.js +62 -10
package/src/cli/deploy.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Deploy module for managing the deployment of applications and services.
3
+ * @module src/cli/deploy.js
4
+ * @namespace UnderpostDeploy
5
+ */
6
+
1
7
  import {
2
8
  buildKindPorts,
3
9
  buildPortProxyRouter,
@@ -14,13 +20,29 @@ import fs from 'fs-extra';
14
20
  import dotenv from 'dotenv';
15
21
  import UnderpostRootEnv from './env.js';
16
22
  import UnderpostCluster from './cluster.js';
17
- import Underpost from '../index.js';
18
23
 
19
24
  const logger = loggerFactory(import.meta);
20
25
 
26
+ /**
27
+ * @class UnderpostDeploy
28
+ * @description Manages the deployment of applications and services.
29
+ * This class provides a set of static methods to handle the deployment process,
30
+ * including resource allocation, configuration management, and Kubernetes deployment.
31
+ * @memberof UnderpostDeploy
32
+ */
21
33
  class UnderpostDeploy {
22
34
  static NETWORK = {};
23
35
  static API = {
36
+ /**
37
+ * Synchronizes deployment configurations for a list of deployments.
38
+ * @param {string} deployList - List of deployment IDs to synchronize.
39
+ * @param {object} options - Options for the synchronization process.
40
+ * @param {string} options.versions - Comma-separated list of versions to deploy.
41
+ * @param {string} options.replicas - Number of replicas for each deployment.
42
+ * @param {string} options.node - Node name for resource allocation.
43
+ * @returns {object} - Deployment data for the specified deployments.
44
+ * @memberof UnderpostDeploy
45
+ */
24
46
  sync(deployList, { versions, replicas, node }) {
25
47
  const deployGroupId = 'dd.router';
26
48
  fs.writeFileSync(`./engine-private/deploy/${deployGroupId}`, deployList, 'utf8');
@@ -43,6 +65,13 @@ class UnderpostDeploy {
43
65
  deployGroupId,
44
66
  });
45
67
  },
68
+ /**
69
+ * Creates a router configuration for a list of deployments.
70
+ * @param {string} deployList - List of deployment IDs to include in the router.
71
+ * @param {string} env - Environment for which the router is being created.
72
+ * @returns {object} - Router configuration for the specified deployments.
73
+ * @memberof UnderpostDeploy
74
+ */
46
75
  async routerFactory(deployList, env) {
47
76
  const initEnvPath = `./engine-private/conf/${deployList.split(',')[0]}/.env.${env}`;
48
77
  const initEnvObj = dotenv.parse(fs.readFileSync(initEnvPath, 'utf8'));
@@ -51,6 +80,15 @@ class UnderpostDeploy {
51
80
  await Config.build('proxy', deployList);
52
81
  return buildPortProxyRouter(env === 'development' ? 80 : 443, buildProxyRouter());
53
82
  },
83
+ /**
84
+ * Creates a YAML service configuration for a deployment.
85
+ * @param {string} deployId - Deployment ID for which the service is being created.
86
+ * @param {string} env - Environment for which the service is being created.
87
+ * @param {number} port - Port number for the service.
88
+ * @param {Array<string>} deploymentVersions - List of deployment versions.
89
+ * @returns {string} - YAML service configuration for the specified deployment.
90
+ * @memberof UnderpostDeploy
91
+ */
54
92
  deploymentYamlServiceFactory({ deployId, env, port, deploymentVersions }) {
55
93
  return deploymentVersions
56
94
  .map(
@@ -61,7 +99,19 @@ class UnderpostDeploy {
61
99
  )
62
100
  .join('');
63
101
  },
102
+ /**
103
+ * Creates a YAML deployment configuration for a deployment.
104
+ * @param {string} deployId - Deployment ID for which the deployment is being created.
105
+ * @param {string} env - Environment for which the deployment is being created.
106
+ * @param {string} suffix - Suffix for the deployment.
107
+ * @param {object} resources - Resource configuration for the deployment.
108
+ * @param {number} replicas - Number of replicas for the deployment.
109
+ * @param {string} image - Docker image for the deployment.
110
+ * @returns {string} - YAML deployment configuration for the specified deployment.
111
+ * @memberof UnderpostDeploy
112
+ */
64
113
  deploymentYamlPartsFactory({ deployId, env, suffix, resources, replicas, image }) {
114
+ const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
65
115
  return `apiVersion: apps/v1
66
116
  kind: Deployment
67
117
  metadata:
@@ -80,7 +130,7 @@ spec:
80
130
  spec:
81
131
  containers:
82
132
  - name: ${deployId}-${env}-${suffix}
83
- image: ${image ?? `localhost/rockylinux9-underpost:${Underpost.version}`}
133
+ image: ${image ?? `localhost/rockylinux9-underpost:v${packageJson.version}`}
84
134
  # resources:
85
135
  # requests:
86
136
  # memory: "${resources.requests.memory}"
@@ -114,6 +164,16 @@ spec:
114
164
  ports:
115
165
  {{ports}} type: LoadBalancer`;
116
166
  },
167
+ /**
168
+ * Builds a manifest for a list of deployments.
169
+ * @param {string} deployList - List of deployment IDs to include in the manifest.
170
+ * @param {string} env - Environment for which the manifest is being built.
171
+ * @param {object} options - Options for the manifest build process.
172
+ * @param {string} options.replicas - Number of replicas for each deployment.
173
+ * @param {string} options.image - Docker image for the deployment.
174
+ * @returns {Promise<void>} - Promise that resolves when the manifest is built.
175
+ * @memberof UnderpostDeploy
176
+ */
117
177
  async buildManifest(deployList, env, options) {
118
178
  const resources = UnderpostDeploy.API.resourcesFactory();
119
179
  const replicas = options.replicas;
@@ -124,7 +184,6 @@ spec:
124
184
  if (!deployId) continue;
125
185
  const confServer = loadReplicas(
126
186
  JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8')),
127
- 'proxy',
128
187
  );
129
188
  const router = await UnderpostDeploy.API.routerFactory(deployId, env);
130
189
  const pathPortAssignmentData = pathPortAssignmentFactory(router, confServer);
@@ -208,6 +267,12 @@ spec:
208
267
  }
209
268
  }
210
269
  },
270
+ /**
271
+ * Builds a Certificate resource for a host using cert-manager.
272
+ * @param {string} host - Hostname for which the certificate is being built.
273
+ * @returns {string} - Certificate resource YAML for the specified host.
274
+ * @memberof UnderpostDeploy
275
+ */
211
276
  buildCertManagerCertificate({ host }) {
212
277
  return `
213
278
  ---
@@ -224,6 +289,12 @@ spec:
224
289
  kind: ClusterIssuer
225
290
  secretName: ${host}`;
226
291
  },
292
+ /**
293
+ * Retrieves the current traffic status for a deployment.
294
+ * @param {string} deployId - Deployment ID for which the traffic status is being retrieved.
295
+ * @returns {string|null} - Current traffic status ('blue' or 'green') or null if not found.
296
+ * @memberof UnderpostDeploy
297
+ */
227
298
  getCurrentTraffic(deployId) {
228
299
  // kubectl get deploy,sts,svc,configmap,secret -n default -o yaml --export > default.yaml
229
300
  const hostTest = Object.keys(
@@ -232,6 +303,32 @@ spec:
232
303
  const info = shellExec(`sudo kubectl get HTTPProxy/${hostTest} -o yaml`, { silent: true, stdout: true });
233
304
  return info.match('blue') ? 'blue' : info.match('green') ? 'green' : null;
234
305
  },
306
+
307
+ /**
308
+ * Callback function for handling deployment options.
309
+ * @param {string} deployList - List of deployment IDs to include in the manifest.
310
+ * @param {string} env - Environment for which the manifest is being built.
311
+ * @param {object} options - Options for the manifest build process.
312
+ * @param {string} options.remove - Whether to remove the deployment.
313
+ * @param {string} options.infoRouter - Whether to display router information.
314
+ * @param {string} options.sync - Whether to synchronize the deployment.
315
+ * @param {string} options.buildManifest - Whether to build the manifest.
316
+ * @param {string} options.infoUtil - Whether to display utility information.
317
+ * @param {string} options.expose - Whether to expose the deployment.
318
+ * @param {string} options.cert - Whether to create a certificate.
319
+ * @param {string} options.certHosts - List of hosts for which certificates are being created.
320
+ * @param {string} options.versions - Comma-separated list of versions to deploy.
321
+ * @param {string} options.image - Docker image for the deployment.
322
+ * @param {string} options.traffic - Current traffic status for the deployment.
323
+ * @param {string} options.replicas - Number of replicas for the deployment.
324
+ * @param {string} options.node - Node name for resource allocation.
325
+ * @param {string} options.restoreHosts - Whether to restore hosts.
326
+ * @param {string} options.disableUpdateDeployment - Whether to disable updating the deployment.
327
+ * @param {string} options.infoTraffic - Whether to display traffic information.
328
+ * @param {string} options.etcHosts - Whether to update /etc/hosts.
329
+ * @returns {Promise<void>} - Promise that resolves when the callback is complete.
330
+ * @memberof UnderpostDeploy
331
+ */
235
332
  async callback(
236
333
  deployList = '',
237
334
  env = 'development',
@@ -399,6 +496,13 @@ EOF`);
399
496
  ` + renderHosts,
400
497
  );
401
498
  },
499
+ /**
500
+ * Retrieves information about a deployment.
501
+ * @param {string} deployId - Deployment ID for which information is being retrieved.
502
+ * @param {string} kindType - Type of Kubernetes resource to retrieve information for (e.g. 'pods').
503
+ * @returns {Array<object>} - Array of objects containing information about the deployment.
504
+ * @memberof UnderpostDeploy
505
+ */
402
506
  get(deployId, kindType = 'pods') {
403
507
  const raw = shellExec(`sudo kubectl get ${kindType} --all-namespaces -o wide`, {
404
508
  stdout: true,
@@ -430,6 +534,11 @@ EOF`);
430
534
 
431
535
  return result;
432
536
  },
537
+ /**
538
+ * Retrieves the resources factory for a deployment.
539
+ * @returns {object} - Object containing the resources factory for the deployment.
540
+ * @memberof UnderpostDeploy
541
+ */
433
542
  resourcesFactory() {
434
543
  return {
435
544
  requests: {
@@ -443,6 +552,14 @@ EOF`);
443
552
  totalPods: UnderpostRootEnv.API.get('total-pods'),
444
553
  };
445
554
  },
555
+ /**
556
+ * Checks if a container file exists in a pod.
557
+ * @param {object} options - Options for the check.
558
+ * @param {string} options.podName - Name of the pod to check.
559
+ * @param {string} options.path - Path to the container file to check.
560
+ * @returns {boolean} - True if the container file exists, false otherwise.
561
+ * @memberof UnderpostDeploy
562
+ */
446
563
  existsContainerFile({ podName, path }) {
447
564
  return JSON.parse(
448
565
  shellExec(`kubectl exec ${podName} -- test -f ${path} && echo "true" || echo "false"`, {
@@ -452,6 +569,15 @@ EOF`);
452
569
  }).trim(),
453
570
  );
454
571
  },
572
+ /**
573
+ * Checks the status of a deployment.
574
+ * @param {string} deployId - Deployment ID for which the status is being checked.
575
+ * @param {string} env - Environment for which the status is being checked.
576
+ * @param {string} traffic - Current traffic status for the deployment.
577
+ * @param {Array<string>} ignoresNames - List of pod names to ignore.
578
+ * @returns {object} - Object containing the status of the deployment.
579
+ * @memberof UnderpostDeploy
580
+ */
455
581
  checkDeploymentReadyStatus(deployId, env, traffic, ignoresNames = []) {
456
582
  const cmd = `underpost config get container-status`;
457
583
  const pods = UnderpostDeploy.API.get(`${deployId}-${env}-${traffic}`);
@@ -476,12 +602,25 @@ EOF`);
476
602
  readyPods,
477
603
  };
478
604
  },
605
+ /**
606
+ * Creates a configmap for a deployment.
607
+ * @param {string} env - Environment for which the configmap is being created.
608
+ * @memberof UnderpostDeploy
609
+ */
479
610
  configMap(env) {
480
611
  shellExec(`kubectl delete configmap underpost-config`);
481
612
  shellExec(
482
613
  `kubectl create configmap underpost-config --from-file=/home/dd/engine/engine-private/conf/dd-cron/.env.${env}`,
483
614
  );
484
615
  },
616
+ /**
617
+ * Switches the traffic for a deployment.
618
+ * @param {string} deployId - Deployment ID for which the traffic is being switched.
619
+ * @param {string} env - Environment for which the traffic is being switched.
620
+ * @param {string} targetTraffic - Target traffic status for the deployment.
621
+ * @param {number} replicas - Number of replicas for the deployment.
622
+ * @memberof UnderpostDeploy
623
+ */
485
624
  switchTraffic(deployId, env, targetTraffic, replicas = 1) {
486
625
  UnderpostRootEnv.API.set(`${deployId}-${env}-traffic`, targetTraffic);
487
626
  shellExec(
@@ -489,6 +628,11 @@ EOF`);
489
628
  );
490
629
  shellExec(`sudo kubectl apply -f ./engine-private/conf/${deployId}/build/${env}/proxy.yaml`);
491
630
  },
631
+ /**
632
+ * Creates a hosts file for a deployment.
633
+ * @param {Array<string>} hosts - List of hosts to be added to the hosts file.
634
+ * @memberof UnderpostDeploy
635
+ */
492
636
  etcHostFactory(hosts = []) {
493
637
  const renderHosts = `127.0.0.1 ${hosts.join(
494
638
  ' ',
@@ -498,6 +642,15 @@ EOF`);
498
642
  fs.writeFileSync(`/etc/hosts`, renderHosts, 'utf8');
499
643
  return { renderHosts };
500
644
  },
645
+ /**
646
+ * Checks if a TLS context is valid.
647
+ * @param {object} options - Options for the check.
648
+ * @param {string} options.host - Host for which the TLS context is being checked.
649
+ * @param {string} options.env - Environment for which the TLS context is being checked.
650
+ * @param {object} options.options - Options for the TLS context check.
651
+ * @returns {boolean} - True if the TLS context is valid, false otherwise.
652
+ * @memberof UnderpostDeploy
653
+ */
501
654
  isValidTLSContext: ({ host, env, options }) =>
502
655
  env === 'production' &&
503
656
  options.cert === true &&
package/src/cli/env.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Environment module for managing the environment variables of the underpost root
3
+ * @module src/cli/env.js
4
+ * @namespace UnderpostEnv
5
+ */
6
+
1
7
  import { getNpmRootPath, writeEnv } from '../server/conf.js';
2
8
  import fs from 'fs-extra';
3
9
  import { loggerFactory } from '../server/logger.js';
@@ -7,8 +13,20 @@ dotenv.config();
7
13
 
8
14
  const logger = loggerFactory(import.meta);
9
15
 
16
+ /**
17
+ * @class UnderpostEnv
18
+ * @description Manages the environment variables of the underpost root.
19
+ * @memberof UnderpostEnv
20
+ */
10
21
  class UnderpostRootEnv {
11
22
  static API = {
23
+ /**
24
+ * @method set
25
+ * @description Sets an environment variable in the underpost root environment.
26
+ * @param {string} key - The key of the environment variable to set.
27
+ * @param {string} value - The value of the environment variable to set.
28
+ * @memberof UnderpostEnv
29
+ */
12
30
  set(key, value) {
13
31
  const exeRootPath = `${getNpmRootPath()}/underpost`;
14
32
  const envPath = `${exeRootPath}/.env`;
@@ -17,6 +35,12 @@ class UnderpostRootEnv {
17
35
  env[key] = value;
18
36
  writeEnv(envPath, env);
19
37
  },
38
+ /**
39
+ * @method delete
40
+ * @description Deletes an environment variable from the underpost root environment.
41
+ * @param {string} key - The key of the environment variable to delete.
42
+ * @memberof UnderpostEnv
43
+ */
20
44
  delete(key) {
21
45
  const exeRootPath = `${getNpmRootPath()}/underpost`;
22
46
  const envPath = `${exeRootPath}/.env`;
@@ -25,6 +49,15 @@ class UnderpostRootEnv {
25
49
  delete env[key];
26
50
  writeEnv(envPath, env);
27
51
  },
52
+ /**
53
+ * @method get
54
+ * @description Gets an environment variable from the underpost root environment.
55
+ * @param {string} key - The key of the environment variable to get.
56
+ * @param {string} value - The value of the environment variable to get.
57
+ * @param {object} options - Options for getting the environment variable.
58
+ * @param {boolean} [options.plain=false] - If true, returns the environment variable value as a string.
59
+ * @memberof UnderpostEnv
60
+ */
28
61
  get(key, value, options = { plain: false }) {
29
62
  const exeRootPath = `${getNpmRootPath()}/underpost`;
30
63
  const envPath = `${exeRootPath}/.env`;
@@ -36,6 +69,11 @@ class UnderpostRootEnv {
36
69
  options?.plain === true ? console.log(env[key]) : logger.info(`${key}(${typeof env[key]})`, env[key]);
37
70
  return env[key];
38
71
  },
72
+ /**
73
+ * @method list
74
+ * @description Lists all environment variables in the underpost root environment.
75
+ * @memberof UnderpostEnv
76
+ */
39
77
  list() {
40
78
  const exeRootPath = `${getNpmRootPath()}/underpost`;
41
79
  const envPath = `${exeRootPath}/.env`;
@@ -47,6 +85,11 @@ class UnderpostRootEnv {
47
85
  logger.info('underpost root', env);
48
86
  return env;
49
87
  },
88
+ /**
89
+ * @method clean
90
+ * @description Cleans the underpost root environment by removing the environment file.
91
+ * @memberof UnderpostEnv
92
+ */
50
93
  clean() {
51
94
  const exeRootPath = `${getNpmRootPath()}/underpost`;
52
95
  const envPath = `${exeRootPath}/.env`;
package/src/cli/fs.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * File storage module for managing file operations using Cloudinary.
3
+ * @module src/cli/fs.js
4
+ * @namespace UnderpostFileStorage
5
+ */
6
+
1
7
  import { v2 as cloudinary } from 'cloudinary';
2
8
  import { loggerFactory } from '../server/logger.js';
3
9
  import dotenv from 'dotenv';
@@ -11,8 +17,19 @@ dotenv.config();
11
17
 
12
18
  const logger = loggerFactory(import.meta);
13
19
 
20
+ /**
21
+ * @class UnderpostFileStorage
22
+ * @description Manages file storage operations using Cloudinary.
23
+ * This class provides a set of static methods to upload, pull, and delete files
24
+ * from Cloudinary, as well as manage a local storage configuration file.
25
+ */
14
26
  class UnderpostFileStorage {
15
27
  static API = {
28
+ /**
29
+ * @method cloudinaryConfig
30
+ * @description Configures the Cloudinary client with environment variables.
31
+ * @memberof UnderpostFileStorage
32
+ */
16
33
  cloudinaryConfig() {
17
34
  // https://console.cloudinary.com/
18
35
  cloudinary.config({
@@ -21,6 +38,15 @@ class UnderpostFileStorage {
21
38
  api_secret: process.env.CLOUDINARY_API_SECRET,
22
39
  });
23
40
  },
41
+ /**
42
+ * @method getStorageConf
43
+ * @description Retrieves the storage configuration for a specific deployment.
44
+ * @param {object} options - An object containing deployment-specific options.
45
+ * @param {string} options.deployId - The identifier for the deployment.
46
+ * @param {string} [options.storageFilePath] - The path to the storage configuration file.
47
+ * @returns {object} An object containing the storage configuration and storage file path.
48
+ * @memberof UnderpostFileStorage
49
+ */
24
50
  getStorageConf(options) {
25
51
  let storage, storageConf;
26
52
  if (options.deployId && typeof options.deployId === 'string') {
@@ -30,9 +56,31 @@ class UnderpostFileStorage {
30
56
  }
31
57
  return { storage, storageConf };
32
58
  },
59
+ /**
60
+ * @method writeStorageConf
61
+ * @description Writes the storage configuration to a file.
62
+ * @param {object} storage - The storage configuration object.
63
+ * @param {string} storageConf - The path to the storage configuration file.
64
+ * @memberof UnderpostFileStorage
65
+ */
33
66
  writeStorageConf(storage, storageConf) {
34
67
  if (storage) fs.writeFileSync(storageConf, JSON.stringify(storage, null, 4), 'utf8');
35
68
  },
69
+ /**
70
+ * @method recursiveCallback
71
+ * @description Recursively processes files and directories based on the provided options.
72
+ * @param {string} path - The path to the directory to process.
73
+ * @param {object} [options] - An object containing options for the recursive callback.
74
+ * @param {boolean} [options.rm=false] - Flag to remove files and directories.
75
+ * @param {boolean} [options.recursive=false] - Flag to process directories recursively.
76
+ * @param {string} [options.deployId=''] - The identifier for the deployment.
77
+ * @param {boolean} [options.force=false] - Flag to force file operations.
78
+ * @param {boolean} [options.pull=false] - Flag to pull files from storage.
79
+ * @param {boolean} [options.git=false] - Flag to use Git for file operations.
80
+ * @param {string} [options.storageFilePath=''] - The path to the storage configuration file.
81
+ * @returns {Promise<void>} A promise that resolves when the recursive callback is complete.
82
+ * @memberof UnderpostFileStorage
83
+ */
36
84
  async recursiveCallback(
37
85
  path,
38
86
  options = {
@@ -84,6 +132,21 @@ class UnderpostFileStorage {
84
132
  shellExec(`underpost cmt ${path} feat`);
85
133
  }
86
134
  },
135
+ /**
136
+ * @method callback
137
+ * @description Orchestrates file storage operations based on the provided options.
138
+ * This method handles file uploads, deletions, and recursive processing of directories.
139
+ * @param {string} path - The path to the file or directory to process.
140
+ * @param {object} [options] - An object containing options for the callback.
141
+ * @param {boolean} [options.rm=false] - Flag to remove files and directories.
142
+ * @param {boolean} [options.recursive=false] - Flag to process directories recursively.
143
+ * @param {string} [options.deployId=''] - The identifier for the deployment.
144
+ * @param {boolean} [options.force=false] - Flag to force file operations.
145
+ * @param {boolean} [options.pull=false] - Flag to pull files from storage.
146
+ * @param {boolean} [options.git=false] - Flag to use Git for file operations.
147
+ * @returns {Promise<void>} A promise that resolves when the callback is complete.
148
+ * @memberof UnderpostFileStorage
149
+ */
87
150
  async callback(
88
151
  path,
89
152
  options = { rm: false, recursive: false, deployId: '', force: false, pull: false, git: false },
@@ -94,6 +157,16 @@ class UnderpostFileStorage {
94
157
  if (options.rm === true) return await UnderpostFileStorage.API.delete(path, options);
95
158
  return await UnderpostFileStorage.API.upload(path, options);
96
159
  },
160
+ /**
161
+ * @method upload
162
+ * @description Uploads a file to Cloudinary.
163
+ * @param {string} path - The path to the file to upload.
164
+ * @param {object} [options] - An object containing options for the upload.
165
+ * @param {boolean} [options.force=false] - Flag to force file operations.
166
+ * @param {string} [options.storageFilePath=''] - The path to the storage configuration file.
167
+ * @returns {Promise<object>} A promise that resolves to the upload result.
168
+ * @memberof UnderpostFileStorage
169
+ */
97
170
  async upload(
98
171
  path,
99
172
  options = { rm: false, recursive: false, deployId: '', force: false, pull: false, storageFilePath: '' },
@@ -115,6 +188,13 @@ class UnderpostFileStorage {
115
188
  UnderpostFileStorage.API.writeStorageConf(storage, storageConf);
116
189
  return uploadResult;
117
190
  },
191
+ /**
192
+ * @method pull
193
+ * @description Pulls a file from Cloudinary.
194
+ * @param {string} path - The path to the file to pull.
195
+ * @returns {Promise<void>} A promise that resolves when the file is pulled.
196
+ * @memberof UnderpostFileStorage
197
+ */
118
198
  async pull(path) {
119
199
  UnderpostFileStorage.API.cloudinaryConfig();
120
200
  const folder = dir.dirname(path);
@@ -138,6 +218,13 @@ class UnderpostFileStorage {
138
218
  logger.info('delete result', deleteResult);
139
219
  return deleteResult;
140
220
  },
221
+ /**
222
+ * @method file2Zip
223
+ * @description Converts a file to a zip file.
224
+ * @param {string} path - The path to the file to convert.
225
+ * @returns {string} The path to the zip file.
226
+ * @memberof UnderpostFileStorage
227
+ */
141
228
  file2Zip(path) {
142
229
  const zip = new AdmZip();
143
230
  zip.addLocalFile(path, '/');
@@ -145,6 +232,13 @@ class UnderpostFileStorage {
145
232
  zip.writeZip(path);
146
233
  return path;
147
234
  },
235
+ /**
236
+ * @method zip2File
237
+ * @description Converts a zip file to a file.
238
+ * @param {string} path - The path to the zip file to convert.
239
+ * @returns {string} The path to the file.
240
+ * @memberof UnderpostFileStorage
241
+ */
148
242
  zip2File(path) {
149
243
  const zip = new AdmZip(path);
150
244
  path = path.replaceAll('.zip', '');
package/src/cli/image.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Image management module for pull, build, creation of docker images and loading them into Kubernetes clusters
3
+ * @module src/cli/image.js
4
+ * @namespace UnderpostImage
5
+ */
6
+
1
7
  import fs from 'fs-extra';
2
8
  import dotenv from 'dotenv';
3
9
  import { loggerFactory } from '../server/logger.js';
@@ -22,6 +28,7 @@ class UnderpostImage {
22
28
  * @param {boolean} [options.k3sLoad=false] - If true, load image into K3s cluster.
23
29
  * @param {string} [options.path=false] - Path to the Dockerfile context.
24
30
  * @param {string} [options.version=''] - Version tag for the image.
31
+ * @memberof UnderpostImage
25
32
  */
26
33
  pullBaseImages(
27
34
  options = {
@@ -68,6 +75,7 @@ class UnderpostImage {
68
75
  * @param {boolean} [options.secrets=false] - If true, load secrets from the .env file for the build.
69
76
  * @param {string} [options.secretsPath=''] - Custom path to the .env file for secrets.
70
77
  * @param {boolean} [options.reset=false] - If true, perform a no-cache build.
78
+ * @memberof UnderpostImage
71
79
  */
72
80
  build(
73
81
  options = {
package/src/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dotenv from 'dotenv';
2
2
  import { Command } from 'commander';
3
- import Underpost from '../index.js';
3
+ import Underpost, { UnderpostRootEnv } from '../index.js';
4
4
  import { getNpmRootPath, getUnderpostRootPath, loadConf } from '../server/conf.js';
5
5
  import fs from 'fs-extra';
6
6
  import { commitData } from '../client/components/core/CommonJs.js';
@@ -26,7 +26,8 @@ program
26
26
  .option('--deploy-id', 'Crete deploy ID conf env files')
27
27
  .option('--cluster', 'Create deploy ID cluster files and sync to current cluster')
28
28
  .option('--dev', 'Sets the development cli context')
29
- .description('Initializes a new Underpost project with a predefined structure.')
29
+ .option('--sub-conf <sub-conf>', 'Create sub conf env files')
30
+ .description('Initializes a new Underpost project, service, or configuration.')
30
31
  .action(Underpost.repo.new);
31
32
 
32
33
  // 'start' command: Start application servers, build pipelines, or services
@@ -86,10 +87,22 @@ program
86
87
  // 'env' command: Manage environment variables
87
88
  program
88
89
  .command('env')
89
- .argument('<deploy-id>', `The deployment configuration ID. Use 'clean' to restore default environment settings.`)
90
+ .argument(
91
+ '[deploy-id]',
92
+ `The deployment configuration ID. Use 'clean' to restore default environment settings. User 'root' to load root env. User 'current' to get plain current deploy Id.`,
93
+ )
90
94
  .argument('[env]', 'Optional: The environment to set (e.g., "production", "development"). Defaults to "production".')
95
+ .argument('[subConf]', 'Optional: The sub configuration to set.')
91
96
  .description('Sets environment variables and configurations related to a specific deployment ID.')
92
- .action(loadConf);
97
+ .action((deployId, env, subConf) => {
98
+ if (fs.existsSync(`./engine-private/conf/${deployId}/.env.${env}`))
99
+ dotenv.config({ path: `./engine-private/conf/${deployId}/.env.${env}`, override: true });
100
+ else if (deployId === 'root') {
101
+ deployId = UnderpostRootEnv.API.get('DEPLOY_ID');
102
+ } else dotenv.config({ path: `./.env`, override: true });
103
+
104
+ loadConf(deployId, subConf);
105
+ });
93
106
 
94
107
  // 'config' command: Manage Underpost configurations
95
108
  program
@@ -34,7 +34,6 @@ class UnderpostMonitor {
34
34
 
35
35
  const confServer = loadReplicas(
36
36
  JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8')),
37
- 'proxy',
38
37
  );
39
38
 
40
39
  const pathPortAssignmentData = pathPortAssignmentFactory(router, confServer);