66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
const dockerCompose = `services:
|
|
backend:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
container_name: huishou-backend
|
|
ports:
|
|
- "4000:4000"
|
|
volumes:
|
|
- ./server/data:/app/server/data
|
|
- ./server/icons:/app/server/icons
|
|
environment:
|
|
- NODE_ENV=production
|
|
- PORT=4000
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD", "node", "-e", "require('http').get('http://localhost:4000/api/prices', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 10s
|
|
|
|
nginx:
|
|
image: nginx:latest
|
|
container_name: huishou
|
|
ports:
|
|
- "4001:80"
|
|
volumes:
|
|
- ./admin:/usr/share/nginx/html/admin
|
|
- ./dist/build/h5:/usr/share/nginx/html/h5
|
|
- ./admin/nginx.conf:/etc/nginx/conf.d/default.conf
|
|
depends_on:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
default:
|
|
driver: bridge
|
|
`;
|
|
|
|
conn.exec(`cat > /www/huishou/docker-compose.yml << 'EOF'\n${dockerCompose}EOF`, (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
stream.on('close', () => {
|
|
conn.exec('cd /www/huishou && docker-compose down && docker-compose up -d', (err2, stream2) => {
|
|
if (err2) { console.log('ERR2:', err2); conn.end(); return; }
|
|
stream2.on('data', (d) => console.log('OUT:', d.toString()));
|
|
stream2.on('close', () => {
|
|
setTimeout(() => {
|
|
conn.exec('curl -s http://localhost:4001/h5/', (err3, stream3) => {
|
|
if (err3) { console.log('ERR3:', err3); conn.end(); return; }
|
|
stream3.on('data', (d) => console.log('H5:', d.toString()));
|
|
stream3.on('close', () => conn.end());
|
|
});
|
|
}, 15000);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' }); |