Files
BuYuHouDuan/deploy/build-middleware.ps1
wz1531 d083d8524b 补回 swagger(Swashbuckle 6.6.2 + XML 注释)、socket.html 入库、固化本机构建与服务器替换脚本
- Directory.Build.props: 生成 XML 注释供 Swagger 展示中文说明
- AdminHost/FishGameHost: 接入 Swashbuckle,路由 adminswagger / roomswagger
- 后台前端 config.js 改为同源相对地址,适配反向代理
- socket.html(SignalR 协议文档)纳入仓库
- deploy/: 本机构建(容器内编译,规避杀软)、服务器替换脚本、Nginx 配置
2026-10-18 17:28:45 +08:00

71 lines
2.8 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<#
本机拉取中间件镜像并导出 tar
------------------------------------------------------------------
适用场景:服务器访问不了 docker.io(拉 mongo/redis/postgres/rabbitmq 报
"error from registry: unknown error"),改为在本机拉好后传过去。
用法:
powershell -ExecutionPolicy Bypass -File deploy\build-middleware.ps1
产物:
deploy\dist\middleware.tar
随后在服务器执行:
docker load -i middleware.tar
docker compose -f deploy/docker-compose.yml up -d
#>
param(
[string]$OutFile = "",
[string[]]$Images = @("redis:7", "mongo:6.0", "postgres:16", "rabbitmq:3.13-management")
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
$Dist = Join-Path $Root "deploy\dist"
if (-not $OutFile) { $OutFile = Join-Path $Dist "middleware.tar" }
$mirrors = @("docker.m.daocloud.io", "docker.1ms.run", "docker.xuanyuan.me", "hub.rat.dev")
function Info($m) { Write-Host "[中间件] $m" -ForegroundColor Green }
function Invoke-Quiet([scriptblock]$sb) {
$prev = $ErrorActionPreference
$ErrorActionPreference = "Continue"
& $sb 2>&1 | Out-Null
$code = $LASTEXITCODE
$ErrorActionPreference = $prev
return $code
}
# ---------- 引擎检查 ----------
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { throw "未找到 docker,请先安装并启动 Docker Desktop" }
if ((Invoke-Quiet { docker info }) -ne 0) { throw "Docker 引擎未就绪,请先启动 Docker Desktop 并等托盘图标变绿" }
# ---------- 拉取镜像(逐个镜像站回退)----------
foreach ($img in $Images) {
if ((Invoke-Quiet { docker image inspect $img }) -eq 0) { Info "已存在,跳过: $img"; continue }
$done = $false
foreach ($m in $mirrors) {
Info "拉取 $img (经 $m)..."
if ((Invoke-Quiet { docker pull "$m/library/$img" }) -eq 0) {
Invoke-Quiet { docker tag "$m/library/$img" $img } | Out-Null
Info "OK: $img <= $m"
$done = $true
break
}
}
if (-not $done) { throw "镜像 $img 在所有镜像站都拉取失败,请稍后重试" }
}
# ---------- 导出 tar ----------
New-Item -ItemType Directory -Force -Path (Split-Path $OutFile) | Out-Null
Info "导出到 $OutFile (体积较大,稍候)..."
if ((Invoke-Quiet { docker save -o $OutFile @Images }) -ne 0) { throw "导出镜像失败" }
$mb = [math]::Round((Get-Item $OutFile).Length / 1MB, 1)
Info "完成!$OutFile ($mb MB)"
Write-Host "下一步 —— 本机上传:" -ForegroundColor Cyan
Write-Host " scp `"$OutFile`" root@<服务器IP>:/opt/buyu/" -ForegroundColor Cyan
Write-Host "服务器执行:" -ForegroundColor Cyan
Write-Host " cd /opt/buyu && docker load -i middleware.tar && docker compose -f deploy/docker-compose.yml up -d" -ForegroundColor Cyan