Skip to content

Commit

Permalink
feat(cli): convert skopeo
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Jul 30, 2024
1 parent 487f722 commit 54c6f76
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 52 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 @@ -44,6 +44,7 @@ import { PipVersionResolver } from '../tools/python/pip';
import { InstallPipBaseService } from '../tools/python/utils';
import { InstallCocoapodsService } from '../tools/ruby/gem';
import { InstallRubyBaseService } from '../tools/ruby/utils';
import { SkopeoInstallService } from '../tools/skopeo';
import { SopsInstallService } from '../tools/sops';
import { logger } from '../utils';
import { InstallLegacyToolService } from './install-legacy-tool.service';
Expand Down Expand Up @@ -81,6 +82,7 @@ function prepareInstallContainer(): Container {
container.bind(INSTALL_TOOL_TOKEN).to(InstallMavenService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallNodeService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallRenovateService);
container.bind(INSTALL_TOOL_TOKEN).to(SkopeoInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(SopsInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallYarnService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallYarnSlimService);
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 @@ -24,6 +24,7 @@ export const NoPrepareTools = [
'pnpm',
'poetry',
'renovate',
'skopeo',
'sops',
'yarn',
'yarn-slim',
Expand Down
65 changes: 65 additions & 0 deletions src/cli/tools/skopeo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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 SkopeoInstallService extends InstallToolBaseService {
readonly name = 'skopeo';

private get ghArch(): string {
switch (this.envSvc.arch) {
case 'arm64':
return 'aarch64';
case 'amd64':
return 'x86_64';
}
}

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}-${this.ghArch}.tar.xz`;
const url = `https://github.com/containerbase/${name}-prebuild/releases/download/${version}/${filename}`;
const checksumFileUrl = `${url}.sha512`;

const checksumFile = await this.http.download({ url: checksumFileUrl });
const expectedChecksum = (await fs.readFile(checksumFile, 'utf-8')).trim();
const file = await this.http.download({
url,
checksumType: 'sha512',
expectedChecksum,
});
await this.compress.extract({ file, cwd: await this.getToolPath() });
}

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

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

private async getToolPath(): Promise<string> {
return await this.pathSvc.ensureToolPath(this.name);
}
}
52 changes: 0 additions & 52 deletions src/usr/local/containerbase/tools/v2/skopeo.sh

This file was deleted.

3 changes: 3 additions & 0 deletions test/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ RUN install-tool powershell v7.4.4
# renovate: datasource=docker versioning=docker
RUN install-tool rust 1.80.0

# renovate: datasource=github-releases packageName=containerbase/skopeo-prebuild
RUN install-tool skopeo 1.16.0

# renovate: datasource=github-releases packageName=getsops/sops
RUN install-tool sops v3.9.0

Expand Down
3 changes: 3 additions & 0 deletions test/Dockerfile.noble
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ RUN install-tool powershell v7.4.4
# renovate: datasource=docker versioning=docker
RUN install-tool rust 1.80.0

# renovate: datasource=github-releases packageName=containerbase/skopeo-prebuild
RUN install-tool skopeo 1.16.0

# renovate: datasource=github-releases packageName=getsops/sops
RUN install-tool sops v3.9.0

Expand Down
3 changes: 3 additions & 0 deletions test/latest/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ FROM base AS test-others
# renovate: datasource=github-releases packageName=kubernetes/kubernetes
RUN install-tool kubectl v1.30.3

# renovate: datasource=github-releases packageName=containerbase/skopeo-prebuild
RUN install-tool skopeo 1.16.0

# renovate: datasource=github-releases packageName=getsops/sops
RUN install-tool sops v3.9.0

Expand Down

0 comments on commit 54c6f76

Please sign in to comment.