Files
maoshen 81632c1b35 docs: 添加项目文档和 AgentSkills
- 添加架构文档 (ARCHITECTURE.md)
- 添加 API 文档 (API.md)
- 添加文档索引 (docs/README.md)
- 添加部署技能 (skills/city-manual-deploy/SKILL.md)
- 添加测试技能 (skills/city-manual-test/SKILL.md)
- 添加内容管理技能 (skills/city-manual-content/SKILL.md)
2026-04-12 13:36:21 +00:00

157 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Skill: city-manual-deploy
## Description
城市手册项目部署技能。用于自动化部署城市手册项目到生产环境。
## Location
`/root/.openclaw/workspace/city-manual/skills/city-manual-deploy/`
## Capabilities
- 检查部署环境
- 配置 Nginx 反向代理
- 启动 Gunicorn 服务
- 数据库迁移
- 静态文件收集
- 服务健康检查
## Usage
当用户提到以下关键词时激活此技能:
- "部署城市手册"
- "deploy city manual"
- "上线项目"
- "生产环境配置"
## Scripts
### deploy.sh
```bash
#!/bin/bash
# 城市手册部署脚本
set -e
PROJECT_DIR="/root/.openclaw/workspace/city-manual"
VENV_DIR="$PROJECT_DIR/backend/venv"
GUNICORN_SOCKET="$PROJECT_DIR/gunicorn.sock"
GUNICORN_LOG="$PROJECT_DIR/gunicorn.log"
echo "=== 城市手册部署开始 ==="
# 1. 激活虚拟环境
source $VENV_DIR/bin/activate
# 2. 数据库迁移
cd $PROJECT_DIR/backend
python manage.py migrate
# 3. 收集静态文件
python manage.py collectstatic --noinput
# 4. 重启 Gunicorn
pkill -f gunicorn || true
sleep 2
cd $PROJECT_DIR
./gunicorn_start.sh
# 5. 检查服务状态
sleep 3
if pgrep -f gunicorn > /dev/null; then
echo "✅ Gunicorn 启动成功"
else
echo "❌ Gunicorn 启动失败"
exit 1
fi
# 6. Nginx 配置检查
nginx -t
if [ $? -eq 0 ]; then
systemctl reload nginx
echo "✅ Nginx 重载成功"
else
echo "❌ Nginx 配置错误"
exit 1
fi
echo "=== 部署完成 ==="
```
## Configuration
### 环境变量
```bash
# .env 文件
DJANGO_SETTINGS_MODULE=config.settings.production
DJANGO_SECRET_KEY=your-secret-key
DATABASE_URL=postgres://user:pass@localhost:5432/cssc
ALLOWED_HOSTS=cssc.datalibstar.com,127.0.0.1
DEBUG=False
```
### Nginx 配置
```nginx
server {
listen 80;
server_name cssc.datalibstar.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static/ {
alias /root/.openclaw/workspace/city-manual/backend/static/;
}
location /media/ {
alias /root/.openclaw/workspace/city-manual/backend/media/;
}
}
```
## Health Check
```bash
# 检查 Gunicorn
curl http://127.0.0.1:8000/admin/
# 检查数据库
psql -h localhost -U coder -d cssc -c "SELECT 1"
# 检查 Nginx
curl http://cssc.datalibstar.com/
```
## Troubleshooting
### Gunicorn 启动失败
1. 检查端口占用:`lsof -i :8000`
2. 查看日志:`tail -f gunicorn.log`
3. 检查虚拟环境:`source backend/venv/bin/activate`
### 数据库连接失败
1. 检查 PostgreSQL 服务:`systemctl status postgresql`
2. 验证连接:`psql -h localhost -U coder -d cssc`
3. 检查 .env 配置
### 静态文件 404
1. 重新收集:`python manage.py collectstatic --noinput`
2. 检查 Nginx 配置路径
3. 重载 Nginx`systemctl reload nginx`
## References
- [DEPLOYMENT.md](../../DEPLOYMENT.md)
- [scripts/deploy.sh](../../deploy.sh)
- [scripts/gunicorn_start.sh](../../gunicorn_start.sh)