mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Consolidate downloading binaries into one script (#4942)
* Consolidate downloading binaries into one script - Upgrade lens-k8s-proxy to 0.1.5 which allows us to remove the trailing slash in KubeAuthProxy - Consolidate nromalizing arch and os strings - Remove LensBinary as HelmCli is not just a raw object since it is always bundled - Introduce OnceCell and use it for the binary paths Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully remove helmCli, move associated variable to vars Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix helm downloading on windows Signed-off-by: Sebastian Malton <sebastian@malton.name> * Don't download binaries for unsupported windows Signed-off-by: Sebastian Malton <sebastian@malton.name> * Arch specific paths Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix downloading helm on windows Signed-off-by: Sebastian Malton <sebastian@malton.name> * rename once-cell file to lazy-initialized Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
dd5dfb393d
commit
a19f094a0d
23 files changed
+472
-641
No files matched your search
+2
-10
@@ -3,19 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import path from "path";
|
||||
import isDevelopmentInjectable from "../../vars/is-development.injectable";
|
||||
import contextDirInjectable from "../../vars/context-dir.injectable";
|
||||
import { baseBinariesDir } from "../../vars";
|
||||
|
||||
const directoryForBundledBinariesInjectable = getInjectable({
|
||||
id: "directory-for-bundled-binaries",
|
||||
instantiate: (di) => {
|
||||
if (di.inject(isDevelopmentInjectable)) {
|
||||
return path.join(di.inject(contextDirInjectable), "binaries");
|
||||
}
|
||||
|
||||
return process.resourcesPath;
|
||||
},
|
||||
instantiate: () => baseBinariesDir.get(),
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A OnceCell is an object that wraps some function that produces a value.
|
||||
*
|
||||
* It then only calls the function on the first call to `get()` and returns the
|
||||
* same instance/value on every subsequent call.
|
||||
*/
|
||||
export interface LazyInitialized<T> {
|
||||
get(): T;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to make a `OnceCell<T>`
|
||||
*/
|
||||
export function lazyInitialized<T>(builder: () => T): LazyInitialized<T> {
|
||||
let value: T | undefined;
|
||||
let called = false;
|
||||
|
||||
return {
|
||||
get() {
|
||||
if (called) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value = builder();
|
||||
called = true;
|
||||
|
||||
return value;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import path from "path";
|
||||
import { SemVer } from "semver";
|
||||
import packageInfo from "../../package.json";
|
||||
import { defineGlobal } from "./utils/defineGlobal";
|
||||
import { lazyInitialized } from "./utils/lazy-initialized";
|
||||
|
||||
export const isMac = process.platform === "darwin";
|
||||
export const isWindows = process.platform === "win32";
|
||||
@@ -29,6 +30,54 @@ export const defaultTheme = "lens-dark" as string;
|
||||
export const defaultFontSize = 12;
|
||||
export const defaultTerminalFontFamily = "RobotoMono";
|
||||
export const defaultEditorFontFamily = "RobotoMono";
|
||||
export const normalizedPlatform = (() => {
|
||||
switch (process.platform) {
|
||||
case "darwin":
|
||||
return "darwin";
|
||||
case "linux":
|
||||
return "linux";
|
||||
case "win32":
|
||||
return "windows";
|
||||
default:
|
||||
throw new Error(`platform=${process.platform} is unsupported`);
|
||||
}
|
||||
})();
|
||||
export const normalizedArch = (() => {
|
||||
switch (process.arch) {
|
||||
case "arm64":
|
||||
return "arm64";
|
||||
case "x64":
|
||||
case "amd64":
|
||||
return "x64";
|
||||
case "386":
|
||||
case "x32":
|
||||
case "ia32":
|
||||
return "ia32";
|
||||
default:
|
||||
throw new Error(`arch=${process.arch} is unsupported`);
|
||||
}
|
||||
})();
|
||||
|
||||
export function getBinaryName(name: string, { forPlatform = normalizedPlatform } = {}): string {
|
||||
if (forPlatform === "windows") {
|
||||
return `${name}.exe`;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
const resourcesDir = lazyInitialized(() => (
|
||||
isProduction
|
||||
? process.resourcesPath
|
||||
: path.join(process.cwd(), "binaries", "client", normalizedPlatform)
|
||||
));
|
||||
|
||||
export const baseBinariesDir = lazyInitialized(() => path.join(resourcesDir.get(), normalizedArch));
|
||||
export const kubeAuthProxyBinaryName = getBinaryName("lens-k8s-proxy");
|
||||
export const helmBinaryName = getBinaryName("helm");
|
||||
export const helmBinaryPath = lazyInitialized(() => path.join(baseBinariesDir.get(), helmBinaryName));
|
||||
export const kubectlBinaryName = getBinaryName("kubectl");
|
||||
export const kubectlBinaryPath = lazyInitialized(() => path.join(baseBinariesDir.get(), kubectlBinaryName));
|
||||
|
||||
// Webpack build paths
|
||||
export const contextDir = process.cwd();
|
||||
|
||||
Reference in new issue
Block a user