Skip to content

Commit 95c9948

Browse files
feat: add apko tool (#5083)
1 parent b4461ad commit 95c9948

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

docs/custom-registries.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ RUN install-tool dart 2.18.0
3030

3131
GitHub releases are redirecting from `https://github.com/<org>/<repo>/releases/download/<version>/<file>` to `https://objects.githubusercontent.com/<some-url>` which seems to be an Amazon S3 bucket.
3232

33+
## `apko`
34+
35+
apko releases are downloaded from:
36+
37+
- `<https://github.com/chainguard-dev/apko/releases>
38+
39+
Samples:
40+
41+
```txt
42+
https://github.com/chainguard-dev/apko/releases/download/v0.30.11/apko_0.30.11_linux_amd64.tar.gz
43+
https://github.com/chainguard-dev/apko/releases/download/v0.30.11/apko_0.30.11_linux_arm64.tar.gz
44+
https://github.com/chainguard-dev/apko/releases/download/v0.30.11/checksums.txt
45+
```
46+
3347
## `bazelisk`
3448

3549
Bazelisk releases are downloaded from:

src/cli/install-tool/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Container, injectFromHierarchy, injectable } from 'inversify';
22
import { PathService, createContainer } from '../services';
33
import { ResolverMap } from '../tools';
4+
import { ApkoInstallService } from '../tools/apko';
45
import { BazeliskInstallService } from '../tools/bazelisk';
56
import { BunInstallService } from '../tools/bun';
67
import { DartInstallService } from '../tools/dart';
@@ -105,6 +106,7 @@ async function prepareInstallContainer(): Promise<Container> {
105106
container.bind(LinkToolService).toSelf();
106107

107108
// modern tool services
109+
container.bind(INSTALL_TOOL_TOKEN).to(ApkoInstallService);
108110
container.bind(INSTALL_TOOL_TOKEN).to(ComposerInstallService);
109111
container.bind(INSTALL_TOOL_TOKEN).to(BazeliskInstallService);
110112
container.bind(INSTALL_TOOL_TOKEN).to(BunInstallService);

src/cli/tools/apko.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import fs from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
import { execa } from 'execa';
4+
import { injectFromHierarchy, injectable } from 'inversify';
5+
import { BaseInstallService } from '../install-tool/base-install.service';
6+
7+
@injectable()
8+
@injectFromHierarchy()
9+
export class ApkoInstallService extends BaseInstallService {
10+
readonly name = 'apko';
11+
12+
private get ghArch(): string {
13+
switch (this.envSvc.arch) {
14+
case 'arm64':
15+
return 'arm64';
16+
case 'amd64':
17+
return 'amd64';
18+
}
19+
}
20+
21+
override async install(version: string): Promise<void> {
22+
/**
23+
* @example
24+
* @see {@href https://github.com/chainguard-dev/apko/releases/tag/v0.30.11}
25+
*/
26+
const baseUrl = `https://github.com/chainguard-dev/apko/releases/download/v${version}/`;
27+
28+
const filename = `apko_${version}_linux_${this.ghArch}.tar.gz`;
29+
30+
const checksumFile = await this.http.download({
31+
url: `${baseUrl}checksums.txt`,
32+
});
33+
const expectedChecksum = (await fs.readFile(checksumFile, 'utf-8'))
34+
.split('\n')
35+
.find((l) => l.includes(filename))
36+
?.split(' ')[0];
37+
38+
const file = await this.http.download({
39+
url: `${baseUrl}${filename}`,
40+
checksumType: 'sha256',
41+
expectedChecksum,
42+
});
43+
44+
await this.pathSvc.ensureToolPath(this.name);
45+
46+
const path = join(
47+
await this.pathSvc.createVersionedToolPath(this.name, version),
48+
'bin',
49+
);
50+
await fs.mkdir(path);
51+
await this.compress.extract({
52+
file,
53+
cwd: path,
54+
strip: 1,
55+
});
56+
}
57+
58+
override async link(version: string): Promise<void> {
59+
const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin');
60+
await this.shellwrapper({ srcDir: src });
61+
}
62+
63+
override async test(_version: string): Promise<void> {
64+
await execa(this.name, ['version'], { stdio: ['inherit', 'inherit', 1] });
65+
}
66+
}

src/cli/tools/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { InstallToolType } from '../install-tool';
22

33
export const NoPrepareTools = [
4+
'apko',
45
'bazelisk',
56
'bower',
67
'bun',

test/latest/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ RUN install-tool bun 1.2.22
225225
# renovate: datasource=github-releases packageName=denoland/deno
226226
RUN install-tool deno 2.5.1
227227

228+
# renovate: datasource=github-releases packageName=chainguard-dev/apko
229+
RUN install-tool apko 0.30.11
230+
228231
# renovate: datasource=github-releases packageName=jetify-com/devbox
229232
RUN install-tool devbox 0.16.0
230233

test/latest/Dockerfile.arm64

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ FROM base AS test-deno
5656
# renovate: datasource=github-releases packageName=denoland/deno
5757
RUN install-tool deno 2.5.1
5858

59+
#--------------------------------------
60+
# Image: apko
61+
#--------------------------------------
62+
FROM base AS test-apko
63+
64+
# renovate: datasource=github-releases packageName=chainguard-dev/apko
65+
RUN install-tool apko 0.30.11
66+
5967
#--------------------------------------
6068
# Image: devbox
6169
#--------------------------------------
@@ -159,6 +167,7 @@ FROM base
159167
COPY --from=test-bazelisk /.dummy /.dummy
160168
COPY --from=test-bun /.dummy /.dummy
161169
COPY --from=test-deno /.dummy /.dummy
170+
COPY --from=test-apko /.dummy /.dummy
162171
COPY --from=test-devbox /.dummy /.dummy
163172
COPY --from=test-docker /.dummy /.dummy
164173
COPY --from=test-git /.dummy /.dummy

0 commit comments

Comments
 (0)