diff --git a/.eslintrc.js b/.eslintrc.js index 46a0a458b5..e0ecc31cf3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,6 +27,7 @@ module.exports = { }, { files: [ + "build/*.ts", "src/**/*.ts", "spec/**/*.ts" ], diff --git a/build/download_helm.ts b/build/download_helm.ts new file mode 100644 index 0000000000..2f81b14583 --- /dev/null +++ b/build/download_helm.ts @@ -0,0 +1,3 @@ +import { helmCli } from "../src/main/helm-cli" + +helmCli.ensureBinary() diff --git a/package.json b/package.json index c68de1056e..f41703cc0c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "version": "3.2.0-rc.1", "main": "main.ts", "config": { - "bundledKubectlVersion": "1.17.3" + "bundledKubectlVersion": "1.17.3", + "bundledHelmVersion": "3.1.2" }, "engines": { "node": ">=12.0 <13.0" @@ -41,6 +42,10 @@ { "from": "binaries/client/linux/x64/kubectl", "to": "./x64/kubectl" + }, + { + "from": "binaries/client/helm3/helm3", + "to": "./helm3/helm3" } ] }, @@ -53,6 +58,10 @@ { "from": "binaries/client/darwin/x64/kubectl", "to": "./x64/kubectl" + }, + { + "from": "binaries/client/helm3/helm3", + "to": "./helm3/helm3" } ] }, @@ -68,6 +77,10 @@ { "from": "binaries/client/windows/ia32/kubectl.exe", "to": "./ia32/kubectl.exe" + }, + { + "from": "binaries/client/helm3/helm3.exe", + "to": "./helm3/helm3.exe" } ] }, @@ -94,7 +107,7 @@ "dev": "concurrently -n app,dash \"yarn dev-electron\" \"yarn dev-dashboard\"", "dev-dashboard": "cd dashboard && yarn dev", "dev-electron": "electron-webpack dev", - "compile": "yarn download:kubectl && electron-webpack", + "compile": "yarn download:bins && electron-webpack", "build:linux": "yarn compile && electron-builder --linux --dir", "build:mac": "yarn compile && electron-builder --mac --dir", "build:win": "yarn compile && electron-builder --win --dir", @@ -105,7 +118,9 @@ "lint-dashboard": "eslint $@ --ext js,ts,tsx --max-warnings=0 dashboard/client dashboard/server", "postinstall": "patch-package", "test": "node_modules/.bin/jest", - "download:kubectl": "yarn run ts-node build/download_kubectl.ts" + "download:bins": "concurrently \"yarn download:kubectl\" \"yarn download:helm\"", + "download:kubectl": "yarn run ts-node build/download_kubectl.ts", + "download:helm": "yarn run ts-node build/download_helm.ts" }, "dependencies": { "@hapi/call": "^6.0.1", diff --git a/src/main/helm-cli.ts b/src/main/helm-cli.ts index 6486b3c0f5..4a411fa1ae 100644 --- a/src/main/helm-cli.ts +++ b/src/main/helm-cli.ts @@ -1,40 +1,28 @@ import * as path from "path" import { LensBinary, LensBinaryOpts } from "./lens-binary" -import { userStore } from "../common/user-store" - -const helmVersion = "3.1.2" -const packageMirrors: Map = new Map([ - ["default", "https://get.helm.sh"], - ["china", "https://mirror.azure.cn/kubernetes/helm"] -]) export class HelmCli extends LensBinary { - public constructor(version: string) { + public constructor(baseDir: string, version: string) { const opts: LensBinaryOpts = { version, + baseDir: baseDir, originalBinaryName: "helm", newBinaryName: "helm3" } super(opts) } + protected getTarName(): string|null { return `${this.binaryName}-v${this.binaryVersion}-${this.platformName}-${this.arch}.tar.gz` } protected getUrl() { - return `${this.getDownloadMirror()}/helm-v${this.binaryVersion}-${this.platformName}-${this.arch}.tar.gz` - } - - protected getDownloadMirror() { - const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror) - if (mirror) { return mirror } - - return packageMirrors.get("default") + return `https://get.helm.sh/helm-v${this.binaryVersion}-${this.platformName}-${this.arch}.tar.gz` } protected getBinaryPath() { - return path.join(this.dirname, this.platformName+"-"+this.arch, this.binaryName) + return path.join(this.dirname, this.binaryName) } protected getOriginalBinaryPath() { @@ -42,4 +30,15 @@ export class HelmCli extends LensBinary { } } -export const helmCli = new HelmCli(helmVersion) +const helmVersion = require("../../package.json").config.bundledHelmVersion +const isDevelopment = process.env.NODE_ENV !== "production" +let baseDir: string = null + +if(isDevelopment) { + baseDir = path.join(process.cwd(), "binaries", "client") +} else { + baseDir = path.join(process.resourcesPath) +} + +export const helmCli = new HelmCli(baseDir, helmVersion) + diff --git a/src/main/index.ts b/src/main/index.ts index d668d1e8cf..ec30792bd1 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -100,9 +100,6 @@ async function main() { }) }, }, promiseIpc) - - // download helm cli - helmCli.ensureBinary() } app.on("ready", main) diff --git a/src/main/lens-binary.ts b/src/main/lens-binary.ts index d2599cad4c..2452ab2906 100644 --- a/src/main/lens-binary.ts +++ b/src/main/lens-binary.ts @@ -1,16 +1,16 @@ -import { app, remote } from "electron" import * as path from "path" import * as fs from "fs" import * as request from "request" import logger from "./logger" import { ensureDir, pathExists } from "fs-extra" import * as tar from "tar" -import { globalRequestOpts} from "../common/request" export type LensBinaryOpts = { version: string; + baseDir: string; originalBinaryName: string; newBinaryName?: string; + requestOpts?: request.Options; } export class LensBinary { @@ -24,12 +24,14 @@ export class LensBinary { protected platformName: string protected arch: string protected originalBinaryName: string + protected requestOpts: request.Options constructor(opts: LensBinaryOpts) { + const baseDir = opts.baseDir this.originalBinaryName = opts.originalBinaryName this.binaryName = opts.newBinaryName || opts.originalBinaryName - this.binaryVersion = opts.version + this.requestOpts = opts.requestOpts let arch = null @@ -41,20 +43,24 @@ export class LensBinary { arch = process.arch } this.arch = arch - const binaryDir = path.join((app || remote.app).getPath("userData"), "binaries", this.binaryName) this.platformName = process.platform === "win32" ? "windows" : process.platform if (process.platform === "win32") { this.binaryName = this.binaryName+".exe" this.originalBinaryName = this.originalBinaryName+".exe" } - this.dirname = path.normalize(path.join(binaryDir, this.binaryVersion)) + + this.dirname = path.normalize(path.join(baseDir, this.binaryName)) const tarName = this.getTarName() if (tarName) { this.tarPath = path.join(this.dirname, tarName) } } + protected binaryDir() { + throw new Error("binaryDir not implemented") + } + public async binaryPath() { await this.ensureBinary() return this.getBinaryPath() @@ -101,6 +107,7 @@ export class LensBinary { await this.downloadBinary().catch((error) => { logger.error(error) }); if (this.tarPath) await this.untarBinary() if(this.originalBinaryName != this.binaryName ) await this.renameBinary() + logger.info(`${this.originalBinaryName} has been downloaded to ${this.getBinaryPath()}`) } } @@ -139,13 +146,14 @@ export class LensBinary { logger.info(`Downloading ${this.originalBinaryName} ${this.binaryVersion} from ${url} to ${binaryPath}`) const requestOpts: request.UriOptions & request.CoreOptions = { uri: url, - gzip: true + gzip: true, + ...this.requestOpts } - const stream = request(globalRequestOpts(requestOpts)) + const stream = request(requestOpts) stream.on("complete", () => { - logger.info(`${this.originalBinaryName} binary download finished`) + logger.info(`Download of ${this.originalBinaryName} finished`) file.end(() => {}) }) diff --git a/src/renderer/components/PreferencesPage.vue b/src/renderer/components/PreferencesPage.vue index dfb4c2cb51..9ecd4b00f2 100644 --- a/src/renderer/components/PreferencesPage.vue +++ b/src/renderer/components/PreferencesPage.vue @@ -30,7 +30,7 @@

Download Mirror