From 880a555227c52b62f9d1787091f1118f27306150 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 11 Sep 2023 13:29:44 +0200 Subject: [PATCH 1/3] feat: add `bun` installer --- src/cli/install-tool/index.ts | 2 + src/cli/tools/bun.ts | 79 +++++++++++++++++++++++++++++++++++ src/cli/tools/index.ts | 1 + test/Dockerfile.jammy | 3 ++ test/latest/Dockerfile | 5 +++ test/latest/Dockerfile.arm64 | 9 ++++ 6 files changed, 99 insertions(+) create mode 100644 src/cli/tools/bun.ts diff --git a/src/cli/install-tool/index.ts b/src/cli/install-tool/index.ts index 68356bb74..2bdb3c894 100644 --- a/src/cli/install-tool/index.ts +++ b/src/cli/install-tool/index.ts @@ -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'; @@ -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); diff --git a/src/cli/tools/bun.ts b/src/cli/tools/bun.ts new file mode 100644 index 000000000..641ff75e9 --- /dev/null +++ b/src/cli/tools/bun.ts @@ -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 { + const baseUrl = `https://github.com/oven-sh/bun/releases/download/bun-v${version}/`; + const filename = `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 { + const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin'); + + await this.shellwrapper({ srcDir: src }); + } + + override async test(_version: string): Promise { + await execa(this.name, ['--version'], { stdio: ['inherit', 'inherit', 1] }); + } +} diff --git a/src/cli/tools/index.ts b/src/cli/tools/index.ts index bb4e269ce..9ee8b806e 100644 --- a/src/cli/tools/index.ts +++ b/src/cli/tools/index.ts @@ -1,5 +1,6 @@ export const NoPrepareTools = [ 'bower', + 'bun', 'bundler', 'cocoapods', 'corepack', diff --git a/test/Dockerfile.jammy b/test/Dockerfile.jammy index 9540f7f5f..9d92fa17f 100644 --- a/test/Dockerfile.jammy +++ b/test/Dockerfile.jammy @@ -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 diff --git a/test/latest/Dockerfile b/test/latest/Dockerfile index d76a31e80..f94a98a4a 100644 --- a/test/latest/Dockerfile +++ b/test/latest/Dockerfile @@ -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 @@ -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}; \ @@ -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}; \ diff --git a/test/latest/Dockerfile.arm64 b/test/latest/Dockerfile.arm64 index f941a9c3d..a62086184 100644 --- a/test/latest/Dockerfile.arm64 +++ b/test/latest/Dockerfile.arm64 @@ -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 #-------------------------------------- @@ -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 From 480783e33a6f741f0511418c4a169eb408655239 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 11 Sep 2023 13:35:33 +0200 Subject: [PATCH 2/3] fix: wrong urls --- docs/custom-registries.md | 16 ++++++++++++++-- src/cli/tools/bun.ts | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/custom-registries.md b/docs/custom-registries.md index ba6dba1d8..37ad63536 100644 --- a/docs/custom-registries.md +++ b/docs/custom-registries.md @@ -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: @@ -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 @@ -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 diff --git a/src/cli/tools/bun.ts b/src/cli/tools/bun.ts index 641ff75e9..80814a96e 100644 --- a/src/cli/tools/bun.ts +++ b/src/cli/tools/bun.ts @@ -34,7 +34,7 @@ export class InstallBunService extends InstallToolBaseService { override async install(version: string): Promise { const baseUrl = `https://github.com/oven-sh/bun/releases/download/bun-v${version}/`; - const filename = `linux_${this.ghArch}.zip`; + const filename = `bun-linux_${this.ghArch}.zip`; const checksumFile = await this.http.download({ url: `${baseUrl}SHASUMS256.txt`, From 7058a923f56bc3dba57bebc5e5880580d64f2317 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 11 Sep 2023 15:25:34 +0200 Subject: [PATCH 3/3] fix: no custom ca support for bun --- docs/custom-root-ca.md | 6 ++++++ src/cli/tools/bun.ts | 2 +- test/latest/Dockerfile | 10 ++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/custom-root-ca.md b/docs/custom-root-ca.md index 42022388a..16e70c991 100644 --- a/docs/custom-root-ca.md +++ b/docs/custom-root-ca.md @@ -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]: + ## Buildtime install This is the easiest method. diff --git a/src/cli/tools/bun.ts b/src/cli/tools/bun.ts index 80814a96e..96e709a6e 100644 --- a/src/cli/tools/bun.ts +++ b/src/cli/tools/bun.ts @@ -34,7 +34,7 @@ export class InstallBunService extends InstallToolBaseService { override async install(version: string): Promise { const baseUrl = `https://github.com/oven-sh/bun/releases/download/bun-v${version}/`; - const filename = `bun-linux_${this.ghArch}.zip`; + const filename = `bun-linux-${this.ghArch}.zip`; const checksumFile = await this.http.download({ url: `${baseUrl}SHASUMS256.txt`, diff --git a/test/latest/Dockerfile b/test/latest/Dockerfile index f94a98a4a..f795fda14 100644 --- a/test/latest/Dockerfile +++ b/test/latest/Dockerfile @@ -48,9 +48,6 @@ 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 @@ -78,7 +75,6 @@ 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}; \ @@ -97,7 +93,6 @@ 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}; \ @@ -187,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