feat: bundle multi-arch nginx for native fnOS stage 2

This commit is contained in:
2026-10-02 15:32:37 +08:00
parent 6725fc131d
commit b05098926c
6 changed files with 108 additions and 7 deletions
+54
View File
@@ -21,6 +21,55 @@ function Copy-Tree {
}
}
function Resolve-DockerCli {
if ($env:DOCKER_BIN) { return $env:DOCKER_BIN }
$command = Get-Command docker -ErrorAction SilentlyContinue
if ($command) { return $command.Source }
$default = "C:\Program Files\Docker\Docker\resources\bin\docker.exe"
if (Test-Path -LiteralPath $default) { return $default }
throw "找不到 docker 命令"
}
function Export-Nginx {
param(
[string]$DockerBin,
[string]$Platform,
[string]$Arch,
[string]$Image,
[string]$OutputDir
)
$archInfo = (& $DockerBin image inspect $Image --format '{{.Architecture}}' 2>$null)
if ($LASTEXITCODE -ne 0) {
throw "找不到 Nginx 来源镜像:$Image"
}
if ($archInfo.Trim() -ne $Arch) {
throw "镜像架构不匹配:$Image 是 $($archInfo.Trim()),需要 $Arch"
}
$archDir = Join-Path $OutputDir $Arch
New-Item -ItemType Directory -Force $archDir | Out-Null
$script = @'
set -e
mkdir -p /out/lib
cp /usr/sbin/nginx /out/nginx
cp /etc/nginx/mime.types /out/mime.types
ldd /usr/sbin/nginx | awk '/=> \// {print $3} /^\// {print $1}' | sort -u | while read lib; do
case "$(basename "$lib")" in
libc.so.6|ld-linux-*.so.*) continue ;;
esac
cp "$lib" /out/lib/
done
'@
& $DockerBin run --rm --platform $Platform -v "${archDir}:/out" --entrypoint sh $Image -c $script
if ($LASTEXITCODE -ne 0) {
throw "提取 $Arch Nginx 失败,退出码:$LASTEXITCODE"
}
Copy-Item -LiteralPath (Join-Path $archDir "mime.types") -Destination (Join-Path $OutputDir "mime.types") -Force
}
if (-not (Test-Path -LiteralPath $project)) {
throw "找不到 Native 应用工程:$project"
}
@@ -67,6 +116,11 @@ if ($LASTEXITCODE -ge 8) {
Copy-Tree -Source (Join-Path $mainRepo "migrations") -Destination (Join-Path $stage "app\migrations")
Copy-Tree -Source (Join-Path $mainRepo "web\assets\image") -Destination (Join-Path $stage "app\web\assets\image")
$serverDir = Join-Path $stage "app\server"
$dockerBin = Resolve-DockerCli
Export-Nginx -DockerBin $dockerBin -Platform "linux/amd64" -Arch "amd64" -Image "jayhub.top/mrlee/havline:$version" -OutputDir $serverDir
Export-Nginx -DockerBin $dockerBin -Platform "linux/arm64" -Arch "arm64" -Image "havline:$version" -OutputDir $serverDir
$env:CGO_ENABLED = "0"
$env:GOOS = "linux"