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 2 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
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: 5 additions & 0 deletions test/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ RUN set -ex; \
#--------------------------------------
FROM build as testa

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

# renovate: datasource=node
RUN install-tool node v18.17.1

Expand Down Expand Up @@ -75,6 +78,7 @@ RUN set -ex; \
nginx; \
su -c 'SSL_CERT_FILE=/test/ca.pem curl -svo /dev/null https://localhost' ${USER_NAME}; \
su -c 'SSL_CERT_FILE=/test/ca.pem curl -svo /dev/null https://buildkitsandbox' ${USER_NAME}; \
su -c 'SSL_CERT_FILE=/test/ca.pem bun run request.mjs' ${USER_NAME}; \
su -c 'SSL_CERT_FILE=/test/ca.pem node request.mjs' ${USER_NAME}; \
su -c 'NODE_EXTRA_CA_CERTS=/test/ca.pem node request.mjs' ${USER_NAME}; \
su -c 'SSL_CERT_FILE=/test/ca.pem php request.php' ${USER_NAME}; \
Expand All @@ -93,6 +97,7 @@ RUN set -ex \
RUN set -ex; \
nginx; \
su -c 'curl -svo /dev/null https://buildkitsandbox' ${USER_NAME}; \
su -c 'bun run request.mjs' ${USER_NAME}; \
su -c 'node request.mjs' ${USER_NAME}; \
su -c 'npm_config_registry=https://localhost npm ping' ${USER_NAME}; \
su -c 'php request.php' ${USER_NAME}; \
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