60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const config = {
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
};
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', async () => {
|
|
console.log('SSH连接成功');
|
|
|
|
try {
|
|
console.log('\n=== 1. 删除容器内旧的H5文件 ===');
|
|
await executeCommand('docker exec huishou rm -rf /usr/share/nginx/html/h5/*');
|
|
|
|
console.log('\n=== 2. 重新复制H5文件到容器 ===');
|
|
await executeCommand('docker cp /www/huishou/dist/build/h5/. huishou:/usr/share/nginx/html/h5/');
|
|
|
|
console.log('\n=== 3. 检查容器内文件时间 ===');
|
|
await executeCommand('docker exec huishou ls -la /usr/share/nginx/html/h5/assets/index-CFIPh5xV.js');
|
|
await executeCommand('docker exec huishou ls -la /usr/share/nginx/html/h5/index.html');
|
|
|
|
console.log('\n=== 4. 测试H5页面访问 ===');
|
|
await executeCommand('curl -s http://localhost:4001/h5/');
|
|
|
|
console.log('\n=== 5. 测试JS资源 ===');
|
|
await executeCommand('curl -s -o /dev/null -w "JS: %{http_code}, Size: %{size_download} bytes\n" http://localhost:4001/h5/assets/index-CFIPh5xV.js');
|
|
|
|
} catch (error) {
|
|
console.error('部署失败:', error.message);
|
|
} finally {
|
|
conn.end();
|
|
}
|
|
});
|
|
|
|
function executeCommand(cmd) {
|
|
return new Promise((resolve) => {
|
|
conn.exec(cmd, (err, stream) => {
|
|
if (err) {
|
|
console.error('命令执行错误:', err.message);
|
|
resolve();
|
|
return;
|
|
}
|
|
|
|
stream.stdout.on('data', (data) => process.stdout.write(data));
|
|
stream.stderr.on('data', (data) => process.stdout.write(data));
|
|
|
|
stream.on('close', () => resolve());
|
|
});
|
|
});
|
|
}
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |