fix: keep deployment SSH sessions alive

This commit is contained in:
江林铖 2026-08-27 06:15:18 +08:00
parent ee1500ab64
commit 2b51d220a5
3 changed files with 18 additions and 1 deletions

View File

@ -155,6 +155,9 @@ function sshArguments(identityFile, knownHostsFile) {
'-o', 'StrictHostKeyChecking=yes',
'-o', `UserKnownHostsFile=${knownHostsFile}`,
'-o', 'ConnectTimeout=10',
'-o', 'ServerAliveInterval=3',
'-o', 'ServerAliveCountMax=10',
'-o', 'TCPKeepAlive=yes',
'-i', identityFile,
]
}

View File

@ -819,7 +819,9 @@ actual_prod_host_key="$(ssh-keygen -F "$PROD_SERVER_IP" -f "$PROD_KNOWN_HOSTS_FI
ok "Build server tools are available"
prod_ssh() {
ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$PROD_KNOWN_HOSTS_FILE" -o ConnectTimeout=8 "$PROD_SERVER_USER@$PROD_SERVER_IP" "$@"
ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$PROD_KNOWN_HOSTS_FILE" \
-o ConnectTimeout=8 -o ServerAliveInterval=3 -o ServerAliveCountMax=10 -o TCPKeepAlive=yes \
"$PROD_SERVER_USER@$PROD_SERVER_IP" "$@"
}
prod_ssh_script() {

View File

@ -40,3 +40,15 @@ test('Mac entry requires an exact commit outside DryRun', () => {
assert.equal(parseArguments(['--dry-run']).dryRun, true)
assert.equal(parseArguments(['--commit', 'b'.repeat(40)]).commit, 'b'.repeat(40))
})
test('deployment SSH hops keep long builds and cutovers alive', () => {
const macSource = readFileSync(new URL('./git-incremental-deploy-macos.mjs', import.meta.url), 'utf8')
const powerShellSource = readFileSync(new URL('./git-incremental-deploy.ps1', import.meta.url), 'utf8')
const payload = extractRemoteTemplate(powerShellSource)
for (const source of [macSource, payload]) {
assert.match(source, /ServerAliveInterval=3/)
assert.match(source, /ServerAliveCountMax=10/)
assert.match(source, /TCPKeepAlive=yes/)
}
})