query-database/deploy/AUTODEPLOY-UBUNTU-TENCENT.md
query-database 6208da9725 feat:更新
2026-03-27 15:52:00 +08:00

70 lines
2.5 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.

# Ubuntu + Docker Compose腾讯云自动化发布方案
本项目已经支持“前端+后端+MySQL”同机 Docker Compose 部署:使用 `docker-compose.prod.yml`,对外只暴露 `80` 端口(由 Nginx 托管前端并反向代理 `/api`)。
如果你有多个服务,不想每次 SSH 登录手动执行 `git pull` / `docker compose up`,建议用下面两种自动化方案之一。
## 方案 A推荐Portainer StackGitOps自动更新
特点:不需要额外写 CI适合多服务统一管理支持“轮询仓库”或“Webhook 触发更新”。
### 1) 服务器安装 Portainer一次性
```bash
docker volume create portainer_data
docker run -d \
--name portainer \
--restart=always \
-p 9443:9443 \
-p 9000:9000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:latest
```
访问:`https://<服务器IP>:9443`,首次进入创建管理员账号。
### 2) 在 Portainer 创建 Stack从 Git 拉取)
- Stacks → Add stack
- Build method 选 Git repository
- Repository URL`http://47.95.203.241:3000/ReeseLin/query-database.git`
- Compose path`docker-compose.prod.yml`
- 选择分支:`main`
### 3) 开启自动更新
二选一:
- 轮询更新:开启 “Auto update”设置间隔例如 1-5 分钟)
- Webhook 更新:开启 Webhook复制 URL。以后每次 push 后调用这个 URL即可自动拉取并重启
### 4) 建议的安全组
- 对外开放:`80`、`9443`Portainer 管理台)
- 如果只在内网管理 Portainer建议把 `9443` 限制为你自己的 IP 白名单
## 方案 B更工程化腾讯云 TCR + CI 构建镜像 + 服务器自动 pull
特点:构建在 CI 完成,服务器只负责 pull/重启;可回滚;更适合团队/正式环境。
高层流程:
1. push 到 `main`
2. CI 构建镜像:`web`、`api`
3. push 到腾讯云 TCR
4. 服务器 `docker compose pull && docker compose up -d`
建议:
- `web`/`api` 镜像 tag 用 commit SHA
- 生产 `docker-compose` 改为引用镜像(不再在服务器 build
如果你要走这条路线,我可以把:
- 生产 compose 的“镜像版”文件
- CI 配置(含 TCR 登录/构建/推送/远程重启)
直接补进仓库。
## 方案 C最轻量服务器定时拉取systemd timer
特点:无入站端口,无 CI缺点是“定时检查”不是严格实时。
思路:每 1 分钟执行一次:
`git fetch` → 检测远端是否变化 → 变化则 `docker compose up -d --build`