Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bun installer #1441

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ RUN install-tool docker v24.0.2
RUN install-tool dart 2.18.0
```

## bun

Bun releases are downloaded from:

- `https://github.com/oven-sh/bun/releases/download`

Samples:

```txt
https://github.com/oven-sh/bun/releases/download/bun-v1.0.0/bun-linux-x64.zip
https://github.com/oven-sh/bun/releases/download/bun-v1.0.0/bun-linux-aarch64.zip
https://github.com/oven-sh/bun/releases/download/bun-v1.0.0/SHASUMS256.txt
```

## dart

Dart releases are downloaded from:
Expand All @@ -39,7 +53,6 @@ https://storage.googleapis.com/dart-archive/channels/stable/release/2.18.0/sdk/d
https://storage.googleapis.com/dart-archive/channels/stable/release/2.19.4/sdk/dartsdk-linux-x64-release.zip.sha256sum
https://storage.googleapis.com/dart-archive/channels/stable/release/2.19.4/sdk/dartsdk-linux-arm64-release.zip
https://storage.googleapis.com/dart-archive/channels/stable/release/2.19.4/sdk/dartsdk-linux-arm64-release.zip.sha256sum

```

## docker
Expand All @@ -53,7 +66,6 @@ Samples:
```txt
https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz
https://download.docker.com/linux/static/stable/aarch64/docker-24.0.5.tgz

```

## dotnet
Expand Down
6 changes: 6 additions & 0 deletions docs/custom-root-ca.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Most tools support two ways to extend the default Root CA certificates list.

If you are using a custom base image, checkout [Custom base image](./custom-base-image.md) docs.

## Notes

1. `Bun` doesn't support custom root ca certificates[^1].

[^1]: <https://github.com/oven-sh/bun/issues/271>

## Buildtime install

This is the easiest method.
Expand Down
2 changes: 2 additions & 0 deletions src/cli/install-tool/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container, injectable } from 'inversify';
import { rootContainer } from '../services';
import { InstallBunService } from '../tools/bun';
import { InstallDartService } from '../tools/dart';
import { InstallDockerService } from '../tools/docker';
import { InstallDotnetService } from '../tools/dotnet';
Expand Down Expand Up @@ -38,6 +39,7 @@ function prepareContainer(): Container {

// tool services
container.bind(INSTALL_TOOL_TOKEN).to(InstallBowerService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallBunService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallBundlerService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallCocoapodsService);
container.bind(INSTALL_TOOL_TOKEN).to(InstallCorepackService);
Expand Down
79 changes: 79 additions & 0 deletions src/cli/tools/bun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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 InstallBunService extends InstallToolBaseService {
readonly name = 'bun';

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

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/oven-sh/bun/releases/download/bun-v${version}/`;
const filename = `bun-linux-${this.ghArch}.zip`;

const checksumFile = await this.http.download({
url: `${baseUrl}SHASUMS256.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,
strip: 1,
});
}

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(this.name, ['--version'], { stdio: ['inherit', 'inherit', 1] });
}
}
1 change: 1 addition & 0 deletions src/cli/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const NoPrepareTools = [
'bower',
'bun',
'bundler',
'cocoapods',
'corepack',
Expand Down
3 changes: 3 additions & 0 deletions test/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ RUN prepare-tool all
#--------------------------------------
FROM build as test

# renovate: datasource=npm
RUN install-tool bun v1.0.0

# renovate datasource=docker
RUN install-tool dart 2.18.0

Expand Down
5 changes: 4 additions & 1 deletion test/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ RUN prepare-tool all
RUN set -ex; [ -d /usr/local/erlang ] && echo "works" || exit 1;

#--------------------------------------
# test: vendir, helmfile, kustomize
# test: bun, vendir, helmfile, kustomize
#--------------------------------------
FROM base as teste

# renovate: datasource=npm
RUN install-tool bun v1.0.0

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

Expand Down
9 changes: 9 additions & 0 deletions test/latest/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ COPY src/ /

RUN install-containerbase

#--------------------------------------
# Image: bun
#--------------------------------------
FROM base as test-bun

# renovate: datasource=npm
RUN install-tool bun v1.0.0

#--------------------------------------
# Image: docker
#--------------------------------------
Expand Down Expand Up @@ -77,6 +85,7 @@ RUN install-tool vendir v0.34.4
#--------------------------------------
FROM base

COPY --from=test-bun /.dummy /.dummy
COPY --from=test-docker /.dummy /.dummy
COPY --from=test-git /.dummy /.dummy
COPY --from=test-git-lfs /.dummy /.dummy
Expand Down