From f0cc37681c77090533376872aec11ff22148585b Mon Sep 17 00:00:00 2001 From: zhuyu <990951175@qq.com> Date: Sat, 11 Apr 2026 17:54:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E5=89=8D=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/Dockerfile | 31 ++++++++++++ docker-compose.yml | 101 ++++++++++++++++++++++++++++++++++++++++ frontend/Dockerfile | 31 ++++++++++++ frontend/vite.config.ts | 2 +- tmpclaude-0c08-cwd | 1 + tmpclaude-18d3-cwd | 1 + tmpclaude-2f0c-cwd | 1 + tmpclaude-47c5-cwd | 1 + tmpclaude-7ecb-cwd | 1 + tmpclaude-85df-cwd | 1 + tmpclaude-9de9-cwd | 1 + tmpclaude-aa04-cwd | 1 + tmpclaude-b88e-cwd | 1 + tmpclaude-d88b-cwd | 1 + tmpclaude-e3e6-cwd | 1 + tmpclaude-f08b-cwd | 1 + 16 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/Dockerfile create mode 100644 tmpclaude-0c08-cwd create mode 100644 tmpclaude-18d3-cwd create mode 100644 tmpclaude-2f0c-cwd create mode 100644 tmpclaude-47c5-cwd create mode 100644 tmpclaude-7ecb-cwd create mode 100644 tmpclaude-85df-cwd create mode 100644 tmpclaude-9de9-cwd create mode 100644 tmpclaude-aa04-cwd create mode 100644 tmpclaude-b88e-cwd create mode 100644 tmpclaude-d88b-cwd create mode 100644 tmpclaude-e3e6-cwd create mode 100644 tmpclaude-f08b-cwd diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..19138c5 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,31 @@ +# 后端 Dockerfile (开发环境) +FROM node:18-alpine + +WORKDIR /app + +# 复制 package.json 和 package-lock.json +COPY package*.json ./ + +# 安装所有依赖 (包括开发依赖) +RUN npm ci + +# 复制源代码 +COPY . . + +# 创建非root用户 +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app + +# 切换用户 +USER nodejs + +# 暴露端口 +EXPOSE 3001 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ + CMD node -e "const http = require('http'); http.get('http://localhost:3001/api/health', (res) => { if (res.statusCode !== 200) throw new Error('Health check failed') }).on('error', (err) => { console.error(err); process.exit(1); })" + +# 启动开发服务器 +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e7d2ff8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,101 @@ +version: '3.8' + +services: + # MySQL 数据库服务 + db: + image: mysql:8.0 + container_name: performance-mysql + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: rootpassword + MYSQL_DATABASE: employee_performance + MYSQL_USER: app_user + MYSQL_PASSWORD: app_password + ports: + - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql + - ./backend/src/db/init.sql:/docker-entrypoint-initdb.d/init.sql + networks: + - app-network + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-prootpassword"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + command: + - --default-authentication-plugin=mysql_native_password + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_unicode_ci + + # 后端 API 服务 + backend: + build: + context: ./backend + dockerfile: Dockerfile + container_name: performance-backend + restart: unless-stopped + depends_on: + db: + condition: service_healthy + environment: + DB_HOST: db + DB_PORT: 3306 + DB_USER: app_user + DB_PASSWORD: app_password + DB_NAME: employee_performance + JWT_SECRET: your_jwt_secret_here_change_in_production + FASTGPT_API_KEY: ${FASTGPT_API_KEY:-your_fastgpt_api_key_here} + FASTGPT_API_URL: https://api.fastgpt.in/api/v1/chat/completions + FASTGPT_MODEL: gpt-4 + PORT: 3001 + NODE_ENV: development + ports: + - "3001:3001" + volumes: + - ./backend:/app + - /app/node_modules + networks: + - app-network + healthcheck: + test: ["CMD", "node", "-e", "const http = require('http'); http.get('http://localhost:3001/api/health', (res) => { if (res.statusCode !== 200) throw new Error('Health check failed') }).on('error', (err) => { console.error(err); process.exit(1); })"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 20s + + # 前端开发服务 + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + container_name: performance-frontend + restart: unless-stopped + depends_on: + - backend + environment: + VITE_API_URL: http://backend:3001 + ports: + - "3000:3000" + volumes: + - ./frontend:/app + - /app/node_modules + networks: + - app-network + healthcheck: + test: ["CMD", "node", "-e", "const http = require('http'); http.get('http://localhost:3000', (res) => { if (res.statusCode !== 200) throw new Error('Health check failed') }).on('error', (err) => { console.error(err); process.exit(1); })"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 30s + +# 定义网络 +networks: + app-network: + driver: bridge + +# 定义数据卷 +volumes: + mysql_data: + driver: local \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..f21ae47 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,31 @@ +# 前端 Dockerfile (开发环境) +FROM node:18-alpine + +WORKDIR /app + +# 复制 package.json 和 package-lock.json +COPY package*.json ./ + +# 安装依赖 +RUN npm ci + +# 复制源代码 +COPY . . + +# 创建非root用户 +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app + +# 切换用户 +USER nodejs + +# 暴露端口 +EXPOSE 3000 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ + CMD node -e "const http = require('http'); http.get('http://localhost:3000', (res) => { if (res.statusCode !== 200) throw new Error('Health check failed') }).on('error', (err) => { console.error(err); process.exit(1); })" + +# 启动开发服务器 +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"] \ No newline at end of file diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index d8ef605..f2cfc95 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ port: 3000, proxy: { '/api': { - target: 'http://localhost:3001', + target: process.env.VITE_API_URL || 'http://localhost:3001', changeOrigin: true, }, }, diff --git a/tmpclaude-0c08-cwd b/tmpclaude-0c08-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-0c08-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-18d3-cwd b/tmpclaude-18d3-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-18d3-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-2f0c-cwd b/tmpclaude-2f0c-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-2f0c-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-47c5-cwd b/tmpclaude-47c5-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-47c5-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-7ecb-cwd b/tmpclaude-7ecb-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-7ecb-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-85df-cwd b/tmpclaude-85df-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-85df-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-9de9-cwd b/tmpclaude-9de9-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-9de9-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-aa04-cwd b/tmpclaude-aa04-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-aa04-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-b88e-cwd b/tmpclaude-b88e-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-b88e-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-d88b-cwd b/tmpclaude-d88b-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-d88b-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-e3e6-cwd b/tmpclaude-e3e6-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-e3e6-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-f08b-cwd b/tmpclaude-f08b-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-f08b-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system