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:
parent
2593f70184
commit
f23da9ccad
@ -27,6 +27,7 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
files: [
|
||||
"build/*.ts",
|
||||
"src/**/*.ts",
|
||||
"spec/**/*.ts"
|
||||
],
|
||||
|
||||
3
build/download_helm.ts
Normal file
3
build/download_helm.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { helmCli } from "../src/main/helm-cli"
|
||||
|
||||
helmCli.ensureBinary()
|
||||
21
package.json
21
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",
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user