feat: 💚 ship with binary

This commit is contained in:
Nate Sesti 2023-10-05 13:26:54 -07:00
parent c2587073d3
commit 2751ddeb2d
2 changed files with 114 additions and 75 deletions

View file

@ -72,6 +72,15 @@ jobs:
run: |
chmod 777 dist/run
# 1.5 Place the binary in extension/exe directory
- name: Make sure extension/exe directory exists
run: |
mkdir -p extension/exe
- name: Copy binary to extension
run: |
cp dist/run extension/exe/run
# 2. Install npm dependencies
- name: Use Node.js 19.0.0
uses: actions/setup-node@v3

View file

@ -198,22 +198,79 @@ export async function downloadFromS3(
});
}
export async function startContinuePythonServer(redownload: boolean = true) {
// Check vscode settings
const manuallyRunningServer =
vscode.workspace
.getConfiguration("continue")
.get<boolean>("manuallyRunningServer") || false;
const serverUrl = getContinueServerUrl();
if (
(serverUrl !== "http://localhost:65432" &&
serverUrl !== "http://127.0.0.1:65432") ||
manuallyRunningServer
) {
console.log("Continue server is being run manually, skipping start");
return;
}
function includedBinaryPath(): string {
const extensionPath = getExtensionUri().fsPath;
return path.join(
extensionPath,
"exe",
`run${os.platform() === "win32" ? ".exe" : ""}`
);
}
function runExecutable(path: string) {
console.log("---- Starting Continue server ----");
let attempts = 0;
let maxAttempts = 5;
let delay = 1000; // Delay between each attempt in milliseconds
const spawnChild = () => {
const retry = (e: any) => {
attempts++;
console.log(`Error caught: ${e}.\n\nRetrying attempt ${attempts}...`);
setTimeout(spawnChild, delay);
};
try {
// NodeJS bug requires not using detached on Windows, otherwise windowsHide is ineffective
// Otherwise, detach is preferable
const windowsSettings = {
windowsHide: true,
};
const macLinuxSettings = {
detached: true,
stdio: "ignore",
};
const settings: any =
os.platform() === "win32" ? windowsSettings : macLinuxSettings;
// Spawn the server
const child = spawn(path, settings);
// Either unref to avoid zombie process, or listen to events because you can
if (os.platform() === "win32") {
child.stdout.on("data", (data: any) => {
console.log(`stdout: ${data}`);
});
child.stderr.on("data", (data: any) => {
console.log(`stderr: ${data}`);
});
child.on("error", (err: any) => {
if (attempts < maxAttempts) {
retry(err);
} else {
console.error("Failed to start subprocess.", err);
}
});
child.on("exit", (code: any, signal: any) => {
console.log("Subprocess exited with code", code, signal);
});
child.on("close", (code: any, signal: any) => {
console.log("Subprocess closed with code", code, signal);
});
} else {
child.unref();
}
} catch (e: any) {
if (attempts < maxAttempts) {
retry(e);
} else {
throw e;
}
}
};
spawnChild();
}
async function setupWithS3Download(redownload: boolean, serverUrl: string) {
// Check if server is already running
if (redownload && (await checkOrKillRunningServer(serverUrl))) {
console.log("Continue server already running");
@ -353,67 +410,40 @@ export async function startContinuePythonServer(redownload: boolean = true) {
}
// Run the executable
console.log("---- Starting Continue server ----");
let attempts = 0;
let maxAttempts = 5;
let delay = 1000; // Delay between each attempt in milliseconds
const spawnChild = () => {
const retry = (e: any) => {
attempts++;
console.log(`Error caught: ${e}.\n\nRetrying attempt ${attempts}...`);
setTimeout(spawnChild, delay);
};
try {
// NodeJS bug requires not using detached on Windows, otherwise windowsHide is ineffective
// Otherwise, detach is preferable
const windowsSettings = {
windowsHide: true,
};
const macLinuxSettings = {
detached: true,
stdio: "ignore",
};
const settings: any =
os.platform() === "win32" ? windowsSettings : macLinuxSettings;
// Spawn the server
const child = spawn(destination, settings);
// Either unref to avoid zombie process, or listen to events because you can
if (os.platform() === "win32") {
child.stdout.on("data", (data: any) => {
console.log(`stdout: ${data}`);
});
child.stderr.on("data", (data: any) => {
console.log(`stderr: ${data}`);
});
child.on("error", (err: any) => {
if (attempts < maxAttempts) {
retry(err);
} else {
console.error("Failed to start subprocess.", err);
}
});
child.on("exit", (code: any, signal: any) => {
console.log("Subprocess exited with code", code, signal);
});
child.on("close", (code: any, signal: any) => {
console.log("Subprocess closed with code", code, signal);
});
} else {
child.unref();
}
} catch (e: any) {
if (attempts < maxAttempts) {
retry(e);
} else {
throw e;
}
}
};
spawnChild();
runExecutable(destination);
// Write the current version of vscode extension to a file called server_version.txt
fs.writeFileSync(serverVersionPath(), getExtensionVersion());
}
export async function startContinuePythonServer(redownload: boolean = true) {
// Check vscode settings for whether server is being run manually
const manuallyRunningServer =
vscode.workspace
.getConfiguration("continue")
.get<boolean>("manuallyRunningServer") || false;
const serverUrl = getContinueServerUrl();
if (
(serverUrl !== "http://localhost:65432" &&
serverUrl !== "http://127.0.0.1:65432") ||
manuallyRunningServer
) {
console.log("Continue server is being run manually, skipping start");
return;
}
// Check if on Apple Silicon, or if the exe folder is empty - have to download binary from S3
const isAppleSilicon = os.platform() === "darwin" && os.arch() === "arm64";
// if (isAppleSilicon) {
// await setupWithS3Download(redownload, serverUrl);
// }
if (!fs.existsSync(includedBinaryPath())) {
throw new Error(
`Continue server binary not found at ${includedBinaryPath()}`
);
}
// Otherwise, use the binary installed with the extension
runExecutable(includedBinaryPath());
}