chore: 更新项目配置文件

- 更新 Docker 配置和构建脚本
- 优化项目文档和部署脚本

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shaw
2025-08-04 10:32:22 +08:00
parent 2ceac331dd
commit 52718ef608
5 changed files with 54 additions and 63 deletions

View File

@@ -55,12 +55,15 @@ coverage/
.nyc_output/
# Build files
dist/
# dist/ # 前端构建阶段需要复制源文件,所以不能忽略
build/
*.pid
*.seed
*.pid.lock
# 但可以忽略本地已构建的 dist 目录
web/admin-spa/dist/
# CI/CD
.travis.yml
.gitlab-ci.yml

View File

@@ -103,52 +103,7 @@ jobs:
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Check if frontend build is needed
id: check_frontend
if: steps.check.outputs.needs_bump == 'true'
run: |
# 检查 web/admin-spa 目录是否有变更
FRONTEND_CHANGES=false
CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD 2>/dev/null || git diff --name-only $(git rev-list --max-parents=0 HEAD)..HEAD)
while IFS= read -r file; do
if [[ "$file" =~ ^web/admin-spa/ ]] &&
[[ ! "$file" =~ ^web/admin-spa/dist/ ]] &&
[[ ! "$file" =~ \.(md|txt)$ ]] &&
[[ "$file" != "web/admin-spa/.gitignore" ]]; then
echo "Found frontend change in: $file"
FRONTEND_CHANGES=true
break
fi
done <<< "$CHANGED_FILES"
echo "needs_build=$FRONTEND_CHANGES" >> $GITHUB_OUTPUT
- name: Setup Node.js
if: steps.check.outputs.needs_bump == 'true' && steps.check_frontend.outputs.needs_build == 'true'
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: web/admin-spa/package-lock.json
- name: Build admin-spa
if: steps.check.outputs.needs_bump == 'true' && steps.check_frontend.outputs.needs_build == 'true'
run: |
echo "Building admin-spa frontend..."
cd web/admin-spa
npm ci
npm run build
cd ../..
# 确认 dist 目录已创建
if [ -d "web/admin-spa/dist" ]; then
echo "✅ Frontend build successful"
ls -la web/admin-spa/dist/
else
echo "❌ Frontend build failed - dist directory not found"
exit 1
fi
# 前端构建已移至 Docker 构建流程中
- name: Update VERSION file
if: steps.check.outputs.needs_bump == 'true'
@@ -159,19 +114,9 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 检查是否需要添加 dist 目录
if [ "${{ steps.check_frontend.outputs.needs_build }}" = "true" ] && [ -d "web/admin-spa/dist" ]; then
git add -f web/admin-spa/dist/
echo "Added frontend dist directory to commit"
fi
# 提交VERSION文件和可能的dist目录 - 添加 [skip ci] 以避免再次触发
# 提交VERSION文件 - 添加 [skip ci] 以避免再次触发
git add VERSION
if [ "${{ steps.check_frontend.outputs.needs_build }}" = "true" ]; then
git commit -m "chore: sync VERSION file with release ${{ steps.next_version.outputs.new_tag }} and rebuild frontend [skip ci]"
else
git commit -m "chore: sync VERSION file with release ${{ steps.next_version.outputs.new_tag }} [skip ci]"
fi
- name: Install git-cliff
if: steps.check.outputs.needs_bump == 'true'

View File

@@ -1,4 +1,22 @@
# 🐳 使用官方 Node.js 18 Alpine 镜像
# 🎯 前端构建阶段
FROM node:18-alpine AS frontend-builder
# 📁 设置工作目录
WORKDIR /app/web/admin-spa
# 📦 复制前端依赖文件
COPY web/admin-spa/package*.json ./
# 🔽 安装前端依赖
RUN npm ci
# 📋 复制前端源代码
COPY web/admin-spa/ ./
# 🏗️ 构建前端
RUN npm run build
# 🐳 主应用阶段
FROM node:18-alpine
# 📋 设置标签
@@ -26,6 +44,9 @@ RUN npm ci --only=production && \
# 📋 复制应用代码
COPY . .
# 📦 从构建阶段复制前端产物
COPY --from=frontend-builder /app/web/admin-spa/dist /app/web/admin-spa/dist
# 🔧 复制并设置启动脚本权限
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

View File

@@ -269,7 +269,17 @@ module.exports = {
}
```
### 第四步:启动服务
### 第四步:安装前端依赖并构建
```bash
# 安装前端依赖
npm run install:web
# 构建前端(生成 dist 目录)
npm run build:web
```
### 第五步:启动服务
```bash
# 初始化
@@ -526,10 +536,14 @@ git add package-lock.json
# 3. 安装新的依赖(如果有)
npm install
# 4. 重启服务
# 4. 安装并构建前端
npm run install:web
npm run build:web
# 5. 重启服务
npm run service:restart:daemon
# 5. 检查服务状态
# 6. 检查服务状态
npm run service:status
```

View File

@@ -458,6 +458,10 @@ EOF
print_info "安装Web界面依赖..."
npm run install:web
# 构建前端
print_info "构建前端界面..."
npm run build:web
# 创建systemd服务文件Linux
if [[ "$OS" == "debian" || "$OS" == "redhat" || "$OS" == "arch" ]]; then
create_systemd_service
@@ -547,6 +551,10 @@ update_service() {
npm install
npm run install:web
# 构建前端
print_info "构建前端界面..."
npm run build:web
# 启动服务
start_service