underpost 2.8.1 → 2.8.6

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 (108) hide show
  1. package/.dockerignore +1 -0
  2. package/.github/workflows/ghpkg.yml +19 -49
  3. package/.github/workflows/npmpkg.yml +67 -0
  4. package/.github/workflows/publish.yml +5 -5
  5. package/.github/workflows/pwa-microservices-template.page.yml +12 -4
  6. package/.github/workflows/pwa-microservices-template.test.yml +2 -2
  7. package/.vscode/extensions.json +17 -71
  8. package/.vscode/settings.json +18 -3
  9. package/AUTHORS.md +16 -5
  10. package/CHANGELOG.md +103 -3
  11. package/Dockerfile +24 -66
  12. package/README.md +1 -28
  13. package/bin/build.js +186 -0
  14. package/bin/db.js +2 -24
  15. package/bin/deploy.js +169 -144
  16. package/bin/file.js +59 -16
  17. package/bin/hwt.js +0 -10
  18. package/bin/index.js +201 -60
  19. package/bin/ssl.js +19 -11
  20. package/bin/util.js +9 -104
  21. package/bin/vs.js +26 -2
  22. package/conf.js +29 -138
  23. package/docker-compose.yml +1 -1
  24. package/manifests/deployment/mongo-express/deployment.yaml +60 -0
  25. package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
  26. package/manifests/kind-config-dev.yaml +12 -0
  27. package/manifests/kind-config.yaml +12 -0
  28. package/manifests/letsencrypt-prod.yaml +15 -0
  29. package/manifests/mariadb/config.yaml +10 -0
  30. package/manifests/mariadb/kustomization.yaml +9 -0
  31. package/manifests/mariadb/pv.yaml +12 -0
  32. package/manifests/mariadb/pvc.yaml +10 -0
  33. package/manifests/mariadb/secret.yaml +8 -0
  34. package/manifests/mariadb/service.yaml +10 -0
  35. package/manifests/mariadb/statefulset.yaml +55 -0
  36. package/manifests/mongodb/backup-access.yaml +16 -0
  37. package/manifests/mongodb/backup-cronjob.yaml +42 -0
  38. package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
  39. package/manifests/mongodb/configmap.yaml +26 -0
  40. package/manifests/mongodb/headless-service.yaml +10 -0
  41. package/manifests/mongodb/kustomization.yaml +11 -0
  42. package/manifests/mongodb/pv-pvc.yaml +23 -0
  43. package/manifests/mongodb/statefulset.yaml +125 -0
  44. package/manifests/mongodb-4.4/kustomization.yaml +7 -0
  45. package/manifests/mongodb-4.4/pv-pvc.yaml +23 -0
  46. package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
  47. package/manifests/valkey/kustomization.yaml +7 -0
  48. package/manifests/valkey/service.yaml +17 -0
  49. package/manifests/valkey/statefulset.yaml +39 -0
  50. package/package.json +133 -136
  51. package/src/api/core/core.service.js +1 -1
  52. package/src/api/user/user.model.js +16 -3
  53. package/src/api/user/user.service.js +1 -1
  54. package/src/cli/cluster.js +202 -0
  55. package/src/cli/cron.js +90 -0
  56. package/src/cli/db.js +212 -0
  57. package/src/cli/deploy.js +318 -0
  58. package/src/cli/env.js +52 -0
  59. package/src/cli/fs.js +149 -0
  60. package/src/cli/image.js +148 -0
  61. package/src/cli/repository.js +125 -0
  62. package/src/cli/script.js +53 -0
  63. package/src/cli/secrets.js +37 -0
  64. package/src/cli/test.js +118 -0
  65. package/src/client/components/core/Auth.js +22 -4
  66. package/src/client/components/core/CalendarCore.js +127 -50
  67. package/src/client/components/core/CommonJs.js +282 -19
  68. package/src/client/components/core/Css.js +1 -0
  69. package/src/client/components/core/CssCore.js +8 -4
  70. package/src/client/components/core/Docs.js +1 -2
  71. package/src/client/components/core/DropDown.js +5 -1
  72. package/src/client/components/core/Input.js +22 -6
  73. package/src/client/components/core/LoadingAnimation.js +8 -1
  74. package/src/client/components/core/Modal.js +40 -12
  75. package/src/client/components/core/Panel.js +92 -31
  76. package/src/client/components/core/PanelForm.js +25 -23
  77. package/src/client/components/core/Scroll.js +1 -0
  78. package/src/client/components/core/Translate.js +47 -9
  79. package/src/client/components/core/Validator.js +9 -1
  80. package/src/client/components/core/VanillaJs.js +0 -9
  81. package/src/client/components/core/Worker.js +34 -31
  82. package/src/client/services/core/core.service.js +15 -10
  83. package/src/client/services/default/default.management.js +4 -2
  84. package/src/client/ssr/Render.js +4 -1
  85. package/src/client/ssr/body/CacheControl.js +2 -3
  86. package/src/client/sw/default.sw.js +3 -3
  87. package/src/db/mongo/MongooseDB.js +29 -1
  88. package/src/index.js +85 -19
  89. package/src/runtime/lampp/Lampp.js +1 -13
  90. package/src/runtime/xampp/Xampp.js +0 -13
  91. package/src/server/auth.js +3 -3
  92. package/src/server/backup.js +49 -93
  93. package/src/server/client-build.js +36 -46
  94. package/src/server/client-formatted.js +6 -3
  95. package/src/server/conf.js +204 -54
  96. package/src/server/dns.js +30 -55
  97. package/src/server/downloader.js +0 -8
  98. package/src/server/logger.js +15 -10
  99. package/src/server/network.js +17 -43
  100. package/src/server/process.js +25 -2
  101. package/src/server/proxy.js +4 -26
  102. package/src/server/runtime.js +30 -30
  103. package/src/server/ssl.js +1 -1
  104. package/src/server/valkey.js +2 -0
  105. package/test/api.test.js +0 -8
  106. package/src/dns.js +0 -22
  107. package/src/server/prompt-optimizer.js +0 -28
  108. package/startup.js +0 -11
package/Dockerfile CHANGED
@@ -2,89 +2,47 @@ ARG BASE_DEBIAN=buster
2
2
 
3
3
  FROM debian:${BASE_DEBIAN}
4
4
 
5
- ENV DEBIAN_FRONTEND noninteractive
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
6
 
7
- WORKDIR /code
7
+ WORKDIR /home/dd
8
8
 
9
9
  # Set root password to root, format is 'user:password'.
10
10
  RUN echo 'root:root' | chpasswd
11
11
 
12
- RUN apt-get update --fix-missing && \
13
- apt-get upgrade -y && \
14
- # install sudo
15
- apt-get -y install sudo && \
16
- # net-tools provides netstat commands
17
- apt-get -y install curl net-tools && \
18
- apt-get -yq install openssh-server supervisor && \
19
- # Few handy utilities which are nice to have
20
- apt-get -y install nano vim less --no-install-recommends && \
21
- apt-get clean
12
+ RUN apt-get update --fix-missing
13
+ RUN apt-get upgrade -y
14
+ # install sudo
15
+ RUN apt-get -y install sudo
16
+ # net-tools provides netstat commands
17
+ RUN apt-get -y install curl net-tools
18
+ RUN apt-get -yq install openssh-server supervisor
19
+ # Few handy utilities which are nice to have
20
+ RUN apt-get -y install nano vim less --no-install-recommends
21
+ RUN apt-get clean
22
22
 
23
23
  # install ssh
24
- RUN mkdir -p /var/run/sshd && \
25
- # Allow root login via password
26
- sed -ri 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
24
+ RUN mkdir -p /var/run/sshd
25
+ # Allow root login via password
26
+ RUN sed -ri 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
27
27
 
28
28
  # copy supervisor config file to start openssh-server
29
29
  COPY supervisord-openssh-server.conf /etc/supervisor/conf.d/supervisord-openssh-server.conf
30
30
 
31
31
  # install open ssl git and others tools
32
- RUN apt-get install -yq --no-install-recommends \
33
- libssl-dev \
34
- curl \
35
- wget \
36
- git \
37
- gnupg
32
+ RUN apt-get install -yq --no-install-recommends libssl-dev curl wget git gnupg
38
33
 
39
34
  # install nodejs https://github.com/nodesource/distributions/blob/master/README.md#deb
40
- RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
41
- apt-get install -y nodejs \
42
- build-essential && \
43
- node --version && \
44
- npm --version
35
+ RUN curl -fsSL https://deb.nodesource.com/setup_23.x | bash -
36
+ RUN apt-get install -y nodejs build-essential
37
+ RUN node --version
38
+ RUN npm --version
45
39
 
46
-
47
- # install lampp
48
- RUN curl -Lo xampp-linux-installer.run https://sourceforge.net/projects/xampp/files/XAMPP%20Linux/7.4.30/xampp-linux-x64-7.4.30-1-installer.run?from_af=true && \
49
- chmod +x xampp-linux-installer.run && \
50
- bash -c './xampp-linux-installer.run' && \
51
- ln -sf /opt/lampp/lampp /usr/bin/lampp && \
52
- # Enable XAMPP web interface(remove security checks)
53
- sed -i.bak s'/Require local/Require all granted/g' /opt/lampp/etc/extra/httpd-xampp.conf && \
54
- # Enable error display in php
55
- sed -i.bak s'/display_errors=Off/display_errors=On/g' /opt/lampp/etc/php.ini && \
56
- # Enable includes of several configuration files
57
- mkdir /opt/lampp/apache2/conf.d && \
58
- echo "IncludeOptional /opt/lampp/apache2/conf.d/*.conf" >> /opt/lampp/etc/httpd.conf && \
59
- # Create a /www folder and a symbolic link to it in /opt/lampp/htdocs. It'll be accessible via http://localhost:[port]/www/
60
- # This is convenient because it doesn't interfere with xampp, phpmyadmin or other tools in /opt/lampp/htdocs
61
- # /opt/lampp/etc/httpd.conf
62
- mkdir /www && \
63
- ln -s /www /opt/lampp/htdocs
64
-
65
-
66
- # Install mongodb necessary libs
67
- RUN apt-get update && apt-get install -y apt-utils wget gnupg gnupg2 curl
68
-
69
- # Install mongodb
70
- RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -
71
- RUN echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list
72
- RUN apt-get update
73
- RUN apt-get install -y mongodb-org
74
-
75
- # BIND TO ALL ADAPTERS IN CONTAINER
76
- RUN sed -i "s,\\(^[[:blank:]]*bindIp:\\) .*,\\1 0.0.0.0," /etc/mongod.conf
77
-
78
- # Bundle app source
79
- # COPY . .
80
-
81
- # Install underpost cli
82
40
  RUN npm install -g underpost
83
41
 
42
+ VOLUME [ "/home/dd/engine/logs" ]
84
43
 
85
- VOLUME [ "/code/app/logs" ]
44
+ EXPOSE 22
86
45
 
87
- EXPOSE 22 80 443 3306 27017
88
- EXPOSE 3000-3020
46
+ EXPOSE 4000-4004
89
47
 
90
- CMD [ "node", "startup" ]
48
+ CMD [ "underpost", "new", "service" ]
package/README.md CHANGED
@@ -16,7 +16,7 @@ template
16
16
 
17
17
  <div align="center">
18
18
 
19
- <a target="_top" href='https://www.npmjs.com/package/npm/v/10.2.3' ><img alt='npm' src='https://img.shields.io/badge/npm v10.2.3-100000?style=flat&logo=npm&logoColor=white&labelColor=CB3837&color=727273'/></a> <a target="_top" href='https://nodejs.org/download/release/v22.9.0/' ><img alt='nodedotjs' src='https://img.shields.io/badge/node v22.9.0-100000?style=flat&logo=nodedotjs&logoColor=white&labelColor=5FA04E&color=727273'/></a> <a target="_top" href='https://pgp.mongodb.com/' ><img alt='mongodb' src='https://img.shields.io/badge/mongodb_server v7.0-100000?style=flat&logo=mongodb&logoColor=white&labelColor=47A248&color=727273'/></a>
19
+ <a target="_top" href='https://www.npmjs.com/package/npm/v/11.1.0' ><img alt='npm' src='https://img.shields.io/badge/npm v11.1.0-100000?style=flat&logo=npm&logoColor=white&labelColor=CB3837&color=727273'/></a> <a target="_top" href='https://nodejs.org/download/release/v22.9.0/' ><img alt='nodedotjs' src='https://img.shields.io/badge/node v23.8.0-100000?style=flat&logo=nodedotjs&logoColor=white&labelColor=5FA04E&color=727273'/></a> <a target="_top" href='https://pgp.mongodb.com/' ><img alt='mongodb' src='https://img.shields.io/badge/mongodb_server v7.0-100000?style=flat&logo=mongodb&logoColor=white&labelColor=47A248&color=727273'/></a>
20
20
 
21
21
  </div>
22
22
 
@@ -67,30 +67,3 @@ Run dev client server
67
67
  ```bash
68
68
  npm run dev
69
69
  ```
70
-
71
- Run dev api server
72
-
73
- ```bash
74
- npm run dev-api
75
- ```
76
-
77
- Run on `pm2`
78
-
79
- ```bash
80
- npm run pm2
81
- ```
82
-
83
- Run on `docker-compose`
84
-
85
- ```bash
86
- npm run start:docker
87
- ```
88
-
89
- Run on `docker`
90
-
91
- ```bash
92
- # build image
93
- docker build . -t app-name
94
- # run image
95
- docker run --name app-name-instance -p 41061:3001 -p 41062:3002 app-name
96
- ```
package/bin/build.js ADDED
@@ -0,0 +1,186 @@
1
+ import fs from 'fs-extra';
2
+ import { loggerFactory } from '../src/server/logger.js';
3
+ import { shellExec } from '../src/server/process.js';
4
+ import dotenv from 'dotenv';
5
+ import { getCapVariableName } from '../src/client/components/core/CommonJs.js';
6
+ import { getPathsSSR } from '../src/server/conf.js';
7
+
8
+ const baseConfPath = './engine-private/conf/dd-cron/.env.production';
9
+ if (fs.existsSync(baseConfPath)) dotenv.config({ path: baseConfPath, override: true });
10
+
11
+ const logger = loggerFactory(import.meta);
12
+
13
+ // (async () => {
14
+ // return;
15
+ // const files = await fs.readdir(`./src`);
16
+ // for (const relativePath of files) {
17
+ // }
18
+ // })();
19
+
20
+ const confName = process.argv[2];
21
+ const basePath = '../pwa-microservices-template';
22
+ const repoName = `engine-${confName.split('dd-')[1]}`;
23
+ const deployList = (confName === 'dd' ? fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8') : confName).split(
24
+ ',',
25
+ );
26
+
27
+ logger.info('', {
28
+ confName,
29
+ repoName,
30
+ basePath,
31
+ deployList,
32
+ });
33
+
34
+ if (process.argv.includes('clean')) {
35
+ if (fs.existsSync(`${basePath}/images`)) fs.copySync(`${basePath}/images`, `./images`);
36
+ shellExec(`cd ${basePath} && git checkout .`);
37
+ shellExec(`cd ${basePath} && git clean -f -d`);
38
+ process.exit(0);
39
+ }
40
+
41
+ if (process.argv.includes('conf')) {
42
+ for (const _confName of deployList) {
43
+ const _repoName = `engine-${_confName.split('dd-')[1]}`;
44
+ const privateRepoName = `${_repoName}-private`;
45
+ const privateGitUri = `${process.env.GITHUB_USERNAME}/${privateRepoName}`;
46
+
47
+ if (!fs.existsSync(`../${privateRepoName}`)) {
48
+ shellExec(`cd .. && underpost clone ${privateGitUri}`, { silent: true });
49
+ } else {
50
+ shellExec(`cd ../${privateRepoName} && underpost pull . ${privateGitUri}`);
51
+ }
52
+ const toPath = `../${privateRepoName}/conf/${_confName}`;
53
+ fs.removeSync(toPath);
54
+ fs.mkdirSync(toPath, { recursive: true });
55
+ fs.copySync(`./engine-private/conf/${_confName}`, toPath);
56
+ if (fs.existsSync(`./engine-private/replica`)) {
57
+ const replicas = await fs.readdir(`./engine-private/replica`);
58
+ for (const replica of replicas)
59
+ if (replica.match(_confName))
60
+ fs.copySync(`./engine-private/replica/${replica}`, `../${privateRepoName}/replica/${replica}`);
61
+ }
62
+ if (fs.existsSync(`./engine-private/itc-scripts`)) {
63
+ const itcScripts = await fs.readdir(`./engine-private/itc-scripts`);
64
+ for (const itcScript of itcScripts)
65
+ if (itcScript.match(_confName))
66
+ fs.copySync(`./engine-private/itc-scripts/${itcScript}`, `../${privateRepoName}/itc-scripts/${itcScript}`);
67
+ }
68
+ shellExec(
69
+ `cd ../${privateRepoName}` +
70
+ ` && git add .` +
71
+ ` && underpost cmt . ci engine-core-conf 'Update ${_confName} conf'` +
72
+ ` && underpost push . ${privateGitUri}`,
73
+ );
74
+ }
75
+ process.exit(0);
76
+ }
77
+
78
+ if (confName === 'dd') {
79
+ for (const _confName of deployList) {
80
+ shellExec(`node bin/build ${_confName}`);
81
+ }
82
+ process.exit(0);
83
+ }
84
+
85
+ const { DefaultConf } = await import(`../conf.${confName}.js`);
86
+
87
+ {
88
+ for (const host of Object.keys(DefaultConf.server)) {
89
+ for (const path of Object.keys(DefaultConf.server[host])) {
90
+ const { apis, ws } = DefaultConf.server[host][path];
91
+ if (apis)
92
+ for (const api of apis) {
93
+ {
94
+ const originPath = `./src/api/${api}`;
95
+ logger.info(`Build`, originPath);
96
+ fs.copySync(originPath, `${basePath}/src/api/${api}`);
97
+ }
98
+ {
99
+ const originPath = `./src/client/services/${api}`;
100
+ logger.info(`Build`, originPath);
101
+ fs.copySync(originPath, `${basePath}/src/client/services/${api}`);
102
+ }
103
+ }
104
+
105
+ if (ws && ws !== 'core' && ws !== 'default') {
106
+ fs.copySync(`./src/ws/${ws}`, `${basePath}/src/ws/${ws}`);
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ {
113
+ for (const client of Object.keys(DefaultConf.client)) {
114
+ const capName = getCapVariableName(client);
115
+ for (const component of Object.keys(DefaultConf.client[client].components)) {
116
+ const originPath = `./src/client/components/${component}`;
117
+ if (fs.existsSync(originPath)) {
118
+ logger.info(`Build`, originPath);
119
+ fs.copySync(originPath, `${basePath}/src/client/components/${component}`);
120
+ }
121
+ }
122
+ {
123
+ const originPath = `./src/client/${capName}.index.js`;
124
+ if (fs.existsSync(originPath)) {
125
+ logger.info(`Build`, originPath);
126
+ fs.copyFileSync(originPath, `${basePath}/src/client/${capName}.index.js`);
127
+ }
128
+ }
129
+ {
130
+ const originPath = `./src/client/public/${client}`;
131
+ if (fs.existsSync(originPath)) {
132
+ logger.info(`Build`, originPath);
133
+ fs.copySync(originPath, `${basePath}/src/client/public/${client}`);
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ {
140
+ for (const client of Object.keys(DefaultConf.ssr)) {
141
+ const ssrPaths = getPathsSSR(DefaultConf.ssr[client]);
142
+ for (const originPath of ssrPaths) {
143
+ if (fs.existsSync(originPath)) {
144
+ logger.info(`Build`, originPath);
145
+ fs.copySync(originPath, `${basePath}/${originPath}`);
146
+ }
147
+ }
148
+ }
149
+
150
+ shellExec(`node bin/deploy update-default-conf ${confName}`);
151
+
152
+ fs.copyFileSync(`./conf.${confName}.js`, `${basePath}/conf.js`);
153
+ fs.copyFileSync(
154
+ `./.github/workflows/engine.${confName.split('dd-')[1]}.ci.yml`,
155
+ `${basePath}/.github/workflows/engine.${confName.split('dd-')[1]}.ci.yml`,
156
+ );
157
+
158
+ switch (confName) {
159
+ case 'dd-cyberia':
160
+ fs.copyFileSync(`./bin/cyberia.js`, `${basePath}/bin/cyberia.js`);
161
+ break;
162
+
163
+ default:
164
+ break;
165
+ }
166
+
167
+ const packageJson = JSON.parse(fs.readFileSync(`${basePath}/package.json`, 'utf8'));
168
+ packageJson.name = repoName;
169
+ fs.writeFileSync(
170
+ `${basePath}/package.json`,
171
+ JSON.stringify(packageJson, null, 4).replaceAll('pwa-microservices-template', repoName),
172
+ 'utf8',
173
+ );
174
+
175
+ fs.copySync(`./src/cli`, `${basePath}/src/cli`);
176
+ if (!fs.existsSync(`${basePath}/images`)) fs.mkdirSync(`${basePath}/images`);
177
+
178
+ const env = process.argv.includes('development') ? 'development' : 'production';
179
+ const deploymentsFiles = ['Dockerfile', 'proxy.yaml', 'deployment.yaml', 'secret.yaml'];
180
+ // remove engine-private of .dockerignore for local testing
181
+ for (const file of deploymentsFiles) {
182
+ if (fs.existsSync(`./manifests/deployment/${confName}-${env}/${file}`)) {
183
+ fs.copyFileSync(`./manifests/deployment/${confName}-${env}/${file}`, `${basePath}/${file}`);
184
+ }
185
+ }
186
+ }
package/bin/db.js CHANGED
@@ -4,10 +4,9 @@ import { loggerFactory } from '../src/server/logger.js';
4
4
  import { MariaDB } from '../src/db/mariadb/MariaDB.js';
5
5
  import { Xampp } from '../src/runtime/xampp/Xampp.js';
6
6
  import { Lampp } from '../src/runtime/lampp/Lampp.js';
7
- import { getCapVariableName, getRestoreCronCmd, loadConf } from '../src/server/conf.js';
7
+ import { getCapVariableName, getRestoreCronCmd, loadConf, splitFileFactory } from '../src/server/conf.js';
8
8
  import { DataBaseProvider } from '../src/db/DataBaseProvider.js';
9
9
  import { hashPassword } from '../src/server/auth.js';
10
- import splitFile from 'split-file';
11
10
 
12
11
  const logger = loggerFactory(import.meta);
13
12
 
@@ -101,28 +100,7 @@ try {
101
100
 
102
101
  cmd = `mysqldump -u ${user} -p${password} ${name} > ${cmdBackupPath}`;
103
102
  shellExec(cmd);
104
- const stats = fs.statSync(cmdBackupPath);
105
- const maxSizeInBytes = 1024 * 1024 * 50; // 50 mb
106
- const fileSizeInBytes = stats.size;
107
- if (fileSizeInBytes > maxSizeInBytes) {
108
- await new Promise((resolve) => {
109
- splitFile
110
- .splitFileBySize(cmdBackupPath, maxSizeInBytes) // 50 mb
111
- .then((names) => {
112
- fs.writeFileSync(
113
- `${cmdBackupPath.split('/').slice(0, -1).join('/')}/${name}-parths.json`,
114
- JSON.stringify(names, null, 4),
115
- 'utf8',
116
- );
117
- resolve();
118
- })
119
- .catch((err) => {
120
- console.log('Error: ', err);
121
- resolve();
122
- });
123
- });
124
- fs.removeSync(cmdBackupPath);
125
- }
103
+ await splitFileFactory(name, cmdBackupPath);
126
104
  }
127
105
  break;
128
106
  case 'import':