Skip to content

Commit

Permalink
feat(cli): convert helm
Browse files Browse the repository at this point in the history
- closes #2063
  • Loading branch information
viceice committed Jul 30, 2024
1 parent 54c6f76 commit 3885faf
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/cli/install-tool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
75 changes: 75 additions & 0 deletions src/cli/tools/helm.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
const src = path.join(
this.pathSvc.versionedToolPath(this.name, version),
'bin',
);
await this.shellwrapper({ srcDir: src });
}

override async test(_version: string): Promise<void> {
await execa(this.name, ['version'], {
stdio: ['inherit', 'inherit', 1],
});
}

/** TODO: create helper */
protected async _getChecksum(
url: string,
filename: string,
): Promise<string | undefined> {
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;
}
}
1 change: 1 addition & 0 deletions src/cli/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const NoPrepareTools = [
'gleam',
'gradle',
'hashin',
'helm',
'kubectl',
'lerna',
'maven',
Expand Down
25 changes: 0 additions & 25 deletions src/usr/local/containerbase/tools/v2/helm.sh

This file was deleted.

0 comments on commit 3885faf

Please sign in to comment.