fix: 增加远程部署连通性校验
This commit is contained in:
@@ -640,6 +640,28 @@ def upload_file(ssh, local_path: Path, remote_path: str) -> None:
|
||||
sftp.close()
|
||||
|
||||
|
||||
def remote_connection_check_command(remote_dir: str) -> str:
|
||||
script = (
|
||||
"const net=require('net');"
|
||||
"const checks=[['mysql',3306],['redis',6379]];"
|
||||
"let left=checks.length;"
|
||||
"let failed=false;"
|
||||
"function done(ok){failed=failed||!ok;if(--left===0)process.exit(failed?1:0);}"
|
||||
"for(const [host,port] of checks){"
|
||||
"const socket=net.createConnection({host,port,timeout:5000},()=>{"
|
||||
"console.log(`${host}:${port} ok`);socket.destroy();done(true);"
|
||||
"});"
|
||||
"socket.on('error',(error)=>{console.error(`${host}:${port} ${error.message}`);done(false);});"
|
||||
"socket.on('timeout',()=>{console.error(`${host}:${port} timeout`);socket.destroy();done(false);});"
|
||||
"}"
|
||||
)
|
||||
return (
|
||||
f"cd {shlex.quote(remote_dir)} && "
|
||||
"docker compose --env-file .env -f docker-compose.remote.yml "
|
||||
f"exec -T api node -e {shlex.quote(script)}"
|
||||
)
|
||||
|
||||
|
||||
def deploy_remote(cfg: DeployConfig, archive_path: Path, api_image: str) -> None:
|
||||
ssh = ssh_connect(cfg)
|
||||
remote_archive = f"/tmp/{archive_path.name}"
|
||||
@@ -678,6 +700,7 @@ def deploy_remote(cfg: DeployConfig, archive_path: Path, api_image: str) -> None
|
||||
]
|
||||
),
|
||||
)
|
||||
remote_exec(ssh, remote_connection_check_command(cfg.remote_dir))
|
||||
finally:
|
||||
ssh.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user