From 5ca57229a3cda5054ae0adbfdba7ad051de2212a Mon Sep 17 00:00:00 2001 From: chuan Date: Sun, 17 May 2026 01:57:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0bun=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bun/.env | 3 +++ Bun/Dockerfile | 15 +++++++++++++ Bun/compose.yml | 12 ++++++++++ Bun/test.bat | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 Bun/.env create mode 100644 Bun/Dockerfile create mode 100644 Bun/compose.yml create mode 100644 Bun/test.bat diff --git a/Bun/.env b/Bun/.env new file mode 100644 index 0000000..4a707e4 --- /dev/null +++ b/Bun/.env @@ -0,0 +1,3 @@ +BASE_IMAGE=ubuntu-xray-transparent-test +IMAGE=bun-test +BUN_REGISTRY=https://registry.npmmirror.com/ diff --git a/Bun/Dockerfile b/Bun/Dockerfile new file mode 100644 index 0000000..a58670d --- /dev/null +++ b/Bun/Dockerfile @@ -0,0 +1,15 @@ +ARG BASE_IMAGE=ubuntu-xray-transparent-test +FROM ${BASE_IMAGE} + +ARG BUN_REGISTRY=https://registry.npmmirror.com/ + +ENV BUN_INSTALL=/opt/bun \ + PATH=/opt/bun/bin:${PATH} + +# Install Bun with the official installer, then configure Bun's npm registry. +RUN set -eux; \ + curl -fsSL https://bun.com/install | bash; \ + ln -sf /opt/bun/bin/bun /usr/local/bin/bun; \ + mkdir -p /root; \ + printf '[install]\nregistry = "%s"\n' "${BUN_REGISTRY}" > /root/.bunfig.toml; \ + bun --version diff --git a/Bun/compose.yml b/Bun/compose.yml new file mode 100644 index 0000000..607b68e --- /dev/null +++ b/Bun/compose.yml @@ -0,0 +1,12 @@ +services: + test: + build: + context: . + args: + BASE_IMAGE: ${BASE_IMAGE:-ubuntu-xray-transparent-test} + BUN_REGISTRY: ${BUN_REGISTRY:-https://registry.npmmirror.com/} + image: ${IMAGE:-bun-test} + environment: + S6_LOGGING: "0" + XRAY_ENABLED: "0" + BUN_REGISTRY: ${BUN_REGISTRY:-https://registry.npmmirror.com/} diff --git a/Bun/test.bat b/Bun/test.bat new file mode 100644 index 0000000..8ceaa99 --- /dev/null +++ b/Bun/test.bat @@ -0,0 +1,59 @@ +@echo off +setlocal + +REM FORCE_BUILD=1: rebuild the Bun image with --no-cache before running tests. +REM FORCE_BUILD=0: reuse the existing Bun image; build only with Docker cache. +set "FORCE_BUILD=0" + +REM VERBOSE=1: print full stdout/stderr logs for every test. +REM VERBOSE=0: print only [PASS], [NO], and reason lines; full logs stay in logs\. +set "VERBOSE=0" + +cd /d "%~dp0" + +if not exist logs mkdir logs + +if "%FORCE_BUILD%"=="1" ( + docker compose --env-file .env -f compose.yml build --no-cache >logs\build.out 2>logs\build.err + if errorlevel 1 ( + call :build_failed + exit /b %errorlevel% + ) +) else ( + docker compose --env-file .env -f compose.yml build >logs\build.out 2>logs\build.err + if errorlevel 1 ( + call :build_failed + exit /b %errorlevel% + ) +) + +docker compose --env-file .env -f compose.yml run --rm --no-deps test bun --version >logs\bun-exists.out 2>logs\bun-exists.err +set "BUN_EXISTS_CODE=%errorlevel%" +if "%BUN_EXISTS_CODE%"=="0" ( + call :pass "bun exists" +) else ( + call :no "bun exists" logs\bun-exists.err +) + +docker compose --env-file .env -f compose.yml run --rm --no-deps test bash -lc "grep -F registry.npmmirror.com /root/.bunfig.toml && tmpdir=$(mktemp -d) && cd $tmpdir && printf '{\"name\":\"bun-registry-test\",\"version\":\"0.0.0\",\"private\":true,\"dependencies\":{\"is-number\":\"7.0.0\"}}\n' > package.json && bun install --lockfile-only" >logs\bun-install-registry.out 2>logs\bun-install-registry.err +set "BUN_INSTALL_REGISTRY_CODE=%errorlevel%" +if "%BUN_INSTALL_REGISTRY_CODE%"=="0" ( + call :pass "bun install uses npmmirror registry" +) else ( + call :no "bun install uses npmmirror registry" logs\bun-install-registry.err +) + +if not "%BUN_EXISTS_CODE%"=="0" exit /b %BUN_EXISTS_CODE% +exit /b %BUN_INSTALL_REGISTRY_CODE% + +:pass +powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host '[PASS] %~1' -ForegroundColor Green" +exit /b 0 + +:no +powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host '[NO] %~1' -ForegroundColor Red; $reason=(Get-Content -LiteralPath '%~2' -ErrorAction SilentlyContinue | Where-Object { $_ } | Select-Object -Last 1); if(!$reason){ $reason='see logs for details' }; Write-Host ('reason: ' + $reason) -ForegroundColor Red" +exit /b 0 + +:build_failed +powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host '[NO] build Bun image' -ForegroundColor Red; $reason=(Get-Content -LiteralPath 'logs\build.err' -ErrorAction SilentlyContinue | Where-Object { $_ } | Select-Object -Last 1); if(!$reason){ $reason='docker compose build failed; see Bun\logs\build.err' }; Write-Host ('reason: ' + $reason) -ForegroundColor Red" +exit /b 0