-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- closes #2064
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 HelmfileInstallService extends InstallToolBaseService { | ||
readonly name = 'helmfile'; | ||
|
||
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}_${version}_linux_${this.envSvc.arch}.tar.gz`; | ||
const url = `https://github.com/${name}/${name}/releases/download/v${version}/`; | ||
|
||
const expectedChecksum = await this._getChecksum( | ||
`${url}${name}_${version}_checksums.txt`, | ||
filename, | ||
); | ||
const file = await this.http.download({ | ||
url: `${url}${filename}`, | ||
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 }); | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters