underpost 2.8.79 → 2.8.84
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/.github/workflows/ghpkg.yml +22 -20
- package/.github/workflows/npmpkg.yml +15 -10
- package/.github/workflows/pwa-microservices-template.page.yml +12 -3
- package/.github/workflows/pwa-microservices-template.test.yml +20 -17
- package/.vscode/extensions.json +2 -3
- package/.vscode/settings.json +2 -42
- package/Dockerfile +14 -33
- package/README.md +43 -25
- package/bin/db.js +1 -0
- package/bin/deploy.js +104 -797
- package/bin/file.js +18 -1
- package/bin/vs.js +18 -3
- package/cli.md +367 -207
- package/conf.js +4 -0
- package/docker-compose.yml +1 -1
- package/manifests/deployment/dd-template-development/deployment.yaml +167 -0
- package/manifests/deployment/dd-template-development/proxy.yaml +46 -0
- package/manifests/deployment/tensorflow/tf-gpu-test.yaml +65 -0
- package/manifests/lxd/lxd-admin-profile.yaml +1 -0
- package/manifests/lxd/lxd-preseed.yaml +9 -37
- package/manifests/lxd/underpost-setup.sh +98 -81
- package/manifests/maas/device-scan.sh +43 -0
- package/manifests/maas/gpu-diag.sh +19 -0
- package/manifests/maas/lxd-preseed.yaml +32 -0
- package/manifests/maas/maas-setup.sh +120 -0
- package/manifests/maas/nat-iptables.sh +26 -0
- package/manifests/maas/snap-clean.sh +26 -0
- package/manifests/mariadb/statefulset.yaml +2 -1
- package/manifests/mariadb/storage-class.yaml +10 -0
- package/manifests/mongodb-4.4/service-deployment.yaml +2 -2
- package/manifests/valkey/service.yaml +3 -9
- package/manifests/valkey/statefulset.yaml +10 -12
- package/package.json +1 -1
- package/src/cli/baremetal.js +1280 -0
- package/src/cli/cloud-init.js +537 -0
- package/src/cli/cluster.js +506 -243
- package/src/cli/deploy.js +41 -3
- package/src/cli/env.js +2 -2
- package/src/cli/image.js +57 -9
- package/src/cli/index.js +271 -232
- package/src/cli/lxd.js +314 -81
- package/src/cli/repository.js +7 -4
- package/src/cli/run.js +262 -0
- package/src/cli/test.js +1 -1
- package/src/index.js +28 -1
- package/src/runtime/lampp/Dockerfile +41 -47
- package/src/server/conf.js +61 -0
- package/src/server/logger.js +3 -3
- package/src/server/process.js +16 -19
- package/src/server/runtime.js +1 -6
- package/src/server/ssl.js +1 -12
- package/src/server/valkey.js +3 -3
- package/supervisord-openssh-server.conf +0 -5
package/src/cli/lxd.js
CHANGED
|
@@ -3,8 +3,36 @@ import { getLocalIPv4Address } from '../server/dns.js';
|
|
|
3
3
|
import { pbcopy, shellExec } from '../server/process.js';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @class UnderpostLxd
|
|
8
|
+
* @description Provides a set of static methods to interact with LXD,
|
|
9
|
+
* encapsulating common LXD operations for VM management and network testing.
|
|
10
|
+
*/
|
|
6
11
|
class UnderpostLxd {
|
|
7
12
|
static API = {
|
|
13
|
+
/**
|
|
14
|
+
* @method callback
|
|
15
|
+
* @description Main entry point for LXD operations based on provided options.
|
|
16
|
+
* @param {object} options - Configuration options for LXD operations.
|
|
17
|
+
* @param {boolean} [options.init=false] - Initialize LXD.
|
|
18
|
+
* @param {boolean} [options.reset=false] - Reset LXD installation.
|
|
19
|
+
* @param {boolean} [options.dev=false] - Run in development mode (adjusts paths).
|
|
20
|
+
* @param {boolean} [options.install=false] - Install LXD snap.
|
|
21
|
+
* @param {boolean} [options.createVirtualNetwork=false] - Create default LXD bridge network (lxdbr0).
|
|
22
|
+
* @param {boolean} [options.createAdminProfile=false] - Create admin-profile for VMs.
|
|
23
|
+
* @param {boolean} [options.control=false] - Flag for control plane VM initialization.
|
|
24
|
+
* @param {boolean} [options.worker=false] - Flag for worker node VM initialization.
|
|
25
|
+
* @param {boolean} [options.k3s=false] - Flag to indicate K3s cluster type for VM initialization.
|
|
26
|
+
* @param {string} [options.initVm=''] - Initialize a specific VM.
|
|
27
|
+
* @param {string} [options.createVm=''] - Create a new VM with the given name.
|
|
28
|
+
* @param {string} [options.infoVm=''] - Display information about a specific VM.
|
|
29
|
+
* @param {string} [options.rootSize=''] - Root disk size for new VMs (e.g., '32GiB').
|
|
30
|
+
* @param {string} [options.joinNode=''] - Join a worker node to a control plane (format: 'workerName,controlName').
|
|
31
|
+
* @param {string} [options.expose=''] - Expose ports from a VM to the host (format: 'vmName:port1,port2').
|
|
32
|
+
* @param {string} [options.deleteExpose=''] - Delete exposed ports from a VM (format: 'vmName:port1,port2').
|
|
33
|
+
* @param {string} [options.test=''] - Test health, status and network connectivity for a VM.
|
|
34
|
+
* @param {string} [options.autoExposeK8sPorts=''] - Automatically expose common Kubernetes ports for the VM.
|
|
35
|
+
*/
|
|
8
36
|
async callback(
|
|
9
37
|
options = {
|
|
10
38
|
init: false,
|
|
@@ -12,22 +40,26 @@ class UnderpostLxd {
|
|
|
12
40
|
dev: false,
|
|
13
41
|
install: false,
|
|
14
42
|
createVirtualNetwork: false,
|
|
43
|
+
createAdminProfile: false,
|
|
15
44
|
control: false,
|
|
16
45
|
worker: false,
|
|
17
|
-
|
|
46
|
+
k3s: false,
|
|
18
47
|
initVm: '',
|
|
19
48
|
createVm: '',
|
|
20
49
|
infoVm: '',
|
|
21
50
|
rootSize: '',
|
|
22
51
|
joinNode: '',
|
|
23
52
|
expose: '',
|
|
53
|
+
deleteExpose: '',
|
|
54
|
+
test: '',
|
|
55
|
+
autoExposeK8sPorts: '',
|
|
24
56
|
},
|
|
25
57
|
) {
|
|
26
58
|
const npmRoot = getNpmRootPath();
|
|
27
59
|
const underpostRoot = options?.dev === true ? '.' : `${npmRoot}/underpost`;
|
|
28
60
|
if (options.reset === true) {
|
|
29
|
-
shellExec(`sudo systemctl stop snap.lxd.daemon`);
|
|
30
|
-
shellExec(`sudo snap remove lxd --purge`);
|
|
61
|
+
shellExec(`sudo systemctl stop snap.lxd.daemon || true`);
|
|
62
|
+
shellExec(`sudo snap remove lxd --purge || true`);
|
|
31
63
|
}
|
|
32
64
|
if (options.install === true) shellExec(`sudo snap install lxd`);
|
|
33
65
|
if (options.init === true) {
|
|
@@ -36,56 +68,157 @@ class UnderpostLxd {
|
|
|
36
68
|
const lxdPressedContent = fs
|
|
37
69
|
.readFileSync(`${underpostRoot}/manifests/lxd/lxd-preseed.yaml`, 'utf8')
|
|
38
70
|
.replaceAll(`127.0.0.1`, getLocalIPv4Address());
|
|
39
|
-
// shellExec(`lxc profile show admin-profile`);
|
|
40
|
-
// shellExec(`lxc network show lxdbr0`);
|
|
41
|
-
// shellExec(`lxd init --preseed < ${underpostRoot}/manifests/lxd/lxd-preseed.yaml`);
|
|
42
71
|
shellExec(`echo "${lxdPressedContent}" | lxd init --preseed`);
|
|
43
72
|
shellExec(`lxc cluster list`);
|
|
44
73
|
}
|
|
45
|
-
if (options.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}`;
|
|
52
|
-
pbcopy(createVmCommand); // Copy the command to clipboard for user
|
|
74
|
+
if (options.createVirtualNetwork === true) {
|
|
75
|
+
shellExec(`lxc network create lxdbr0 \
|
|
76
|
+
ipv4.address=10.250.250.1/24 \
|
|
77
|
+
ipv4.nat=true \
|
|
78
|
+
ipv4.dhcp=true \
|
|
79
|
+
ipv6.address=none`);
|
|
53
80
|
}
|
|
54
|
-
if (options.
|
|
55
|
-
|
|
56
|
-
shellExec(`
|
|
57
|
-
shellExec(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
runcmd:
|
|
67
|
-
- [touch, /var/log/userdata-ok]"`,
|
|
81
|
+
if (options.createAdminProfile === true) {
|
|
82
|
+
pbcopy(`lxc profile create admin-profile`);
|
|
83
|
+
shellExec(`cat ${underpostRoot}/manifests/lxd/lxd-admin-profile.yaml | lxc profile edit admin-profile`);
|
|
84
|
+
shellExec(`lxc profile show admin-profile`);
|
|
85
|
+
}
|
|
86
|
+
if (options.createVm && typeof options.createVm === 'string') {
|
|
87
|
+
pbcopy(
|
|
88
|
+
`lxc launch images:rockylinux/9 ${
|
|
89
|
+
options.createVm
|
|
90
|
+
} --vm --target lxd-node1 -c limits.cpu=2 -c limits.memory=4GB --profile admin-profile -d root,size=${
|
|
91
|
+
options.rootSize && typeof options.rootSize === 'string' ? options.rootSize + 'GiB' : '32GiB'
|
|
92
|
+
}`,
|
|
68
93
|
);
|
|
69
|
-
shellExec(`lxc start ${options.startVm}`);
|
|
70
94
|
}
|
|
71
95
|
if (options.initVm && typeof options.initVm === 'string') {
|
|
72
96
|
let flag = '';
|
|
73
97
|
if (options.control === true) {
|
|
74
|
-
|
|
98
|
+
if (options.k3s === true) {
|
|
99
|
+
flag = ' -s -- --k3s';
|
|
100
|
+
} else {
|
|
101
|
+
// Default to kubeadm if not K3s
|
|
102
|
+
flag = ' -s -- --kubeadm';
|
|
103
|
+
}
|
|
75
104
|
shellExec(`lxc exec ${options.initVm} -- bash -c 'mkdir -p /home/dd/engine'`);
|
|
76
105
|
shellExec(`lxc file push /home/dd/engine/engine-private ${options.initVm}/home/dd/engine --recursive`);
|
|
106
|
+
shellExec(`lxc file push /home/dd/engine/manifests ${options.initVm}/home/dd/engine --recursive`);
|
|
77
107
|
} else if (options.worker == true) {
|
|
78
|
-
|
|
108
|
+
if (options.k3s === true) {
|
|
109
|
+
flag = ' -s -- --worker --k3s';
|
|
110
|
+
} else {
|
|
111
|
+
// Default to kubeadm worker
|
|
112
|
+
flag = ' -s -- --worker';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
console.log(`Executing underpost-setup.sh on VM: ${options.initVm}`);
|
|
116
|
+
shellExec(`cat ${underpostRoot}/manifests/lxd/underpost-setup.sh | lxc exec ${options.initVm} -- bash${flag}`);
|
|
117
|
+
console.log(`underpost-setup.sh execution completed on VM: ${options.initVm}`);
|
|
118
|
+
}
|
|
119
|
+
// --- Automatic Kubernetes Port Exposure ---
|
|
120
|
+
if (options.autoExposeK8sPorts && typeof options.autoExposeK8sPorts === 'string') {
|
|
121
|
+
console.log(`Automatically exposing Kubernetes ports for VM: ${options.autoExposeK8sPorts}`);
|
|
122
|
+
const vmName = options.autoExposeK8sPorts;
|
|
123
|
+
const hostIp = getLocalIPv4Address();
|
|
124
|
+
let vmIp = '';
|
|
125
|
+
let retries = 0;
|
|
126
|
+
const maxRetries = 10;
|
|
127
|
+
const delayMs = 5000; // 5 seconds
|
|
128
|
+
|
|
129
|
+
// Wait for VM to get an IP address
|
|
130
|
+
while (!vmIp && retries < maxRetries) {
|
|
131
|
+
try {
|
|
132
|
+
console.log(`Attempting to get IPv4 address for ${vmName} (Attempt ${retries + 1}/${maxRetries})...`);
|
|
133
|
+
vmIp = shellExec(
|
|
134
|
+
`lxc list ${vmName} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
135
|
+
{ stdout: true },
|
|
136
|
+
).trim();
|
|
137
|
+
if (vmIp) {
|
|
138
|
+
console.log(`IPv4 address found for ${vmName}: ${vmIp}`);
|
|
139
|
+
} else {
|
|
140
|
+
console.log(`IPv4 address not yet available for ${vmName}. Retrying in ${delayMs / 1000} seconds...`);
|
|
141
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
142
|
+
}
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error(`Error getting IPv4 address for exposure: ${error.message}`);
|
|
145
|
+
console.log(`Retrying in ${delayMs / 1000} seconds...`);
|
|
146
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
147
|
+
}
|
|
148
|
+
retries++;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!vmIp) {
|
|
152
|
+
console.error(`Failed to get VM IP for ${vmName} after ${maxRetries} attempts. Cannot expose ports.`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let portsToExpose = [];
|
|
157
|
+
if (options.control === true) {
|
|
158
|
+
// Kubernetes API Server (Kubeadm and K3s both use 6443 by default)
|
|
159
|
+
portsToExpose.push('6443');
|
|
160
|
+
// Standard HTTP/HTTPS for Ingress if deployed
|
|
161
|
+
portsToExpose.push('80');
|
|
162
|
+
portsToExpose.push('443');
|
|
163
|
+
}
|
|
164
|
+
// Add common NodePorts if needed, or rely on explicit 'expose'
|
|
165
|
+
portsToExpose.push('30000'); // Example NodePort
|
|
166
|
+
portsToExpose.push('30001'); // Example NodePort
|
|
167
|
+
portsToExpose.push('30002'); // Example NodePort
|
|
168
|
+
|
|
169
|
+
const protocols = ['tcp']; // Most K8s services are TCP, UDP for some like DNS
|
|
170
|
+
|
|
171
|
+
for (const port of portsToExpose) {
|
|
172
|
+
for (const protocol of protocols) {
|
|
173
|
+
const deviceName = `${vmName}-${protocol}-port-${port}`;
|
|
174
|
+
try {
|
|
175
|
+
// Remove existing device first to avoid conflicts if re-running
|
|
176
|
+
shellExec(`lxc config device remove ${vmName} ${deviceName} || true`);
|
|
177
|
+
shellExec(
|
|
178
|
+
`lxc config device add ${vmName} ${deviceName} proxy listen=${protocol}:${hostIp}:${port} connect=${protocol}:${vmIp}:${port} nat=true`,
|
|
179
|
+
);
|
|
180
|
+
console.log(`Exposed ${protocol}:${hostIp}:${port} -> ${vmIp}:${port} for ${vmName}`);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error(`Failed to expose port ${port} for ${vmName}: ${error.message}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
79
185
|
}
|
|
80
|
-
pbcopy(`cat ${underpostRoot}/manifests/lxd/underpost-setup.sh | lxc exec ${options.initVm} -- bash${flag}`);
|
|
81
186
|
}
|
|
82
187
|
if (options.joinNode && typeof options.joinNode === 'string') {
|
|
83
188
|
const [workerNode, controlNode] = options.joinNode.split(',');
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
|
|
189
|
+
// Determine if it's a Kubeadm or K3s join
|
|
190
|
+
const isK3sJoin = options.k3s === true;
|
|
191
|
+
|
|
192
|
+
if (isK3sJoin) {
|
|
193
|
+
console.log(`Attempting to join K3s worker node ${workerNode} to control plane ${controlNode}`);
|
|
194
|
+
// Get K3s token from control plane
|
|
195
|
+
const k3sToken = shellExec(
|
|
196
|
+
`lxc exec ${controlNode} -- bash -c 'sudo cat /var/lib/rancher/k3s/server/node-token'`,
|
|
197
|
+
{ stdout: true },
|
|
198
|
+
).trim();
|
|
199
|
+
// Get control plane IP
|
|
200
|
+
const controlPlaneIp = shellExec(
|
|
201
|
+
`lxc list ${controlNode} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
202
|
+
{ stdout: true },
|
|
203
|
+
).trim();
|
|
204
|
+
|
|
205
|
+
if (!k3sToken || !controlPlaneIp) {
|
|
206
|
+
console.error(`Failed to get K3s token or control plane IP. Cannot join worker.`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const k3sJoinCommand = `K3S_URL=https://${controlPlaneIp}:6443 K3S_TOKEN=${k3sToken} curl -sfL https://get.k3s.io | sh -`;
|
|
210
|
+
shellExec(`lxc exec ${workerNode} -- bash -c '${k3sJoinCommand}'`);
|
|
211
|
+
console.log(`K3s worker node ${workerNode} join command executed.`);
|
|
212
|
+
} else {
|
|
213
|
+
// Kubeadm join
|
|
214
|
+
console.log(`Attempting to join Kubeadm worker node ${workerNode} to control plane ${controlNode}`);
|
|
215
|
+
const token = shellExec(
|
|
216
|
+
`echo "$(lxc exec ${controlNode} -- bash -c 'sudo kubeadm token create --print-join-command')"`,
|
|
217
|
+
{ stdout: true },
|
|
218
|
+
);
|
|
219
|
+
shellExec(`lxc exec ${workerNode} -- bash -c '${token}'`);
|
|
220
|
+
console.log(`Kubeadm worker node ${workerNode} join command executed.`);
|
|
221
|
+
}
|
|
89
222
|
}
|
|
90
223
|
if (options.infoVm && typeof options.infoVm === 'string') {
|
|
91
224
|
shellExec(`lxc config show ${options.infoVm}`);
|
|
@@ -94,67 +227,167 @@ runcmd:
|
|
|
94
227
|
shellExec(`lxc list ${options.infoVm}`);
|
|
95
228
|
}
|
|
96
229
|
if (options.expose && typeof options.expose === 'string') {
|
|
97
|
-
const [
|
|
98
|
-
console.log({
|
|
99
|
-
const protocols = ['tcp'
|
|
230
|
+
const [vmName, ports] = options.expose.split(':');
|
|
231
|
+
console.log({ vmName, ports });
|
|
232
|
+
const protocols = ['tcp']; // udp
|
|
100
233
|
const hostIp = getLocalIPv4Address();
|
|
101
234
|
const vmIp = shellExec(
|
|
102
|
-
`lxc list ${
|
|
235
|
+
`lxc list ${vmName} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
103
236
|
{ stdout: true },
|
|
104
237
|
).trim();
|
|
238
|
+
if (!vmIp) {
|
|
239
|
+
console.error(`Could not get VM IP for ${vmName}. Cannot expose ports.`);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
105
242
|
for (const port of ports.split(',')) {
|
|
106
243
|
for (const protocol of protocols) {
|
|
107
|
-
|
|
244
|
+
const deviceName = `${vmName}-${protocol}-port-${port}`;
|
|
245
|
+
shellExec(`lxc config device remove ${vmName} ${deviceName} || true`); // Use || true to prevent error if device doesn't exist
|
|
108
246
|
shellExec(
|
|
109
|
-
`lxc config device add ${
|
|
247
|
+
`lxc config device add ${vmName} ${deviceName} proxy listen=${protocol}:${hostIp}:${port} connect=${protocol}:${vmIp}:${port} nat=true`,
|
|
110
248
|
);
|
|
111
|
-
|
|
249
|
+
console.log(`Manually exposed ${protocol}:${hostIp}:${port} -> ${vmIp}:${port} for ${vmName}`);
|
|
112
250
|
}
|
|
113
251
|
}
|
|
114
252
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
- ${ip}/24
|
|
123
|
-
gateway4: 10.250.250.1
|
|
124
|
-
nameservers:
|
|
125
|
-
addresses: [1.1.1.1, 8.8.8.8]`;
|
|
126
|
-
},
|
|
127
|
-
getUsedIpsFromLxd() {
|
|
128
|
-
const json = shellExec('lxc list --format json', { stdout: true, silent: true });
|
|
129
|
-
const vms = JSON.parse(json);
|
|
130
|
-
|
|
131
|
-
const usedIps = [];
|
|
132
|
-
|
|
133
|
-
for (const vm of vms) {
|
|
134
|
-
if (vm.state && vm.state.network) {
|
|
135
|
-
for (const iface of Object.values(vm.state.network)) {
|
|
136
|
-
if (iface.addresses) {
|
|
137
|
-
for (const addr of iface.addresses) {
|
|
138
|
-
if (addr.family === 'inet' && addr.address.startsWith('10.250.250.')) {
|
|
139
|
-
usedIps.push(addr.address);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
253
|
+
if (options.deleteExpose && typeof options.deleteExpose === 'string') {
|
|
254
|
+
const [controlNode, ports] = options.deleteExpose.split(':');
|
|
255
|
+
console.log({ controlNode, ports });
|
|
256
|
+
const protocols = ['tcp']; // udp
|
|
257
|
+
for (const port of ports.split(',')) {
|
|
258
|
+
for (const protocol of protocols) {
|
|
259
|
+
shellExec(`lxc config device remove ${controlNode} ${controlNode}-${protocol}-port-${port}`);
|
|
143
260
|
}
|
|
144
261
|
}
|
|
145
262
|
}
|
|
146
263
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
264
|
+
if (options.test && typeof options.test === 'string') {
|
|
265
|
+
const vmName = options.test;
|
|
266
|
+
console.log(`Starting comprehensive test for VM: ${vmName}`);
|
|
267
|
+
|
|
268
|
+
// 1. Monitor for IPv4 address
|
|
269
|
+
let vmIp = '';
|
|
270
|
+
let retries = 0;
|
|
271
|
+
const maxRetries = 10;
|
|
272
|
+
const delayMs = 5000; // 5 seconds
|
|
273
|
+
|
|
274
|
+
while (!vmIp && retries < maxRetries) {
|
|
275
|
+
try {
|
|
276
|
+
console.log(`Attempting to get IPv4 address for ${vmName} (Attempt ${retries + 1}/${maxRetries})...`);
|
|
277
|
+
vmIp = shellExec(
|
|
278
|
+
`lxc list ${vmName} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
279
|
+
{ stdout: true },
|
|
280
|
+
).trim();
|
|
281
|
+
if (vmIp) {
|
|
282
|
+
console.log(`IPv4 address found for ${vmName}: ${vmIp}`);
|
|
283
|
+
} else {
|
|
284
|
+
console.log(`IPv4 address not yet available for ${vmName}. Retrying in ${delayMs / 1000} seconds...`);
|
|
285
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
286
|
+
}
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.error(`Error getting IPv4 address: ${error.message}`);
|
|
289
|
+
console.log(`Retrying in ${delayMs / 1000} seconds...`);
|
|
290
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
291
|
+
}
|
|
292
|
+
retries++;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (!vmIp) {
|
|
296
|
+
console.error(`Failed to get IPv4 address for ${vmName} after ${maxRetries} attempts. Aborting tests.`);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 2. Iteratively check connection to google.com
|
|
301
|
+
let connectedToGoogle = false;
|
|
302
|
+
retries = 0;
|
|
303
|
+
while (!connectedToGoogle && retries < maxRetries) {
|
|
304
|
+
try {
|
|
305
|
+
console.log(`Checking connectivity to google.com from ${vmName} (Attempt ${retries + 1}/${maxRetries})...`);
|
|
306
|
+
const curlOutput = shellExec(
|
|
307
|
+
`lxc exec ${vmName} -- bash -c 'curl -s -o /dev/null -w "%{http_code}" http://google.com'`,
|
|
308
|
+
{ stdout: true },
|
|
309
|
+
);
|
|
310
|
+
if (curlOutput.startsWith('2') || curlOutput.startsWith('3')) {
|
|
311
|
+
console.log(`Successfully connected to google.com from ${vmName}.`);
|
|
312
|
+
connectedToGoogle = true;
|
|
313
|
+
} else {
|
|
314
|
+
console.log(`Connectivity to google.com not yet verified. Retrying in ${delayMs / 1000} seconds...`);
|
|
315
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
316
|
+
}
|
|
317
|
+
} catch (error) {
|
|
318
|
+
console.error(`Error checking connectivity to google.com: ${error.message}`);
|
|
319
|
+
console.log(`Retrying in ${delayMs / 1000} seconds...`);
|
|
320
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
321
|
+
}
|
|
322
|
+
retries++;
|
|
155
323
|
}
|
|
324
|
+
|
|
325
|
+
if (!connectedToGoogle) {
|
|
326
|
+
console.error(
|
|
327
|
+
`Failed to connect to google.com from ${vmName} after ${maxRetries} attempts. Aborting further tests.`,
|
|
328
|
+
);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// 3. Check other connectivity, network, and VM health parameters
|
|
333
|
+
console.log(`\n--- Comprehensive Health Report for ${vmName} ---`);
|
|
334
|
+
|
|
335
|
+
// VM Status
|
|
336
|
+
console.log('\n--- VM Status ---');
|
|
337
|
+
try {
|
|
338
|
+
const vmStatus = shellExec(`lxc list ${vmName} --format json`, { stdout: true, silent: true });
|
|
339
|
+
console.log(JSON.stringify(JSON.parse(vmStatus), null, 2));
|
|
340
|
+
} catch (error) {
|
|
341
|
+
console.error(`Error getting VM status: ${error.message}`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// CPU Usage
|
|
345
|
+
console.log('\n--- CPU Usage ---');
|
|
346
|
+
try {
|
|
347
|
+
const cpuUsage = shellExec(`lxc exec ${vmName} -- bash -c 'top -bn1 | grep "Cpu(s)"'`, { stdout: true });
|
|
348
|
+
console.log(cpuUsage.trim());
|
|
349
|
+
} catch (error) {
|
|
350
|
+
console.error(`Error getting CPU usage: ${error.message}`);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Memory Usage
|
|
354
|
+
console.log('\n--- Memory Usage ---');
|
|
355
|
+
try {
|
|
356
|
+
const memoryUsage = shellExec(`lxc exec ${vmName} -- bash -c 'free -m'`, { stdout: true });
|
|
357
|
+
console.log(memoryUsage.trim());
|
|
358
|
+
} catch (error) {
|
|
359
|
+
console.error(`Error getting memory usage: ${error.message}`);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Disk Usage
|
|
363
|
+
console.log('\n--- Disk Usage (Root Partition) ---');
|
|
364
|
+
try {
|
|
365
|
+
const diskUsage = shellExec(`lxc exec ${vmName} -- bash -c 'df -h /'`, { stdout: true });
|
|
366
|
+
console.log(diskUsage.trim());
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.error(`Error getting disk usage: ${error.message}`);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Network Interface Status
|
|
372
|
+
console.log('\n--- Network Interface Status (ip a) ---');
|
|
373
|
+
try {
|
|
374
|
+
const ipA = shellExec(`lxc exec ${vmName} -- bash -c 'ip a'`, { stdout: true });
|
|
375
|
+
console.log(ipA.trim());
|
|
376
|
+
} catch (error) {
|
|
377
|
+
console.error(`Error getting network interface status: ${error.message}`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// DNS Resolution (resolv.conf)
|
|
381
|
+
console.log('\n--- DNS Configuration (/etc/resolv.conf) ---');
|
|
382
|
+
try {
|
|
383
|
+
const resolvConf = shellExec(`lxc exec ${vmName} -- bash -c 'cat /etc/resolv.conf'`, { stdout: true });
|
|
384
|
+
console.log(resolvConf.trim());
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error(`Error getting DNS configuration: ${error.message}`);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
console.log(`\nComprehensive test for VM: ${vmName} completed.`);
|
|
156
390
|
}
|
|
157
|
-
throw new Error('No IPs available in the static range');
|
|
158
391
|
},
|
|
159
392
|
};
|
|
160
393
|
}
|
package/src/cli/repository.js
CHANGED
|
@@ -60,7 +60,7 @@ class UnderpostRepository {
|
|
|
60
60
|
},
|
|
61
61
|
|
|
62
62
|
push(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template', options = { f: false, g8: false }) {
|
|
63
|
-
const gExtension = options.g8 === true ? '.g8' : '.git';
|
|
63
|
+
const gExtension = options.g8 === true || options.G8 === true ? '.g8' : '.git';
|
|
64
64
|
shellExec(
|
|
65
65
|
`cd ${repoPath} && git push https://${process.env.GITHUB_TOKEN}@github.com/${gitUri}${gExtension}${
|
|
66
66
|
options?.f === true ? ' --force' : ''
|
|
@@ -71,9 +71,12 @@ class UnderpostRepository {
|
|
|
71
71
|
);
|
|
72
72
|
logger.info(
|
|
73
73
|
'commit url',
|
|
74
|
-
`http://github.com/${gitUri}
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
`http://github.com/${gitUri}${gExtension === '.g8' ? '.g8' : ''}/commit/${shellExec(
|
|
75
|
+
`cd ${repoPath} && git rev-parse --verify HEAD`,
|
|
76
|
+
{
|
|
77
|
+
stdout: true,
|
|
78
|
+
},
|
|
79
|
+
).trim()}`,
|
|
77
80
|
);
|
|
78
81
|
},
|
|
79
82
|
|