这是 `incremental.icu <https://github.com/inrenping/incremental.icu>`前端对应的后端接口。通过 Github Actions 自动部署。
注意:服务器的内存需大于 1GB,否则安装相关依赖不足。
注意
> garth 的可用版本不支持 python 3.14 以上的版本,如果您使用的新版本的 python,请用 uv 管理使用 3.12 版本运行。
apt update
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install gunicorn
# 如果是用 uv 管理
uv pip install -r requirements.txt
uv pip install gunicorn记得配置好环境变量
# uvicorn app.main:app --reload
python -m uvicorn app.main:app
# 如果是用 uv 管理
uv run uvicorn app.main:app --reloadpip freeze > requirements.txtsudo journalctl -u incremental-serve.service -f下载代码,进入目录:
git clone <repository-url> /path/to/directory
手动配置
.env文件。创建并激活虚拟环境:
python3 -m venv venv source venv/bin/activate安装依赖:
pip install --upgrade pip pip install -r requirements.txt
直接运行:
uvicorn app.main:app --host 0.0.0.0 --port 8000
在服务器上生成 SSH 密钥对:
ssh-keygen -t ed25519 -f ~/.ssh/github_actions_deploy -C "github-actions"把公钥添加到服务器域名:
ssh-copy-id -i ~/.ssh/github_actions_deploy.pub root@你的服务器IP
在服务器上 git clone 本项目,并按照直接运行的方式先跑一遍确定可以运行:
git clone <repository-url> /var/www/incremental-serve
cd /var/www/incremental-serve
# 手动配置 .env 文件。
# 安装依赖
pip install -r requirements.txt
# 启动服务
uvicorn app.main:app --host 0.0.0.0 --port 8000创建服务文件:
sudo vi /etc/systemd/system/incremental-serve.service在文件中写入以下配置:
[Unit]
Description=incremental-serve deploy
# 确保在网络就绪后再启动
After=network.target
[Service]
# 运行服务的用户
User=root
# 程序所在的目录
WorkingDirectory=/var/www/incremental-serve
Environment="PYTHONPATH=/var/www/incremental-serve"
# 启动命令(必须使用绝对路径)
ExecStart=/var/www/incremental-serve/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000
# 如果程序崩溃,5秒后自动重启
Restart=always
RestartSec=5
[Install]
# 定义服务在系统运行级别下的启动方式
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl start incremental-serve.service
sudo systemctl status incremental-serve.service