Skip to content

Commit cb10064

Browse files
FjHehfjVLSMB
authored
Feature: add Docker support (#116)
* feat: add Docker support * feat: add Docker environment config example * fix(docker): unblock containerized deploy (fat-jar deps, healthcheck, SSE proxy) * fix(docker): unblock frontend build — exclude host node_modules, pin pnpm 11, remove dead ignore files --------- Co-authored-by: hfj <hfj@qq.com> Co-authored-by: VLSMB <vlsmb@foxmail.com>
1 parent 9882302 commit cb10064

9 files changed

Lines changed: 415 additions & 7 deletions

File tree

‎.dockerignore‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Dependencies
2+
**/node_modules/
3+
.pnpm-store/
4+
5+
# Build output
6+
**/dist/
7+
build/
8+
**/target/
9+
10+
# IDE files
11+
.idea/
12+
.vscode/
13+
*.swp
14+
*.swo
15+
16+
# OS files
17+
.DS_Store
18+
Thumbs.db
19+
20+
# Logs
21+
*.log
22+
npm-debug.log*
23+
pnpm-debug.log*
24+
25+
# Git files
26+
.git/
27+
.gitignore
28+
29+
# Docker files (避免递归,但保留需要的配置文件)
30+
docker/backend/
31+
docker/frontend/Dockerfile
32+
docker/.env
33+
docker/.env.example
34+
docker/docker-compose.yml
35+
docker/docker-*.sh
36+
docker/docker-*.bat
37+
38+
# Test files
39+
coverage/
40+
.nyc_output/
41+
.playwright-cli/
42+
43+
# Documentation
44+
*.md
45+
docs/
46+
47+
# Root config files (不需要复制到镜像)
48+
.env
49+
.gitattributes
50+
.github/
51+
AGENTS.md
52+
LICENSE
53+
54+
# SQL files (通过 volume 挂载,不需要复制)
55+
sql/

‎data-agent-backend/pom.xml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
<artifactId>spring-boot-starter-web</artifactId>
8585
</dependency>
8686

87+
<dependency>
88+
<groupId>org.springframework.boot</groupId>
89+
<artifactId>spring-boot-starter-actuator</artifactId>
90+
</dependency>
91+
8792
<dependency>
8893
<groupId>org.springframework.boot</groupId>
8994
<artifactId>spring-boot-starter-validation</artifactId>
@@ -123,7 +128,6 @@
123128
<groupId>io.agentscope</groupId>
124129
<artifactId>agentscope-extensions-nacos-skill</artifactId>
125130
<version>${agentscope.version}</version>
126-
<optional>true</optional>
127131
</dependency>
128132

129133
<dependency>

‎data-agent-backend/src/main/resources/application.properties‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ server.port=8080
22

33
spring.application.name=data-agent-management
44

5+
management.endpoints.web.exposure.include=health
6+
57
# Database Configuration
68
spring.datasource.url=${DB_URL:jdbc:mysql://localhost:3306/data_agent?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true}
79
spring.datasource.username=${DB_USERNAME:root}

‎docker/.env.example‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Data Agent 环境变量配置
2+
# 此文件不应提交到 Git(已在 .gitignore 中)
3+
4+
# AI 模型配置 (必填)
5+
IO_GITHUB_MALONETALK_MODEL_API_KEY=
6+
IO_GITHUB_MALONETALK_MODEL_PROVIDER=openai
7+
IO_GITHUB_MALONETALK_MODEL_NAME=deepseek-v4-flash
8+
IO_GITHUB_MALONETALK_MODEL_BASE_URL=https://api.deepseek.com
9+
IO_GITHUB_MALONETALK_MODEL_THINKING_ENABLED=true
10+
11+
# 数据库配置
12+
DB_PASSWORD=root
13+
14+
# JWT 配置(生产环境必须 >= 32 字节)
15+
JWT_SECRET=
16+
17+
# 管理员配置(首次启动时使用)
18+
ADMIN_INIT_PASSWORD=admin

‎docker/backend/Dockerfile‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Stage 1: Build (使用 maven 镜像,自带 Maven)
2+
FROM maven:3.9-eclipse-temurin-17 AS builder
3+
4+
WORKDIR /app
5+
6+
# Maven 依赖默认直连 Maven Central。国内网络拉取易中断导致构建失败时,
7+
# 取消下面整段注释,改用阿里云镜像源:
8+
# RUN mkdir -p /root/.m2 && echo '<settings>\
9+
# <mirrors>\
10+
# <mirror>\
11+
# <id>aliyun</id>\
12+
# <url>https://maven.aliyun.com/repository/public</url>\
13+
# <mirrorOf>*</mirrorOf>\
14+
# </mirror>\
15+
# </mirrors>\
16+
# </settings>' > /root/.m2/settings.xml
17+
18+
# Copy pom.xml and download dependencies
19+
COPY data-agent-backend/pom.xml .
20+
RUN mvn dependency:go-offline -B
21+
22+
# Copy source code and build
23+
COPY data-agent-backend/src ./src
24+
RUN mvn clean package -DskipTests -B
25+
26+
# Stage 2: Runtime
27+
FROM eclipse-temurin:17-jre-alpine
28+
29+
WORKDIR /app
30+
31+
# Skills 目录(skill.properties 的 filesystem 源)
32+
COPY skills/ /app/skills/
33+
34+
# Add non-root user
35+
RUN addgroup -g 1001 appgroup && \
36+
adduser -u 1001 -G appgroup -D appuser
37+
38+
# Copy the built jar
39+
COPY --from=builder /app/target/*.jar app.jar
40+
41+
# Create log directory
42+
RUN mkdir -p /app/logs && chown -R appuser:appgroup /app
43+
44+
USER appuser
45+
46+
# Health check
47+
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
48+
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
49+
50+
ENTRYPOINT ["java", "-jar", "app.jar"]

‎docker/docker-compose.yml‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Data Agent Docker Compose Configuration
2+
#
3+
# 所有配置项都有合理的默认值,可以直接启动。
4+
# 如需自定义配置:cp .env.example .env,然后编辑 .env。
5+
#
6+
7+
services:
8+
# MySQL Database
9+
mysql:
10+
image: mysql:8.0
11+
container_name: data-agent-mysql
12+
restart: unless-stopped
13+
environment:
14+
# 可通过 .env.example 覆盖:DB_PASSWORD=xxx
15+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
16+
MYSQL_DATABASE: data_agent
17+
MYSQL_CHARACTER_SET_SERVER: utf8mb4
18+
MYSQL_COLLATION_SERVER: utf8mb4_unicode_ci
19+
TZ: Asia/Shanghai
20+
ports:
21+
# 可通过 .env.example 覆盖:MYSQL_PORT=3307
22+
- "${MYSQL_PORT:-3306}:3306"
23+
volumes:
24+
- data-agent-mysql:/var/lib/mysql
25+
# 自动挂载项目根目录的 sql/ 文件夹进行初始化
26+
- ../sql:/docker-entrypoint-initdb.d:ro
27+
command:
28+
- --character-set-server=utf8mb4
29+
- --collation-server=utf8mb4_unicode_ci
30+
- --character-set-client-handshake=FALSE
31+
- --init-connect='SET NAMES utf8mb4'
32+
- --default-authentication-plugin=mysql_native_password
33+
networks:
34+
- data-agent-network
35+
healthcheck:
36+
# 使用 mysql 命令实际测试数据库连接和查询
37+
test: ["CMD", "mysql", "-h", "localhost", "-u", "root", "-p${DB_PASSWORD:-root}", "-e", "SELECT 1 FROM data_agent.sys_user LIMIT 1;"]
38+
interval: 10s
39+
timeout: 10s
40+
retries: 10
41+
start_period: 60s
42+
43+
# Backend Service (Spring Boot)
44+
backend:
45+
build:
46+
context: ..
47+
dockerfile: docker/backend/Dockerfile
48+
container_name: data-agent-backend
49+
restart: unless-stopped
50+
environment:
51+
# 数据库配置(通常不需要修改)
52+
DB_URL: ${DB_URL:-jdbc:mysql://mysql:3306/data_agent?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true}
53+
DB_USERNAME: ${DB_USERNAME:-root}
54+
DB_PASSWORD: ${DB_PASSWORD:-root}
55+
56+
# AI 模型配置(重要:需要配置真实的 API Key)
57+
# 可通过 .env.example 覆盖:IO_GITHUB_MALONETALK_MODEL_API_KEY=sk-xxx
58+
IO_GITHUB_MALONETALK_MODEL_PROVIDER: ${IO_GITHUB_MALONETALK_MODEL_PROVIDER:-dashscope}
59+
IO_GITHUB_MALONETALK_MODEL_NAME: ${IO_GITHUB_MALONETALK_MODEL_NAME:-qwen3-max}
60+
IO_GITHUB_MALONETALK_MODEL_BASE_URL: ${IO_GITHUB_MALONETALK_MODEL_BASE_URL:-}
61+
IO_GITHUB_MALONETALK_MODEL_API_KEY: ${IO_GITHUB_MALONETALK_MODEL_API_KEY:-}
62+
IO_GITHUB_MALONETALK_MODEL_THINKING_ENABLED: ${IO_GITHUB_MALONETALK_MODEL_THINKING_ENABLED:-false}
63+
64+
# JWT 配置(可通过 .env.example 覆盖)
65+
# JWT_SECRET 必须 >= 32 字节
66+
JWT_SECRET: ${JWT_SECRET:-}
67+
JWT_EXPIRATION_HOURS: ${JWT_EXPIRATION_HOURS:-24}
68+
69+
# 初始管理员密码(首次启动时使用)
70+
ADMIN_INIT_PASSWORD: ${ADMIN_INIT_PASSWORD:-admin}
71+
72+
TZ: Asia/Shanghai
73+
ports:
74+
# 可通过 .env.example 覆盖:BACKEND_PORT=8081
75+
- "${BACKEND_PORT:-8080}:8080"
76+
depends_on:
77+
mysql:
78+
condition: service_healthy
79+
networks:
80+
- data-agent-network
81+
82+
# Frontend Service (Vue + Nginx)
83+
frontend:
84+
build:
85+
context: ..
86+
dockerfile: docker/frontend/Dockerfile
87+
container_name: data-agent-frontend
88+
restart: unless-stopped
89+
ports:
90+
# 可通过 .env.example 覆盖:FRONTEND_PORT=3001
91+
- "${FRONTEND_PORT:-3000}:80"
92+
depends_on:
93+
backend:
94+
condition: service_healthy
95+
networks:
96+
- data-agent-network
97+
98+
volumes:
99+
data-agent-mysql:
100+
name: data-agent-mysql
101+
102+
networks:
103+
data-agent-network:
104+
name: data-agent-network

‎docker/frontend/Dockerfile‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Stage 1: Build
2+
FROM node:22-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# 直接安装 pnpm(不使用 corepack;项目 pnpm-workspace.yaml 用了 allowBuilds,需 pnpm 11)
7+
RUN npm install -g pnpm@11.24.0
8+
9+
# 先复制所有源代码(.dockerignore 会排除不需要的文件)
10+
COPY data-agent-frontend/ .
11+
12+
# 再安装依赖
13+
RUN pnpm install --frozen-lockfile
14+
15+
# Build the application (跳过类型检查,直接打包)
16+
RUN pnpm vite build
17+
18+
# Stage 2: Production with Nginx
19+
FROM nginx:alpine
20+
21+
# Copy custom nginx config
22+
COPY docker/frontend/nginx.conf /etc/nginx/nginx.conf
23+
24+
# Copy built files
25+
COPY --from=builder /app/dist /usr/share/nginx/html
26+
27+
# Add healthcheck
28+
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
29+
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1/health || exit 1
30+
31+
CMD ["nginx", "-g", "daemon off;"]

‎docker/frontend/nginx.conf‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
include /etc/nginx/mime.types;
7+
default_type application/octet-stream;
8+
9+
# Logging
10+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
11+
'$status $body_bytes_sent "$http_referer" '
12+
'"$http_user_agent" "$http_x_forwarded_for"';
13+
14+
access_log /var/log/nginx/access.log main;
15+
error_log /var/log/nginx/error.log warn;
16+
17+
# Gzip compression
18+
gzip on;
19+
gzip_vary on;
20+
gzip_min_length 1024;
21+
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss image/svg+xml;
22+
23+
# Docker DNS resolver
24+
resolver 127.0.0.11 valid=10s;
25+
26+
server {
27+
listen 80;
28+
listen [::]:80;
29+
server_name localhost;
30+
root /usr/share/nginx/html;
31+
index index.html;
32+
33+
# Security headers
34+
add_header X-Frame-Options "SAMEORIGIN" always;
35+
add_header X-Content-Type-Options "nosniff" always;
36+
add_header X-XSS-Protection "1; mode=block" always;
37+
38+
# Vue Router history mode support
39+
location / {
40+
try_files $uri $uri/ /index.html;
41+
}
42+
43+
location = /index.html {
44+
add_header Cache-Control "no-cache";
45+
}
46+
47+
# API proxy to backend
48+
location ^~ /api/ {
49+
set $backend_upstream http://backend:8080;
50+
proxy_pass $backend_upstream;
51+
proxy_http_version 1.1;
52+
proxy_set_header Connection "";
53+
proxy_buffering off;
54+
proxy_read_timeout 600s;
55+
proxy_set_header Host $host;
56+
proxy_set_header X-Real-IP $remote_addr;
57+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
58+
proxy_set_header X-Forwarded-Proto $scheme;
59+
proxy_connect_timeout 60s;
60+
proxy_send_timeout 60s;
61+
}
62+
63+
# Cache static assets
64+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
65+
expires 1y;
66+
add_header Cache-Control "public, immutable";
67+
}
68+
69+
# Health check endpoint
70+
location /health {
71+
access_log off;
72+
return 200 "healthy\n";
73+
add_header Content-Type text/plain;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)