feat: 增加bun编译镜像

This commit is contained in:
chuan
2026-05-17 01:57:32 +08:00
parent d9bf7f4acf
commit 5ca57229a3
4 changed files with 89 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
BASE_IMAGE=ubuntu-xray-transparent-test
IMAGE=bun-test
BUN_REGISTRY=https://registry.npmmirror.com/
+15
View File
@@ -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
+12
View File
@@ -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/}
+59
View File
@@ -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