Skip to content

Commit

Permalink
feat(cli): convert kustomize
Browse files Browse the repository at this point in the history
- closes #2065
  • Loading branch information
viceice committed Jul 30, 2024
1 parent ef1c140 commit 733a397
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 28 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 @@ -26,6 +26,7 @@ import {
JavaVersionResolver,
} from '../tools/java/resolver';
import { InstallKubectlService } from '../tools/kubectl';
import { KustomizeInstallService } from '../tools/kustomize';
import { InstallNodeService } from '../tools/node';
import {
InstallRenovateService,
Expand Down Expand Up @@ -83,6 +84,7 @@ function prepareInstallContainer(): Container {
container.bind(INSTALL_TOOL_TOKEN).to(InstallJavaJreService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallJavaJdkService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallKubectlService);
container.bind(INSTALL_TOOL_TOKEN).to(KustomizeInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallMavenService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallNodeService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallRenovateService);
Expand Down
1 change: 1 addition & 0 deletions src/cli/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const NoPrepareTools = [
'helm',
'helmfile',
'kubectl',
'kustomize',
'lerna',
'maven',
'npm',
Expand Down
67 changes: 67 additions & 0 deletions src/cli/tools/kustomize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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 KustomizeInstallService extends InstallToolBaseService {
readonly name = 'kustomize';

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 baseUrl = `https://github.com/kubernetes-sigs/${name}/releases/download/${name}%2Fv${version}/`;

const checksumFile = await this.http.download({
url: `${baseUrl}checksums.txt`,
fileName: `${name}_v${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,
});
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],
});
}
}
24 changes: 0 additions & 24 deletions src/usr/local/containerbase/tools/v2/kustomize.sh

This file was deleted.

2 changes: 1 addition & 1 deletion test/helm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ COPY dist/cli/containerbase-cli-${TARGETARCH} /usr/local/containerbase/bin/conta

RUN install-containerbase

# renovate: datasource=github-releases packageName=helm/helm
# renovate: datasource=github-releases depName=helm packageName=helm/helm
ARG HELM_VERSION=3.8.0

#------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions test/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ RUN install-tool skopeo 1.16.0
# renovate: datasource=github-releases packageName=getsops/sops
RUN install-tool sops v3.9.0

# renovate: datasource=github-releases packageName=vmware-tanzu/carvel-vendir
# renovate: datasource=github-releases depName=vendir packageName=vmware-tanzu/carvel-vendir
ARG VENDIR_VERSION=0.32.2

# renovate: datasource=github-releases packageName=helmfile/helmfile
# renovate: datasource=github-releases depName=helmfile packageName=helmfile/helmfile
ARG HELMFILE_VERSION=0.150.0

# renovate: datasource=github-releases packageName=kubernetes-sigs/kustomize
# renovate: datasource=github-releases depName=kustomize packageName=kubernetes-sigs/kustomize
ARG KUSTOMIZE_VERSION=5.0.0

RUN install-tool vendir "v${VENDIR_VERSION}"
Expand Down

0 comments on commit 733a397

Please sign in to comment.