feat(deploy): doc79 同机部署 lunar.neatcn.com 配置入库
- 新增 nginx 反代配置(HTTPS + 本机 8080,含 1Panel 建站替代说明) - 新增 docker-compose.yml(端口仅绑定 127.0.0.1,env_file 注入生产变量) - PULL_DEPLOY.md 重写为完整一次性安装指南:域名/证书/微信合法域名/ 生产环境变量模板/容器/脚本/timer/验证清单 - AUTO_DEPLOY_1PANEL.md 标记废弃(SSH 手工方式违反安全红线)
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
# lunar-server 容器编排(doc79 同机部署)
|
||||||
|
# 用法:保存到 /opt/lunar/docker-compose.yml,先创建 /opt/lunar/production/.env
|
||||||
|
# (包含全部生产环境变量,见 PULL_DEPLOY.md),然后:
|
||||||
|
# docker compose up -d
|
||||||
|
# 之后 CI 产物由 deploy-watch.sh 自动替换 /opt/lunar/production/current 并重启容器。
|
||||||
|
|
||||||
|
services:
|
||||||
|
lunar-server:
|
||||||
|
image: golang:1.22-bookworm
|
||||||
|
container_name: lunar-server
|
||||||
|
working_dir: /app
|
||||||
|
volumes:
|
||||||
|
- /opt/lunar/production/current:/app
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080" # 只监听本机,对外由 nginx 反代 lunar.neatcn.com
|
||||||
|
env_file:
|
||||||
|
- /opt/lunar/production/.env
|
||||||
|
restart: unless-stopped
|
||||||
|
command: /app/bin/server
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# lunar.neatcn.com — Nginx 反向代理配置(doc79 同机部署)
|
||||||
|
# 用法二选一:
|
||||||
|
# A. 1Panel(推荐):网站 → 创建网站 → 反向代理,主机域名 lunar.neatcn.com,
|
||||||
|
# 代理地址 http://127.0.0.1:8080,然后申请 Let's Encrypt 证书并开启 HTTPS。
|
||||||
|
# B. 手工:将本文件放入 nginx conf.d,证书路径按实际填写后 reload。
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name lunar.neatcn.com;
|
||||||
|
# HTTPS 就绪后全部跳转
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
http2 on;
|
||||||
|
server_name lunar.neatcn.com;
|
||||||
|
|
||||||
|
# 证书路径按实际申请位置调整(1Panel 站点证书在其站点目录下)
|
||||||
|
ssl_certificate /etc/nginx/ssl/lunar.neatcn.com.pem;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/lunar.neatcn.com.key;
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
|
||||||
|
# 小程序 request / 管理后台均走这里 → 本机 Go 服务
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8080;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
# 1Panel 自动部署配置指南
|
# 1Panel 自动部署配置指南
|
||||||
|
|
||||||
|
> ⚠️ **本文档已废弃**(2026-08-09):文中“SSH 到服务器手工执行”的方式违反安全红线(服务器曾因 AI 工具持有 SSH 密钥被入侵)。
|
||||||
|
> 现行方案请看 [PULL_DEPLOY.md](./PULL_DEPLOY.md):CI 只构建,部署由服务器本地 watcher 自动拉取,任何 AI/CI 不再 SSH。
|
||||||
|
> 本文仅作历史参考,禁止按其中步骤操作。
|
||||||
|
|
||||||
本文档说明如何配置 1Panel 实现后端服务的全自动部署。
|
本文档说明如何配置 1Panel 实现后端服务的全自动部署。
|
||||||
|
|
||||||
## 架构说明
|
## 架构说明
|
||||||
|
|||||||
+58
-24
@@ -1,27 +1,72 @@
|
|||||||
# 拉取式部署配置(一次性)
|
# doc79 同机拉取式部署配置(一次性)
|
||||||
|
|
||||||
> 安全原则:CI 只构建、不部署;任何 AI 与流水线都不允许 SSH 到服务器执行命令。
|
> 安全原则:CI 只构建、不部署;任何 AI 与流水线都不允许 SSH 到服务器执行命令。
|
||||||
> 部署由服务器本地的 watcher 监听 CI 产物目录自动完成。本文档的所有命令由**管理员本人**在服务器上执行一次。
|
> 部署由服务器本地的 watcher 监听 CI 产物目录自动完成。本文档的所有命令由**管理员本人**在 doc79 上执行一次。
|
||||||
|
|
||||||
## 工作原理
|
## 架构
|
||||||
|
|
||||||
```
|
```
|
||||||
push main → Gitea Actions 构建 → 产物写入 /ci-artifacts(runner 与宿主同机)
|
push main → Gitea Actions 构建(runner 与 doc79 同机)→ 产物写入 /ci-artifacts
|
||||||
↓
|
↓
|
||||||
服务器本地 systemd timer 每分钟运行 deploy-watch.sh → 发现新 sha256 → 执行 deploy.sh
|
systemd timer 每分钟运行 deploy-watch.sh → 发现新 sha256 → deploy.sh 原子切换 + 重启容器 + 健康检查
|
||||||
↓
|
↓
|
||||||
目录级原子切换 → docker restart → HTTP 健康检查 → 失败自动回滚
|
nginx (lunar.neatcn.com, HTTPS) → 127.0.0.1:8080 lunar-server 容器
|
||||||
```
|
```
|
||||||
|
|
||||||
## 一次性安装(管理员手工执行)
|
## 一次性安装步骤
|
||||||
|
|
||||||
|
### 1. 域名与 HTTPS(lunar.neatcn.com)
|
||||||
|
|
||||||
|
- DNS:将 `lunar.neatcn.com` A 记录指向 doc79 公网 IP;
|
||||||
|
- 站点:1Panel → 网站 → 创建反向代理网站,域名 `lunar.neatcn.com` → `http://127.0.0.1:8080`,
|
||||||
|
申请 Let's Encrypt 证书并开启 HTTPS(参考 `.gitea/deploy/nginx-lunar.neatcn.com.conf`);
|
||||||
|
- 微信公众平台 → 开发管理 → 服务器域名:将 `https://lunar.neatcn.com` 加入 request 合法域名。
|
||||||
|
|
||||||
|
### 2. 生产环境变量(切勿写入仓库)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1. 放置脚本
|
sudo mkdir -p /opt/lunar/production /opt/lunar/backups /opt/lunar/scripts
|
||||||
sudo mkdir -p /opt/lunar/scripts
|
sudo tee /opt/lunar/production/.env > /dev/null <<'EOF'
|
||||||
sudo cp deploy.sh deploy-watch.sh /opt/lunar/scripts/ # 从仓库 .gitea/scripts/ 复制
|
SERVER_ENV=production
|
||||||
sudo chmod +x /opt/lunar/scripts/*.sh
|
SERVER_PORT=8080
|
||||||
|
DB_HOST=<数据库地址>
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USER=<用户名>
|
||||||
|
DB_PASSWORD=<密码>
|
||||||
|
DB_NAME=lunar
|
||||||
|
JWT_SECRET=<强随机值,至少32位>
|
||||||
|
MINI_APP_ID=<小程序AppID>
|
||||||
|
MINI_APP_SECRET=<小程序AppSecret>
|
||||||
|
WECHAT_PAY_APIKEY=<支付API密钥>
|
||||||
|
WECHAT_PAY_MCHID=<商户号>
|
||||||
|
ADMIN_PASSWORD=<后台登录密码>
|
||||||
|
CORS_ORIGINS=https://lunar.neatcn.com
|
||||||
|
EOF
|
||||||
|
sudo chmod 600 /opt/lunar/production/.env
|
||||||
|
```
|
||||||
|
|
||||||
# 2. systemd timer(每分钟轮询)
|
### 3. 启动容器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 从仓库 .gitea/deploy/ 复制 docker-compose.yml
|
||||||
|
sudo cp docker-compose.yml /opt/lunar/docker-compose.yml
|
||||||
|
cd /opt/lunar && sudo docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
(首次启动时 /opt/lunar/production/current 还不存在,容器会重启失败,
|
||||||
|
待第 5 步 watcher 完成首次部署后自动恢复;或先手工 mkdir 空目录。)
|
||||||
|
|
||||||
|
### 4. 安装部署脚本
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 从仓库 .gitea/scripts/ 复制
|
||||||
|
sudo cp deploy.sh deploy-watch.sh /opt/lunar/scripts/
|
||||||
|
sudo chmod +x /opt/lunar/scripts/*.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. systemd timer(每分钟轮询)
|
||||||
|
|
||||||
|
```bash
|
||||||
sudo tee /etc/systemd/system/lunar-deploy-watch.service > /dev/null <<'EOF'
|
sudo tee /etc/systemd/system/lunar-deploy-watch.service > /dev/null <<'EOF'
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Lunar pull-based deploy watcher
|
Description=Lunar pull-based deploy watcher
|
||||||
@@ -49,20 +94,9 @@ sudo systemctl enable --now lunar-deploy-watch.timer
|
|||||||
```bash
|
```bash
|
||||||
systemctl list-timers | grep lunar
|
systemctl list-timers | grep lunar
|
||||||
tail -f /opt/lunar/deploy-watch.log
|
tail -f /opt/lunar/deploy-watch.log
|
||||||
curl -s http://localhost:8080/api/version
|
curl -s https://lunar.neatcn.com/api/version # 应返回版本 JSON
|
||||||
```
|
```
|
||||||
|
|
||||||
## 生产容器必备环境变量
|
|
||||||
|
|
||||||
在 1Panel 容器配置中设置(切勿写入仓库):
|
|
||||||
|
|
||||||
- `DB_HOST` / `DB_PORT` / `DB_USER` / `DB_PASSWORD` / `DB_NAME`
|
|
||||||
- `JWT_SECRET`(必须为强随机值,禁止使用默认值)
|
|
||||||
- `SERVER_ENV=production`
|
|
||||||
- `MINI_APP_ID` / `MINI_APP_SECRET`(微信登录)
|
|
||||||
- `WECHAT_PAY_APIKEY`(支付回调验签,未配置时回调接口直接返回 503)
|
|
||||||
- `ADMIN_PASSWORD`(管理后台登录,未配置时后台登录禁用)
|
|
||||||
|
|
||||||
## 回滚
|
## 回滚
|
||||||
|
|
||||||
deploy.sh 健康检查失败会自动回滚;手工回滚使用 `/opt/lunar/backups/` 下的备份包重新执行 deploy.sh。
|
deploy.sh 健康检查失败会自动回滚;手工回滚使用 `/opt/lunar/backups/` 下的备份包重新执行 deploy.sh。
|
||||||
|
|||||||
Reference in New Issue
Block a user