diff --git a/src/cli/install-tool/index.ts b/src/cli/install-tool/index.ts index e25a1c8c7..c521831a8 100644 --- a/src/cli/install-tool/index.ts +++ b/src/cli/install-tool/index.ts @@ -8,6 +8,7 @@ import { InstallDotnetService } from '../tools/dotnet'; import { InstallFlutterService } from '../tools/flutter'; import { InstallFluxService } from '../tools/flux'; import { InstallGleamService } from '../tools/gleam'; +import { HelmInstallService } from '../tools/helm'; import { InstallJavaJdkService, InstallJavaJreService, @@ -75,6 +76,7 @@ function prepareInstallContainer(): Container { container.bind(INSTALL_TOOL_TOKEN).to(InstallFluxService); container.bind(INSTALL_TOOL_TOKEN).to(InstallGleamService); container.bind(INSTALL_TOOL_TOKEN).to(InstallGradleService); + container.bind(INSTALL_TOOL_TOKEN).to(HelmInstallService); container.bind(INSTALL_TOOL_TOKEN).to(InstallJavaService); container.bind(INSTALL_TOOL_TOKEN).to(InstallJavaJreService); container.bind(INSTALL_TOOL_TOKEN).to(InstallJavaJdkService); diff --git a/src/cli/tools/helm.ts b/src/cli/tools/helm.ts new file mode 100644 index 000000000..62189b729 --- /dev/null +++ b/src/cli/tools/helm.ts @@ -0,0 +1,75 @@ +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { execa } from 'execa'; +import { inject, injectable } from 'inversify'; +import { InstallToolBaseService } from '../install-tool/install-tool-base.service'; +import { + CompressionService, + EnvService, + HttpService, + PathService, +} from '../services'; + +@injectable() +export class HelmInstallService extends InstallToolBaseService { + readonly name = 'helm'; + + constructor( + @inject(EnvService) envSvc: EnvService, + @inject(PathService) pathSvc: PathService, + @inject(HttpService) private http: HttpService, + @inject(CompressionService) private compress: CompressionService, + ) { + super(pathSvc, envSvc); + } + + override async install(version: string): Promise { + const name = this.name; + const filename = `${name}-v${version}-linux-${this.envSvc.arch}.tar.gz`; + const url = `https://get.helm.sh/${filename}`; + + const expectedChecksum = await this._getChecksum( + `${url}.sha256sum`, + filename, + ); + const file = await this.http.download({ + url, + checksumType: 'sha256', + expectedChecksum, + }); + await this.pathSvc.ensureToolPath(this.name); + const cwd = path.join( + await this.pathSvc.createVersionedToolPath(this.name, version), + 'bin', + ); + await fs.mkdir(cwd); + await this.compress.extract({ file, cwd, strip: 1 }); + } + + override async link(version: string): Promise { + const src = path.join( + this.pathSvc.versionedToolPath(this.name, version), + 'bin', + ); + await this.shellwrapper({ srcDir: src }); + } + + override async test(_version: string): Promise { + await execa(this.name, ['version'], { + stdio: ['inherit', 'inherit', 1], + }); + } + + /** TODO: create helper */ + protected async _getChecksum( + url: string, + filename: string, + ): Promise { + const checksumFile = await this.http.download({ url }); + const expectedChecksum = (await fs.readFile(checksumFile, 'utf-8')) + .split('\n') + .find((l) => l.includes(filename)) + ?.split(' ')[0]; + return expectedChecksum; + } +} diff --git a/src/cli/tools/index.ts b/src/cli/tools/index.ts index bd6f137bd..03fd7a13c 100644 --- a/src/cli/tools/index.ts +++ b/src/cli/tools/index.ts @@ -14,6 +14,7 @@ export const NoPrepareTools = [ 'gleam', 'gradle', 'hashin', + 'helm', 'kubectl', 'lerna', 'maven', diff --git a/src/usr/local/containerbase/tools/v2/helm.sh b/src/usr/local/containerbase/tools/v2/helm.sh deleted file mode 100644 index 61473bcc7..000000000 --- a/src/usr/local/containerbase/tools/v2/helm.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -function install_tool () { - local versioned_tool_path - local arch=linux-amd64 - local file - - if [[ "$(uname -p)" = "aarch64" ]]; then - arch=linux-arm64 - fi - - file=$(get_from_url "https://get.helm.sh/helm-v${TOOL_VERSION}-${arch}.tar.gz") - - versioned_tool_path=$(create_versioned_tool_path) - create_folder "${versioned_tool_path}/bin" - tar --strip 1 -C "${versioned_tool_path}/bin" -xf "${file}" -} - -function link_tool () { - local versioned_tool_path - versioned_tool_path=$(find_versioned_tool_path) - - shell_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" - helm version -}