Skip to content

Commit

Permalink
feat(cli): convert flux (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Jul 18, 2023
1 parent 5d26a78 commit c35bc93
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 24 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 @@ -2,6 +2,7 @@ import { Container } from 'inversify';
import { rootContainer } from '../services';
import { InstallDartService } from '../tools/dart';
import { InstallDockerService } from '../tools/docker';
import { InstallFluxService } from '../tools/flux';
import { logger } from '../utils';
import { InstallLegacyToolService } from './install-legacy-tool.service';
import { INSTALL_TOOL_TOKEN, InstallToolService } from './install-tool.service';
Expand All @@ -18,6 +19,7 @@ function prepareContainer(): Container {
// tool services
container.bind(INSTALL_TOOL_TOKEN).to(InstallDockerService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallDartService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallFluxService);

logger.trace('preparing container done');
return container;
Expand Down
77 changes: 77 additions & 0 deletions src/cli/tools/flux/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import fs from 'node:fs/promises';
import { join } 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 InstallFluxService extends InstallToolBaseService {
readonly name = 'flux';

private get arch(): string {
return this.envSvc.arch;
}

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 baseUrl = `https://github.com/fluxcd/flux2/releases/download/v${version}/`;
const filename = `flux_${version}_linux_${this.arch}.tar.gz`;

const checksumFile = await this.http.download({
url: `${baseUrl}flux_${version}_checksums.txt`,
});
const expectedChecksum = (await fs.readFile(checksumFile, 'utf-8'))
.split('\n')
.find((l) => l.includes(filename))
?.split(' ')[0];

const file = await this.http.download({
url: `${baseUrl}${filename}`,
checksumType: 'sha256',
expectedChecksum,
});

// TODO: create recursive
if (!(await this.pathSvc.findToolPath(this.name))) {
await this.pathSvc.createToolPath(this.name);
}

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
'bin'
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
});
}

override async link(version: string): Promise<void> {
const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin');

await this.shellwrapper({ srcDir: src });
}

override needsPrepare(): boolean {
return false;
}

override async test(_version: string): Promise<void> {
await execa('flux', ['--version'], { stdio: 'inherit' });
}
}
24 changes: 0 additions & 24 deletions src/usr/local/containerbase/tools/v2/flux.sh

This file was deleted.

0 comments on commit c35bc93

Please sign in to comment.