|
|
# 方案 C:开发机构镜像 + 服务器 load(最省服务器内存)
|
|
|
# Usage: powershell -ExecutionPolicy Bypass -File deploy/pack-prebuilt-upload.ps1
|
|
|
#
|
|
|
# 产出:
|
|
|
# 上传到服务器/
|
|
|
# ├── 镜像/yubao-app-image.tar
|
|
|
# ├── 部署/deploy/ (仅脚本 + compose,不含 src)
|
|
|
# ├── 数据库/ (SQL,可选)
|
|
|
# └── README.md
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
|
|
$Out = Join-Path $Root ([char]0x4e0a + [char]0x4f20 + [char]0x5230 + [char]0x670d + [char]0x52a1 + [char]0x5668)
|
|
|
$ImageDir = Join-Path $Out ([char]0x955c + [char]0x50cf)
|
|
|
$DeployDir = Join-Path $Out ([char]0x90e8 + [char]0x7f72)
|
|
|
$DbDir = Join-Path $Out ([char]0x6570 + [char]0x636e + [char]0x5e93)
|
|
|
|
|
|
Write-Host "prebuilt-pack: build image on dev machine…"
|
|
|
& (Join-Path $Root "deploy\build-image-local.ps1")
|
|
|
|
|
|
$TarSrc = Join-Path $Root "deploy\yubao-app-image.tar"
|
|
|
if (-not (Test-Path $TarSrc)) {
|
|
|
throw "missing $TarSrc after build"
|
|
|
}
|
|
|
|
|
|
Write-Host "prebuilt-pack: clean $Out (keep build tar)"
|
|
|
if (Test-Path $Out) {
|
|
|
Remove-Item -Recurse -Force $Out
|
|
|
}
|
|
|
New-Item -ItemType Directory -Path $ImageDir -Force | Out-Null
|
|
|
New-Item -ItemType Directory -Path (Join-Path $DeployDir "deploy") -Force | Out-Null
|
|
|
New-Item -ItemType Directory -Path $DbDir -Force | Out-Null
|
|
|
|
|
|
Copy-Item $TarSrc (Join-Path $ImageDir "yubao-app-image.tar") -Force
|
|
|
Write-Host "prebuilt-pack: image copied"
|
|
|
|
|
|
$DeployFiles = @(
|
|
|
"docker-compose.prebuilt.yml",
|
|
|
"docker-compose.bt-host-mysql.yml",
|
|
|
".env.bt-host-mysql.example",
|
|
|
"install-prebuilt-image.sh",
|
|
|
"update-prebuilt-image.sh",
|
|
|
"install-bt-host-mysql.sh",
|
|
|
"install-bt-host-mysql-lowmem.sh",
|
|
|
"update-code-only-bt-host-mysql.sh"
|
|
|
)
|
|
|
$deployDst = Join-Path $DeployDir "deploy"
|
|
|
foreach ($f in $DeployFiles) {
|
|
|
$src = Join-Path $Root "deploy\$f"
|
|
|
if (Test-Path $src) {
|
|
|
Copy-Item $src (Join-Path $deployDst $f) -Force
|
|
|
Write-Host "prebuilt-pack: deploy/$f"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
# scripts/docker-entrypoint-web.sh referenced in compose lives in image; not needed on host
|
|
|
|
|
|
$DbFiles = @("email_forecast.sql", "email_forecast.sql.gz", "README.md")
|
|
|
foreach ($f in $DbFiles) {
|
|
|
$src = Join-Path $Root "deploy\database\$f"
|
|
|
if (Test-Path $src) {
|
|
|
Copy-Item $src (Join-Path $DbDir $f) -Force
|
|
|
Write-Host "prebuilt-pack: database/$f"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function Convert-ShFilesToLf {
|
|
|
param([string]$BaseDir)
|
|
|
Get-ChildItem -Path $BaseDir -Filter "*.sh" -Recurse -File | ForEach-Object {
|
|
|
$text = [System.IO.File]::ReadAllText($_.FullName)
|
|
|
$fixed = $text -replace "`r`n", "`n" -replace "`r", "`n"
|
|
|
if ($text -ne $fixed) {
|
|
|
[System.IO.File]::WriteAllText($_.FullName, $fixed, [System.Text.UTF8Encoding]::new($false))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Convert-ShFilesToLf -BaseDir $DeployDir
|
|
|
|
|
|
$readmePath = Join-Path $Root "deploy\pack-prebuilt-readme.md"
|
|
|
if (Test-Path $readmePath) {
|
|
|
Copy-Item $readmePath (Join-Path $Out "README.md") -Force
|
|
|
} else {
|
|
|
Set-Content -Path (Join-Path $Out "README.md") -Value "# 预构建镜像部署`n见 deploy/pack-prebuilt-readme.md" -Encoding UTF8
|
|
|
}
|
|
|
|
|
|
$imgMb = [math]::Round((Get-Item (Join-Path $ImageDir "yubao-app-image.tar")).Length / 1MB, 1)
|
|
|
Write-Host ""
|
|
|
Write-Host "prebuilt-pack: done -> $Out"
|
|
|
Write-Host ("prebuilt-pack: image=" + $imgMb + "MB")
|