来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
61 lines
2.0 KiB
PowerShell
61 lines
2.0 KiB
PowerShell
param(
|
|
[ValidateSet('h5', 'api', 'both')]
|
|
[string]$Target = 'both',
|
|
[string]$KeyFile = '',
|
|
[string]$User = 'root'
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$root = Split-Path -Parent $PSScriptRoot
|
|
if (-not $KeyFile) {
|
|
$candidates = @(
|
|
(Join-Path $root 'deploy\id_rsa_tencent'),
|
|
(Join-Path $root 'id_rsa_tencent')
|
|
)
|
|
foreach ($c in $candidates) {
|
|
if (Test-Path $c) { $KeyFile = $c; break }
|
|
}
|
|
}
|
|
|
|
if (-not $KeyFile -or -not (Test-Path $KeyFile)) {
|
|
Write-Error "SSH key not found. Place private key at deploy\id_rsa_tencent or pass -KeyFile"
|
|
}
|
|
|
|
$envFile = Join-Path $root '.env.tencent'
|
|
$lines = @{}
|
|
if (Test-Path $envFile) {
|
|
Get-Content $envFile | ForEach-Object {
|
|
if ($_ -match '^\s*#' -or $_ -notmatch '=') { return }
|
|
$k, $v = $_ -split '=', 2
|
|
$lines[$k.Trim()] = $v.Trim()
|
|
}
|
|
}
|
|
|
|
$hosts = @{
|
|
h5 = @{ Name = 'test-h5'; Ip = $lines['TENCENT_PROD_H5_IP'] ?? '119.45.34.106'; User = 'root' }
|
|
api = @{ Name = 'test-api'; Ip = $lines['TENCENT_PROD_API_IP'] ?? '146.56.223.139'; User = 'ubuntu' }
|
|
}
|
|
|
|
$ssh = Get-Command ssh -ErrorAction SilentlyContinue
|
|
if (-not $ssh) {
|
|
Write-Error 'OpenSSH client not found. Enable "OpenSSH Client" in Windows Optional Features.'
|
|
}
|
|
|
|
function Invoke-Remote([string]$ip, [string]$label, [string]$role, [string]$sshUser) {
|
|
Write-Host "`n=== $label ($ip) role=$role user=$sshUser ===" -ForegroundColor Cyan
|
|
$cmd = "cd /opt/ai-fresh-delivery 2>/dev/null || cd ~/Projects/canteen-delivery; bash scripts/prod-on-server.sh $role"
|
|
& ssh -i $KeyFile -o StrictHostKeyChecking=accept-new -o ConnectTimeout=15 "${sshUser}@${ip}" $cmd
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Warning "$label failed (exit $LASTEXITCODE). Check repo path on server."
|
|
}
|
|
}
|
|
|
|
if ($Target -eq 'h5' -or $Target -eq 'both') {
|
|
Invoke-Remote $hosts.h5.Ip $hosts.h5.Name 'h5' $hosts.h5.User
|
|
}
|
|
if ($Target -eq 'api' -or $Target -eq 'both') {
|
|
Invoke-Remote $hosts.api.Ip $hosts.api.Name 'api' $hosts.api.User
|
|
}
|
|
|
|
Write-Host "`nDone." -ForegroundColor Green
|