From 4371ebd5550147b328104bf22f655af1d25f1da0 Mon Sep 17 00:00:00 2001 From: Sarah Shader Date: Wed, 21 Aug 2024 16:02:23 -0400 Subject: [PATCH] Download correct OSS binary based on OS (#29074) GitOrigin-RevId: 747565cb17ddb179175faae1269ee6abf7466d63 --- .../convex/src/cli/lib/localDeployment/run.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/npm-packages/convex/src/cli/lib/localDeployment/run.ts b/npm-packages/convex/src/cli/lib/localDeployment/run.ts index aa25d63a..2c1c51ae 100644 --- a/npm-packages/convex/src/cli/lib/localDeployment/run.ts +++ b/npm-packages/convex/src/cli/lib/localDeployment/run.ts @@ -88,9 +88,16 @@ async function checkForExistingDownload( } async function downloadBinary(ctx: Context, version: string): Promise { - // TODO(ENG-7077) download the file depending on the platform + const downloadPath = getDownloadPath(); + if (downloadPath === null) { + return await ctx.crash({ + exitCode: 1, + errorType: "fatal", + printedMessage: `Unsupported platform ${process.platform} and architecture ${process.arch} for local deployment.`, + }); + } const response = await fetch( - `https://github.com/get-convex/convex-backend/releases/download/${version}/convex-local-backend-aarch64-apple-darwin.zip`, + `https://github.com/get-convex/convex-backend/releases/download/${version}/${downloadPath}`, ); logMessage(ctx, "Downloading convex backend"); if (!ctx.fs.exists(binariesDir())) { @@ -242,3 +249,25 @@ export async function ensureBackendStopped( export function localDeploymentUrl(cloudPort: number): string { return `http://127.0.0.1:${cloudPort}`; } + +function getDownloadPath() { + switch (process.platform) { + case "darwin": + if (process.arch === "arm64") { + return "convex-local-backend-aarch64-apple-darwin.zip"; + } else if (process.arch === "x64") { + return "convex-local-backend-x86_64-apple-darwin.zip"; + } + break; + case "linux": + if (process.arch === "arm64") { + return "convex-local-backend-aarch64-unknown-linux-gnu.zip"; + } else if (process.arch === "x64") { + return "convex-local-backend-x86_64-unknown-linux-gnu.zip"; + } + break; + case "win32": + return "convex-local-backend-x86_64-pc-windows-msvc.zip"; + } + return null; +}