From db902809895b81c51c061fab6f7f57ed67ed93d9 Mon Sep 17 00:00:00 2001 From: ShiZhui Date: Thu, 11 Jun 2026 17:58:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20CI=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=20workflow=20+=20CMS=20IP=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 25 +++++++++++++++++++++++++ .gitignore | 3 +++ deploy/act_runner-config.yaml | 20 ++++++++++++++++++++ deploy/act_runner.service | 13 +++++++++++++ docs/CMS.md | 29 +++++++++++++++++++++++------ public/admin/config.yml | 11 ++++++----- 6 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 .gitea/workflows/deploy.yml create mode 100644 deploy/act_runner-config.yaml create mode 100644 deploy/act_runner.service diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..50a48e5 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,25 @@ +name: Build and Deploy + +on: + push: + branches: + - main + +jobs: + build-deploy: + runs-on: ubuntu-latest + steps: + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 安装依赖 + run: npm ci + + - name: 构建站点 + run: npm run build + + - name: 发布到 Nginx 目录 + run: | + mkdir -p /var/www/shizhui + rsync -a --delete dist/ /var/www/shizhui/ + echo "已发布到 /var/www/shizhui" diff --git a/.gitignore b/.gitignore index ad7a572..58c48e8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ AccessKey* credentials* # macOS .DS_Store + +# 本地凭据,禁止提交 +CREDENTIALS.txt diff --git a/deploy/act_runner-config.yaml b/deploy/act_runner-config.yaml new file mode 100644 index 0000000..8dea881 --- /dev/null +++ b/deploy/act_runner-config.yaml @@ -0,0 +1,20 @@ +# act_runner 配置(host 模式,2G 内存服务器友好) +log: + level: info + +runner: + capacity: 1 # 同时只跑 1 个任务,省内存 + timeout: 10m + fetch_timeout: 5s + fetch_interval: 2s + +cache: + enabled: true + +container: + # host 模式不使用容器;以下保留默认 + network: "" + privileged: false + +host: + workdir_parent: /var/lib/act_runner/work diff --git a/deploy/act_runner.service b/deploy/act_runner.service new file mode 100644 index 0000000..767b0c6 --- /dev/null +++ b/deploy/act_runner.service @@ -0,0 +1,13 @@ +[Unit] +Description=Gitea Actions Runner +After=network.target gitea.service + +[Service] +ExecStart=/usr/local/bin/act_runner daemon --config /etc/act_runner/config.yaml +WorkingDirectory=/var/lib/act_runner +Environment=HOME=/root +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target diff --git a/docs/CMS.md b/docs/CMS.md index 7965fd3..28f6bc5 100644 --- a/docs/CMS.md +++ b/docs/CMS.md @@ -50,14 +50,31 @@ > 以下涉及服务器操作,按 `.kiro/steering/commands.md` 规则,需用户确认授权后执行。 ### 阶段一:基础设施 -1. 服务器初始化:Nginx、防火墙(见 `docs/DEPLOY.md`)。 -2. 安装 Gitea(二进制或 docker),数据目录规划,配置 `git.shizhui.xyz`。 -3. Nginx 反向代理 Gitea,申请 HTTPS 证书(含 git 子域名)。 -4. 创建管理员账号,建立本项目仓库,推送现有代码。 +1. 服务器初始化:Nginx、防火墙(见 `docs/DEPLOY.md`)。✅ +2. 安装 Gitea(二进制或 docker),数据目录规划,配置 `git.shizhui.xyz`。✅ +3. Nginx 反向代理 Gitea,申请 HTTPS 证书(含 git 子域名)。✅ +4. 创建管理员账号,建立本项目仓库,推送现有代码。✅ -### 阶段二:CI 自动部署 +### 已完成的 Gitea 部署细节 +- 版本:Gitea 1.25.5(二进制,SQLite 数据库,省内存) +- 运行:systemd 服务 `gitea`,监听 127.0.0.1:3000 +- 反代:Nginx → https://git.shizhui.xyz(证书已含该子域名) +- 配置:`/etc/gitea/app.ini`(关闭开放注册、启用 Actions) +- 账号: + - `shizhui`(管理员) + - `developer`(普通用户 / 内容维护者) + - 两账号密码已单独设置,不记录于文档;首次登录后请自行修改。 +- 仓库:`shizhui/shizhui_website`(已推送全部代码) +- 推送方式:因域名未备案,经公网域名会被劫持,推送通过 SSH 端口转发 + (本地 3000 → 服务器 127.0.0.1:3000)完成。 + +### 阶段二:CI 自动部署(进行中) 5. 安装并注册 Gitea Actions Runner。 -6. 编写 workflow:`push` 到主分支 → `npm ci && npm run build` → 发布到 `/var/www/shizhui`。 +6. workflow:push 主分支 → 构建 → 发布到 `/var/www/shizhui`。 + +### 测试访问地址(备案完成前) +- 网站:http://8.137.165.96:8080 +- Gitea:需在本地 hosts 绑定,或经 SSH 隧道访问(域名直连会被劫持) ### 阶段三:接入 CMS 7. 在站点加入 `/admin`(Sveltia CMS 页面 + `config.yml`)。 diff --git a/public/admin/config.yml b/public/admin/config.yml index 1453805..f78266c 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -1,12 +1,13 @@ # Sveltia CMS 配置(兼容 Decap CMS 格式) -# 后端:自托管 Gitea,通过 Gitea OAuth 登录鉴权 +# 后端:自托管 Gitea(IP 访问,备案完成前不走域名),通过 Gitea OAuth 登录鉴权 backend: name: gitea - repo: shizhui/shizhui_website # Gitea 上的 /,部署时按实际创建调整 - base_url: https://git.shizhui.xyz # Gitea 实例地址(OAuth 在此完成) - api_root: https://git.shizhui.xyz/api/v1 + repo: shizhui/shizhui_website # Gitea 上的 / + base_url: http://8.137.165.96:3000 # Gitea 实例地址(OAuth 在此完成) + api_root: http://8.137.165.96:3000/api/v1 branch: main + app_id: "27b5f734-8df0-4a5e-9ea8-e7597dea4f6c" # Gitea OAuth 应用 client_id(公开客户端,PKCE) # 上传媒体(图片等)存放位置 media_folder: "public/uploads" # 文件实际写入仓库的此目录 @@ -17,7 +18,7 @@ public_folder: "/uploads" # 站点引用时的 URL 前缀 local_backend: true # 站点地址(编辑器“在站点查看”跳转用) -site_url: https://shizhui.xyz +site_url: http://8.137.165.96:8080 # 中文界面 locale: zh