Files
huishou/deploy-h5.py
T
2026-07-27 14:07:26 +08:00

43 lines
1.4 KiB
Python

import paramiko
import os
host = 'hs.yifenbao.cn'
port = 22
username = 'root'
password = 'Torch1112'
local_file = 'd:/Trae/huishou/h5.zip'
remote_file = '/tmp/h5.zip'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
print('连接服务器...')
ssh.connect(host, port, username, password, timeout=30)
print('Step 1: 上传文件')
sftp = ssh.open_sftp()
sftp.put(local_file, remote_file)
sftp.close()
print('Step 1完成')
print('Step 2: 解压文件')
stdin, stdout, stderr = ssh.exec_command('mkdir -p /tmp/h5-deploy && unzip -o /tmp/h5.zip -d /tmp/h5-deploy')
exit_code = stdout.channel.recv_exit_status()
print(f'Step 2完成, 退出码: {exit_code}')
if exit_code != 0:
print('解压失败:', stderr.read().decode())
print('Step 3: 复制到容器')
ssh.exec_command('docker exec huishou rm -rf /usr/share/nginx/html/h5/*')
ssh.exec_command('docker cp /tmp/h5-deploy/index.html huishou:/usr/share/nginx/html/h5/index.html')
ssh.exec_command('docker cp /tmp/h5-deploy/assets/ huishou:/usr/share/nginx/html/h5/assets/')
print('Step 3完成')
print('Step 4: 验证部署')
stdin, stdout, stderr = ssh.exec_command('docker exec huishou ls -la /usr/share/nginx/html/h5/')
print(stdout.read().decode())
print('=== H5部署完成 ===')
finally:
ssh.close()