mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Bundle helm3 binary (#220)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
2593f70184
commit
f23da9ccad
7 files changed
+56
-33
No files matched your search
+17
-18
@@ -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<string, string> = 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)
|
||||
|
||||
@@ -100,9 +100,6 @@ async function main() {
|
||||
})
|
||||
},
|
||||
}, promiseIpc)
|
||||
|
||||
// download helm cli
|
||||
helmCli.ensureBinary()
|
||||
}
|
||||
|
||||
app.on("ready", main)
|
||||
|
||||
+16
-8
@@ -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(() => {})
|
||||
})
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<h2>Download Mirror</h2>
|
||||
|
||||
<b-form-group
|
||||
label="Download mirror for kubectl/helm:"
|
||||
label="Download mirror for kubectl:"
|
||||
label-for="input-download-mirror"
|
||||
>
|
||||
<b-form-select
|
||||
|
||||
Reference in new issue
Block a user