onedeploy-cli 0.1.4 → 0.1.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.
- package/dist/index.js +7 -3
- package/dist/nebula.js +21 -2
- package/package.json +1 -1
- package/src/index.ts +12 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import prompts from "prompts";
|
|
3
3
|
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
-
import { cleanupNebula, connectNebula, installNebula } from "./nebula.js";
|
|
4
|
+
import { cleanupNebula, connectNebula, installNebula, isNebulaRunning, } from "./nebula.js";
|
|
5
5
|
if (process.argv.includes("--version")) {
|
|
6
6
|
console.log("onedeploy-cli version 0.1.4");
|
|
7
7
|
process.exit();
|
|
@@ -104,8 +104,12 @@ const mainMenu = async () => {
|
|
|
104
104
|
}
|
|
105
105
|
return true;
|
|
106
106
|
};
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
process.on("SIGINT", () => {
|
|
108
|
+
if (!isNebulaRunning) {
|
|
109
|
+
process.exit();
|
|
110
|
+
}
|
|
111
|
+
// ignore SIGINTs to continue after Nebula is disconnected
|
|
112
|
+
});
|
|
109
113
|
await installNebula();
|
|
110
114
|
try {
|
|
111
115
|
while (true) {
|
package/dist/nebula.js
CHANGED
|
@@ -9,10 +9,15 @@ import { parse } from "yaml";
|
|
|
9
9
|
const getNebulaPackageName = () => {
|
|
10
10
|
switch (process.platform) {
|
|
11
11
|
case "linux":
|
|
12
|
-
if (process.arch
|
|
12
|
+
if (process.arch === "x64") {
|
|
13
|
+
return `nebula-linux-amd64.tar.gz`;
|
|
14
|
+
}
|
|
15
|
+
else if (process.arch === "arm64") {
|
|
16
|
+
return `nebula-linux-arm64.tar.gz`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
13
19
|
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
14
20
|
}
|
|
15
|
-
return `nebula-linux-amd64.tar.gz`;
|
|
16
21
|
case "darwin":
|
|
17
22
|
return `nebula-darwin.zip`;
|
|
18
23
|
case "win32":
|
|
@@ -67,10 +72,23 @@ export const getNebulaCert = async (instance) => {
|
|
|
67
72
|
"-path",
|
|
68
73
|
`${tmpDir}/nebula-debug.crt`,
|
|
69
74
|
]);
|
|
75
|
+
// in case our local time isn't correct, wait for the certificate to become valid
|
|
76
|
+
const validFrom = stdout.match(/Not before: ([\d-]+ [\d:]+ \+\d+)/);
|
|
77
|
+
if (validFrom === null) {
|
|
78
|
+
throw new Error("Invalid Nebula certificate: Missing 'Not before' field.");
|
|
79
|
+
}
|
|
80
|
+
const validFromDate = new Date(validFrom[1]);
|
|
81
|
+
if (validFromDate > new Date()) {
|
|
82
|
+
const waitTime = validFromDate.getTime() - Date.now();
|
|
83
|
+
console.log(`Your system clock is running slow! Waiting ${Math.ceil(waitTime / 1000)} seconds for Nebula certificate to become valid...`);
|
|
84
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
85
|
+
}
|
|
70
86
|
process.stdout.write(stdout);
|
|
71
87
|
};
|
|
88
|
+
export let isNebulaRunning = false;
|
|
72
89
|
export const connectNebula = async (instance) => {
|
|
73
90
|
await getNebulaCert(instance);
|
|
91
|
+
isNebulaRunning = true;
|
|
74
92
|
const nebula = spawn(`${tmpDir}/nebula`, ["-config", `${tmpDir}/nebula.yml`], { stdio: "inherit" });
|
|
75
93
|
const interval = setInterval(async () => {
|
|
76
94
|
// refresh Nebula cert every 10 minutes (lifetime is 15 minutes)
|
|
@@ -78,5 +96,6 @@ export const connectNebula = async (instance) => {
|
|
|
78
96
|
nebula.kill("SIGHUP");
|
|
79
97
|
}, 10 * 60 * 1000);
|
|
80
98
|
await new Promise((resolve) => nebula.on("exit", resolve));
|
|
99
|
+
isNebulaRunning = false;
|
|
81
100
|
clearInterval(interval);
|
|
82
101
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import prompts from "prompts";
|
|
3
3
|
import { loadConfig, saveConfig } from "./config.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cleanupNebula,
|
|
6
|
+
connectNebula,
|
|
7
|
+
installNebula,
|
|
8
|
+
isNebulaRunning,
|
|
9
|
+
} from "./nebula.js";
|
|
5
10
|
|
|
6
11
|
if (process.argv.includes("--version")) {
|
|
7
12
|
console.log("onedeploy-cli version 0.1.4");
|
|
@@ -107,8 +112,12 @@ const mainMenu = async (): Promise<boolean> => {
|
|
|
107
112
|
return true;
|
|
108
113
|
};
|
|
109
114
|
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
process.on("SIGINT", () => {
|
|
116
|
+
if (!isNebulaRunning) {
|
|
117
|
+
process.exit();
|
|
118
|
+
}
|
|
119
|
+
// ignore SIGINTs to continue after Nebula is disconnected
|
|
120
|
+
});
|
|
112
121
|
await installNebula();
|
|
113
122
|
try {
|
|
114
123
|
while (true) {
|