@underpostnet/underpost 2.90.4 → 2.95.0

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 (41) hide show
  1. package/.github/workflows/pwa-microservices-template-page.cd.yml +5 -4
  2. package/.github/workflows/release.cd.yml +7 -7
  3. package/README.md +7 -8
  4. package/bin/build.js +6 -1
  5. package/bin/deploy.js +2 -196
  6. package/cli.md +154 -80
  7. package/manifests/deployment/dd-default-development/deployment.yaml +4 -4
  8. package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
  9. package/package.json +1 -1
  10. package/scripts/disk-clean.sh +216 -0
  11. package/scripts/rocky-setup.sh +1 -0
  12. package/scripts/ssh-cluster-info.sh +4 -3
  13. package/src/cli/cluster.js +1 -1
  14. package/src/cli/db.js +1143 -201
  15. package/src/cli/deploy.js +93 -24
  16. package/src/cli/env.js +2 -2
  17. package/src/cli/image.js +198 -133
  18. package/src/cli/index.js +111 -44
  19. package/src/cli/lxd.js +73 -74
  20. package/src/cli/monitor.js +20 -9
  21. package/src/cli/repository.js +212 -5
  22. package/src/cli/run.js +207 -74
  23. package/src/cli/ssh.js +642 -14
  24. package/src/client/components/core/CommonJs.js +0 -1
  25. package/src/db/mongo/MongooseDB.js +5 -1
  26. package/src/index.js +1 -1
  27. package/src/monitor.js +11 -1
  28. package/src/server/backup.js +1 -1
  29. package/src/server/conf.js +1 -1
  30. package/src/server/dns.js +242 -1
  31. package/src/server/process.js +6 -1
  32. package/src/server/start.js +2 -0
  33. package/scripts/snap-clean.sh +0 -26
  34. package/src/client/public/default/plantuml/client-conf.svg +0 -1
  35. package/src/client/public/default/plantuml/client-schema.svg +0 -1
  36. package/src/client/public/default/plantuml/cron-conf.svg +0 -1
  37. package/src/client/public/default/plantuml/cron-schema.svg +0 -1
  38. package/src/client/public/default/plantuml/server-conf.svg +0 -1
  39. package/src/client/public/default/plantuml/server-schema.svg +0 -1
  40. package/src/client/public/default/plantuml/ssr-conf.svg +0 -1
  41. package/src/client/public/default/plantuml/ssr-schema.svg +0 -1
@@ -4,7 +4,7 @@ name: CD | Gihub page | PWA Microservices Template
4
4
  on:
5
5
  # Runs on pushes targeting the default branch
6
6
  push:
7
- branches: ["main"]
7
+ branches: ['main']
8
8
 
9
9
  # Allows you to run this workflow manually from the Actions tab
10
10
  workflow_dispatch:
@@ -18,7 +18,7 @@ permissions:
18
18
  # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19
19
  # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20
20
  concurrency:
21
- group: "pages"
21
+ group: 'pages'
22
22
  cancel-in-progress: false
23
23
 
24
24
  jobs:
@@ -53,7 +53,8 @@ jobs:
53
53
  run: |
54
54
  npm install -g underpost
55
55
  npm install
56
- node bin/deploy update-default-conf dd-github-pages
56
+ node bin new --default-conf --conf-workflow-id dd-github-pages
57
+ node bin new --deploy-id dd-github-pages
57
58
  underpost env dd-github-pages production
58
59
  env-cmd -f .env.production node bin/deploy build-full-client dd-github-pages underpostnet.github.io /pwa-microservices-template-ghpkg
59
60
  # git lfs install
@@ -66,7 +67,7 @@ jobs:
66
67
  uses: actions/upload-pages-artifact@v3
67
68
  with:
68
69
  # Upload entire repository
69
- path: "./public/underpostnet.github.io/pwa-microservices-template-ghpkg/"
70
+ path: './public/underpostnet.github.io/pwa-microservices-template-ghpkg/'
70
71
  - name: Deploy to GitHub Pages
71
72
  id: deployment
72
73
  uses: actions/deploy-pages@v4
@@ -30,11 +30,11 @@ jobs:
30
30
  script: |
31
31
  set -e
32
32
  echo "Starting remote release deploy"
33
- underpost run pull
34
- underpost run secret
35
- npm install -g underpost
36
33
  cd /home/dd/engine
37
- underpost run secret
38
- node bin run --dev git-conf
39
- node bin run --dev template-deploy-image
40
- node bin run --dev ssh-deploy sync-engine-test
34
+ sudo -n -- /bin/bash -lc "node bin run pull"
35
+ sudo -n -- /bin/bash -lc "underpost run secret"
36
+ sudo -n -- /bin/bash -lc "npm install -g underpost"
37
+ sudo -n -- /bin/bash -lc "underpost run secret"
38
+ sudo -n -- /bin/bash -lc "node bin run --dev git-conf"
39
+ sudo -n -- /bin/bash -lc "node bin run --dev template-deploy-image"
40
+ sudo -n -- /bin/bash -lc "node bin run --dev ssh-deploy sync-engine-test"
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  <!-- badges -->
20
20
 
21
- [![Node.js CI](https://github.com/underpostnet/engine/actions/workflows/docker-image.ci.yml/badge.svg?branch=master)](https://github.com/underpostnet/engine/actions/workflows/docker-image.yml) [![Test](https://github.com/underpostnet/engine/actions/workflows/coverall.ci.yml/badge.svg?branch=master)](https://github.com/underpostnet/engine/actions/workflows/coverall.ci.yml) [![Downloads](https://img.shields.io/npm/dm/underpost.svg)](https://www.npmjs.com/package/underpost) [![Socket Badge](https://socket.dev/api/badge/npm/package/underpost/2.90.4)](https://socket.dev/npm/package/underpost/overview/2.90.4) [![Coverage Status](https://coveralls.io/repos/github/underpostnet/engine/badge.svg?branch=master)](https://coveralls.io/github/underpostnet/engine?branch=master) [![Version](https://img.shields.io/npm/v/underpost.svg)](https://www.npmjs.org/package/underpost) [![License](https://img.shields.io/npm/l/underpost.svg)](https://www.npmjs.com/package/underpost)
21
+ [![Node.js CI](https://github.com/underpostnet/engine/actions/workflows/docker-image.ci.yml/badge.svg?branch=master)](https://github.com/underpostnet/engine/actions/workflows/docker-image.yml) [![Test](https://github.com/underpostnet/engine/actions/workflows/coverall.ci.yml/badge.svg?branch=master)](https://github.com/underpostnet/engine/actions/workflows/coverall.ci.yml) [![Downloads](https://img.shields.io/npm/dm/underpost.svg)](https://www.npmjs.com/package/underpost) [![Socket Badge](https://socket.dev/api/badge/npm/package/underpost/2.95.0)](https://socket.dev/npm/package/underpost/overview/2.95.0) [![Coverage Status](https://coveralls.io/repos/github/underpostnet/engine/badge.svg?branch=master)](https://coveralls.io/github/underpostnet/engine?branch=master) [![Version](https://img.shields.io/npm/v/underpost.svg)](https://www.npmjs.org/package/underpost) [![License](https://img.shields.io/npm/l/underpost.svg)](https://www.npmjs.com/package/underpost)
22
22
 
23
23
  <!-- end-badges -->
24
24
 
@@ -66,7 +66,7 @@ Run dev client server
66
66
  npm run dev
67
67
  ```
68
68
  <!-- -->
69
- ## underpost ci/cd cli v2.90.4
69
+ ## underpost ci/cd cli v2.95.0
70
70
 
71
71
  ### Usage: `underpost [options] [command]`
72
72
  ```
@@ -85,22 +85,21 @@ Commands:
85
85
  static [options] Manages static build of page, bundles, and documentation with comprehensive customization options.
86
86
  config [options] <operator> [key] [value] Manages Underpost configurations using various operators.
87
87
  root Displays the root path of the npm installation.
88
- ip [options] Displays the current public machine IP addresses.
88
+ ip [options] [ips] Displays the current public machine IP addresses.
89
89
  cluster [options] [pod-name] Manages Kubernetes clusters, defaulting to Kind cluster initialization.
90
90
  deploy [options] [deploy-list] [env] Manages application deployments, defaulting to deploying development pods.
91
91
  secret [options] <platform> Manages secrets for various platforms.
92
- dockerfile-image-build [options] Builds a Docker image from a specified Dockerfile with various options for naming, saving, and loading.
93
- dockerfile-pull-base-images [options] Pulls required Underpost Dockerfile base images and optionally loads them into clusters.
92
+ image [options] Manages Docker images, including building, saving, and loading into Kubernetes clusters.
94
93
  install Quickly imports Underpost npm dependencies by copying them.
95
- db [options] <deploy-list> Manages database operations, including import, export, and collection management.
94
+ db [options] <deploy-list> Manages database operations with support for MariaDB and MongoDB, including import/export, multi-pod targeting, and Git integration.
96
95
  metadata [options] [deploy-id] [host] [path] Manages cluster metadata operations, including import and export.
97
96
  script [options] <operator> <script-name> [script-value] Supports a variety of built-in Underpost global scripts, their preset lifecycle events, and arbitrary custom scripts.
98
97
  cron [options] [deploy-list] [job-list] Manages cron jobs, including initialization, execution, and configuration updates.
99
98
  fs [options] [path] Manages file storage, defaulting to file upload operations.
100
99
  test [options] [deploy-list] Manages and runs tests, defaulting to the current Underpost default test suite.
101
100
  monitor [options] <deploy-id> [env] Manages health server monitoring for specified deployments.
102
- ssh [options] Import and start ssh server and client based on current default deployment ID.
103
- run [options] <runner-id> [path] Runs a script from the specified path.
101
+ ssh [options]
102
+ run [options] <runner-id> [path] Runs specified scripts using various runners.
104
103
  lxd [options] Manages LXD containers and virtual machines.
105
104
  baremetal [options] [workflow-id] [hostname] [ip-address] Manages baremetal server operations, including installation, database setup, commissioning, and user management.
106
105
  help [command] display help for command
package/bin/build.js CHANGED
@@ -47,7 +47,9 @@ if (process.argv.includes('conf')) {
47
47
  if (!fs.existsSync(`../${privateRepoName}`)) {
48
48
  shellExec(`cd .. && underpost clone ${privateGitUri}`, { silent: true });
49
49
  } else {
50
- shellExec(`cd ../${privateRepoName} && git checkout . && git clean -f -d && underpost pull . ${privateGitUri}`);
50
+ shellExec(`cd ../${privateRepoName} && git checkout . && git clean -f -d && underpost pull . ${privateGitUri}`, {
51
+ silent: true,
52
+ });
51
53
  }
52
54
  const toPath = `../${privateRepoName}/conf/${_confName}`;
53
55
  fs.removeSync(toPath);
@@ -72,6 +74,9 @@ if (process.argv.includes('conf')) {
72
74
  ` && git add .` +
73
75
  ` && underpost cmt . ci engine-core-conf 'Update ${_confName} conf'` +
74
76
  ` && underpost push . ${privateGitUri}`,
77
+ {
78
+ silent: true,
79
+ },
75
80
  );
76
81
  }
77
82
  process.exit(0);
package/bin/deploy.js CHANGED
@@ -24,10 +24,8 @@ import {
24
24
  buildCliDoc,
25
25
  } from '../src/server/conf.js';
26
26
  import { buildClient } from '../src/server/client-build.js';
27
- import { DefaultConf } from '../conf.js';
28
27
  import colors from 'colors';
29
28
  import { program } from '../src/cli/index.js';
30
- import Dns, { getLocalIPv4Address } from '../src/server/dns.js';
31
29
  import { timer } from '../src/client/components/core/CommonJs.js';
32
30
 
33
31
  colors.enable();
@@ -598,198 +596,6 @@ ${shellExec(`git log | grep Author: | sort -u`, { stdout: true }).split(`\n`).jo
598
596
  break;
599
597
  }
600
598
 
601
- case 'update-default-conf': {
602
- const defaultServer = DefaultConf.server['default.net']['/'];
603
- let confName = process.argv[3];
604
- let defaultConf = false;
605
- if (confName === 'dd-github-pages') {
606
- const host = `${process.env.GITHUB_USERNAME ?? 'underpostnet'}.github.io`;
607
- const path = '/pwa-microservices-template-ghpkg';
608
- DefaultConf.server = {
609
- [host]: { [path]: defaultServer },
610
- };
611
- DefaultConf.server[host][path].apiBaseProxyPath = '/';
612
- DefaultConf.server[host][path].apiBaseHost = 'www.nexodev.org';
613
- defaultConf = true;
614
- } else if (confName === 'template') {
615
- const host = 'default.net';
616
- const path = '/';
617
- DefaultConf.server[host][path].valkey = {
618
- port: 6379,
619
- host: 'valkey-service.default.svc.cluster.local',
620
- };
621
- // mongodb-0.mongodb-service
622
- DefaultConf.server[host][path].db.host = 'mongodb://mongodb-service:27017';
623
- defaultConf = true;
624
- } else if (confName && fs.existsSync(`./engine-private/conf/${confName}`)) {
625
- DefaultConf.client = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.client.json`, 'utf8'));
626
- DefaultConf.server = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.server.json`, 'utf8'));
627
- DefaultConf.ssr = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.ssr.json`, 'utf8'));
628
- // DefaultConf.cron = JSON.parse(fs.readFileSync(`./engine-private/conf/${confName}/conf.cron.json`, 'utf8'));
629
-
630
- for (const host of Object.keys(DefaultConf.server)) {
631
- for (const path of Object.keys(DefaultConf.server[host])) {
632
- DefaultConf.server[host][path].db = defaultServer.db;
633
- DefaultConf.server[host][path].mailer = defaultServer.mailer;
634
-
635
- delete DefaultConf.server[host][path]._wp_client;
636
- delete DefaultConf.server[host][path]._wp_git;
637
- delete DefaultConf.server[host][path]._wp_directory;
638
- delete DefaultConf.server[host][path].wp;
639
- delete DefaultConf.server[host][path].git;
640
- delete DefaultConf.server[host][path].directory;
641
- }
642
- }
643
- }
644
- const sepRender = '/**/';
645
- const confRawPaths = fs.readFileSync('./conf.js', 'utf8').split(sepRender);
646
- confRawPaths[1] = `${JSON.stringify(DefaultConf)};`;
647
- const targetConfPath = `./conf${defaultConf ? '' : `.${confName}`}.js`;
648
- fs.writeFileSync(targetConfPath, confRawPaths.join(sepRender), 'utf8');
649
- shellExec(`prettier --write ${targetConfPath}`);
650
-
651
- switch (confName) {
652
- case 'dd-github-pages':
653
- {
654
- if (fs.exists(`./engine-private/conf/${confName}`)) fs.removeSync(`./engine-private/conf/${confName}`);
655
- shellExec(`node bin new --deploy-id ${confName}`);
656
- }
657
- break;
658
-
659
- default:
660
- break;
661
- }
662
-
663
- break;
664
- }
665
-
666
- case 'ssh': {
667
- // only import + start
668
- // node bin/deploy ssh root@<host> <password> import
669
-
670
- // generate + import + start
671
- // node bin/deploy ssh root@<host> <password>
672
-
673
- const host = process.argv[3] ?? `root@${await Dns.getPublicIp()}`;
674
- const domain = host.split('@')[1];
675
- const user = 'root'; // host.split('@')[0];
676
- const password = process.argv[4] ?? '';
677
- const port = 22;
678
-
679
- const setUpSSH = () => {
680
- // Required port forwarding mapping
681
- // ssh TCP 2222 22 <local-server-ip>
682
- // ssh UDP 2222 22 <local-server-ip>
683
-
684
- // Remote connect via public key
685
- // ssh -i <key-path> <user>@<host>:2222
686
-
687
- shellExec(`cat ./engine-private/deploy/id_rsa.pub > ~/.ssh/authorized_keys`);
688
-
689
- // local trust on first use validator
690
- // check ~/.ssh/known_hosts
691
-
692
- // shellExec(`sudo sed -i -e "s@#PasswordAuthentication yes@PasswordAuthentication no@g" /etc/ssh/sshd_config`);
693
- // shellExec(`sudo sed -i -e "s@#UsePAM no@UsePAM yes@g" /etc/ssh/sshd_config`);
694
-
695
- // Include /etc/ssh/sshd_config.d/*.conf
696
- // sudo tee /etc/ssh/sshd_config.d/99-custom.conf
697
- shellExec(`sudo tee /etc/ssh/sshd_config <<EOF
698
- PasswordAuthentication no
699
- ChallengeResponseAuthentication yes
700
- UsePAM yes
701
- PubkeyAuthentication Yes
702
- RSAAuthentication Yes
703
- PermitRootLogin Yes
704
- X11Forwarding yes
705
- X11DisplayOffset 10
706
- LoginGraceTime 120
707
- StrictModes yes
708
- SyslogFacility AUTH
709
- LogLevel INFO
710
- #HostKey /etc/ssh/ssh_host_ecdsa_key
711
- HostKey /etc/ssh/ssh_host_ed25519_key
712
- #HostKey /etc/ssh/ssh_host_rsa_key
713
- AuthorizedKeysFile ~/.ssh/authorized_keys
714
- Subsystem sftp /usr/libexec/openssh/sftp-server
715
- ListenAddress 0.0.0.0
716
- ListenAddress ::
717
- ListenAddress ${domain}
718
- ListenAddress ${domain}:22
719
- EOF`);
720
-
721
- shellExec(`sudo chmod 700 ~/.ssh/`);
722
- shellExec(`sudo chmod 600 ~/.ssh/authorized_keys`);
723
- shellExec(`sudo chmod 644 ~/.ssh/known_hosts`);
724
- shellExec(`sudo chmod 600 ~/.ssh/id_rsa`);
725
- shellExec(`sudo chmod 600 /etc/ssh/ssh_host_ed25519_key`);
726
- shellExec(`chown -R ${user}:${user} ~/.ssh`);
727
-
728
- shellExec(`ufw allow ${port}/tcp`);
729
- shellExec(`ufw allow ${port}/udp`);
730
- shellExec(`ufw allow ssh`);
731
- shellExec(`ufw allow from 192.168.0.0/16 to any port 22`);
732
-
733
- // active ssh-agent
734
- shellExec('eval `ssh-agent -s`' + ` && ssh-add ~/.ssh/id_rsa` + ` && ssh-add -l`);
735
- // remove all
736
- // shellExec(`ssh-add -D`);
737
- // remove single
738
- // shellExec(`ssh-add -d ~/.ssh/id_rsa`);
739
-
740
- // shellExec(`echo "@${host.split(`@`)[1]} * $(cat ~/.ssh/id_rsa.pub)" > ~/.ssh/known_hosts`);
741
- shellExec('eval `ssh-agent -s`' + `&& ssh-keyscan -H -t ed25519 ${host.split(`@`)[1]} > ~/.ssh/known_hosts`);
742
- // shellExec(`sudo echo "" > ~/.ssh/known_hosts`);
743
-
744
- // ssh-copy-id -i ~/.ssh/id_rsa.pub -p <port_number> <username>@<host>
745
- // shellExec(`ssh-copy-id -i ~/.ssh/id_rsa.pub -p ${port} ${host}`);
746
- // debug:
747
- // shellExec(`ssh -vvv ${host}`);
748
-
749
- shellExec(`sudo cp ./engine-private/deploy/id_rsa ~/.ssh/id_rsa`);
750
- shellExec(`sudo cp ./engine-private/deploy/id_rsa.pub ~/.ssh/id_rsa.pub`);
751
-
752
- shellExec(`sudo echo "" > /etc/ssh/ssh_host_ecdsa_key`);
753
- shellExec(`sudo cp ./engine-private/deploy/id_rsa /etc/ssh/ssh_host_ed25519_key`);
754
- shellExec(`sudo echo "" > /etc/ssh/ssh_host_rsa_key`);
755
-
756
- shellExec(`sudo echo "" > /etc/ssh/ssh_host_ecdsa_key.pub`);
757
- shellExec(`sudo cp ./engine-private/deploy/id_rsa.pub /etc/ssh/ssh_host_ed25519_key.pub`);
758
- shellExec(`sudo echo "" > /etc/ssh/ssh_host_rsa_key.pub`);
759
-
760
- shellExec(`sudo systemctl enable sshd`);
761
- shellExec(`sudo systemctl restart sshd`);
762
-
763
- const status = shellExec(`sudo systemctl status sshd`, { silent: true, stdout: true });
764
- console.log(
765
- status.match('running') ? status.replaceAll(`running`, `running`.green) : `ssh service not running`.red,
766
- );
767
- };
768
-
769
- if (process.argv.includes('import')) {
770
- setUpSSH();
771
- break;
772
- }
773
-
774
- shellExec(`sudo rm -rf ./id_rsa`);
775
- shellExec(`sudo rm -rf ./id_rsa.pub`);
776
-
777
- if (process.argv.includes('legacy'))
778
- shellExec(`ssh-keygen -t rsa -b 4096 -f id_rsa -N "${password}" -q -C "${host}"`);
779
- else shellExec(`ssh-keygen -t ed25519 -f id_rsa -N "${password}" -q -C "${host}"`);
780
-
781
- shellExec(`sudo cp ./id_rsa ~/.ssh/id_rsa`);
782
- shellExec(`sudo cp ./id_rsa.pub ~/.ssh/id_rsa.pub`);
783
-
784
- shellExec(`sudo cp ./id_rsa ./engine-private/deploy/id_rsa`);
785
- shellExec(`sudo cp ./id_rsa.pub ./engine-private/deploy/id_rsa.pub`);
786
-
787
- shellExec(`sudo rm -rf ./id_rsa`);
788
- shellExec(`sudo rm -rf ./id_rsa.pub`);
789
- setUpSSH();
790
- break;
791
- }
792
-
793
599
  case 'maas-db': {
794
600
  // DROP, ALTER, CREATE, WITH ENCRYPTED
795
601
  // sudo -u <user> -h <host> psql <db-name>
@@ -1052,7 +858,7 @@ EOF`);
1052
858
  shellExec(`sudo podman pull ghcr.io/astral-sh/uv:0.5.11`);
1053
859
  shellExec(`sudo rm -rf ${path}/${imageName.replace(':', '_')}.tar`);
1054
860
  const args = [
1055
- `node bin dockerfile-image-build --path ${path}/backend/`,
861
+ `node bin image --build --path ${path}/backend/`,
1056
862
  `--image-name=${imageName} --image-path=${path}`,
1057
863
  `--podman-save --${process.argv.includes('kubeadm') ? 'kubeadm' : 'kind'}-load --reset`,
1058
864
  ];
@@ -1064,7 +870,7 @@ EOF`);
1064
870
  shellExec(`sudo podman pull docker.io/library/nginx:1`);
1065
871
  shellExec(`sudo rm -rf ${path}/${imageName.replace(':', '_')}.tar`);
1066
872
  const args = [
1067
- `node bin dockerfile-image-build --path ${path}/frontend/`,
873
+ `node bin image --build --path ${path}/frontend/`,
1068
874
  `--image-name=${imageName} --image-path=${path}`,
1069
875
  `--podman-save --${process.argv.includes('kubeadm') ? 'kubeadm' : 'kind'}-load --reset`,
1070
876
  ];