HostWeaver
远程部署与状态管理工具 - 基于 SSH/SFTP 的自动化部署引擎
Remote deployment and state management tool based on SSH/SFTP.
✨ 功能特性
- 🔐 SSH/SFTP 封装 - 支持密码和私钥认证,连接池管理
- 📦 文件传输 - 可靠的文件上传/下载,自动赋予执行权限(
chmod +x) - ⚙️ Systemd 管理 - 动态生成
.service配置文件,完整生命周期管理(start/stop/restart/status) - 🔑 License 生成 - 基于机器指纹(
/etc/machine-id)的授权密钥生成 - 🚀 一键部署 - 完整的部署工作流,支持进度显示
- 🖥️ 多机并发 - 批量部署支持,失败隔离,汇总报告
- 🎨 优雅 CLI - 基于 typer 和 rich 的终端体验
📦 安装
# 使用 pip 安装
pip install hostweaver
# 使用 uv 安装
uv pip install hostweaver
# 从源码安装(开发模式)
git clone https://github.com/zsuroy/hostweaver.git
cd hostweaver
uv pip install -e ".[dev]"
🚀 快速开始
命令行使用
# 部署单个二进制文件
hostweaver deploy \
--host 192.168.1.100 \
--username root \
--key-file ~/.ssh/id_rsa \
--source ./dist/app \
--install-dir /opt/app \
--service myapp \
--env APP_ENV=production \
--env APP_PORT=8000
# 部署整个项目目录
hostweaver deploy \
--host 192.168.1.100 \
--username root \
--key-file ~/.ssh/id_rsa \
--source ./project \
--entrypoint main.py \
--install-dir /opt/app \
--service myapp
# 查询服务状态
hostweaver status \
--host 192.168.1.100 \
--username root \
--service myapp
# 查看服务日志
hostweaver logs \
--host 192.168.1.100 \
--username root \
--service myapp \
--lines 50
# 重启服务
hostweaver restart \
--host 192.168.1.100 \
--username root \
--service myapp
Python API 使用
单机部署
from hostweaver.business.generic_deployer import GenericDeployer
from hostweaver.workflow.single_deploy import SingleDeployWorkflow
# 创建部署器
deployer = GenericDeployer(
host="192.168.1.100",
username="root",
pkey_path="~/.ssh/id_rsa",
source_path="./dist/app",
install_dir="/opt/app",
service_name="myapp",
env_vars={"APP_ENV": "production"},
secret_key="your-secret-key", # 用于生成 License
)
# 执行部署
workflow = SingleDeployWorkflow(deployer)
result = workflow.execute()
# 检查结果
if result.success:
print(f"部署成功!机器指纹:{result.machine_id}")
else:
print(f"部署失败:{result.message}")
多机并发部署
from hostweaver.business.generic_deployer import GenericDeployer
from hostweaver.concurrent.pool import DeployPool, HostConfig
from hostweaver.concurrent.reporter import DeploymentReporter
# 创建并发池
pool = DeployPool(max_workers=5)
# 添加主机
hosts = [
HostConfig(host="192.168.1.100", username="root"),
HostConfig(host="192.168.1.101", username="root"),
HostConfig(host="192.168.1.102", username="root", env_vars={"NODE_ID": "3"}),
]
for config in hosts:
pool.add_task(
config=config,
deployer_class=GenericDeployer,
source_path="./dist/app",
install_dir="/opt/app",
service_name="myapp",
secret_key="your-secret-key",
)
# 执行部署
results = pool.execute()
# 生成报告
reporter = DeploymentReporter(results)
reporter.print_report(verbose=True)
# 获取汇总
summary = reporter.get_summary()
print(f"成功率:{summary['success_rate']:.1%}")
📖 核心概念
部署流程
HostWeaver 定义了一个标准的部署生命周期:
connect → pre_deploy() → run() → post_deploy() → disconnect
- connect: 建立 SSH 连接,初始化 SFTP 和 Systemd 管理器
- pre_deploy(): 部署前准备(获取机器指纹、停止旧服务、生成 License)
- run(): 执行部署(文件上传、配置渲染、systemd 重载)
- post_deploy(): 部署后处理(启动服务、验证状态、输出日志)
- disconnect: 断开 SSH 连接
📚 更多文档
🤝 贡献
欢迎提交 Issue 和 Pull Request!
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
📄 License
MIT License - 详见 LICENSE 文件
🙏 致谢
感谢以下开源项目:
Metadata
Release files for hostweaver 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hostweaver-0.1.0.tar.gz | 44.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hostweaver-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 79.2 kB
Release files / hostweaver-0.1.0.tar.gz
| Download URL | hostweaver-0.1.0.tar.gz |
|---|---|
| Size | 44.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7fb915e4fd524a1d567503022c9fdf9f3a11823b3ac20c2fc24cd45cfdd7b44c
|
|
BLAKE2b-256 checksum How to use checksums |
7a59e481f0f589101853bdb9f87f32acaeb6ae4e5bee2337cd5506d4f75582cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.
Transparency logRelease files / hostweaver-0.1.0-py3-none-any.whl
| Download URL | hostweaver-0.1.0-py3-none-any.whl |
|---|---|
| Size | 34.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
862af39dd1d0e2f9e76548217101c867d76d22609b1dccdc3ee5b8c9a2d0dfed
|
|
BLAKE2b-256 checksum How to use checksums |
2e36250fce00177431cec1e6db783045e508be95c28ee1f204a6ee63a6b24e8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.
Transparency log