fundplatform/Dockerfile
zhangjf 5b80e237b9 feat: Docker容器化部署和Prometheus+Grafana监控
## Docker 容器化部署

### 新增文件
- Dockerfile: 多阶段构建镜像,支持 Java 21
- docker-compose.yml: 完整服务编排配置
  - 基础设施: MySQL 8.0, Redis 7, Nacos 3.0
  - 监控: Prometheus, Grafana
  - 业务服务: Gateway + 9个微服务
- docker/.env: 环境变量配置
- docker/mysql/init/01-init.sql: 数据库初始化脚本

### Docker 特性
- 多阶段构建优化镜像大小
- 非 root 用户运行服务
- 健康检查配置
- 统一时区设置 (Asia/Shanghai)

## Prometheus + Grafana 监控

### Prometheus 配置
- docker/prometheus/prometheus.yml: 服务发现配置
- docker/prometheus/rules/alerts.yml: 告警规则
  - 服务可用性告警
  - JVM 内存告警
  - HTTP 请求告警
  - 数据库连接池告警
  - 系统资源告警

### Grafana 配置
- docker/grafana/provisioning/: 数据源和Dashboard自动导入
- docker/grafana/dashboards/fund-platform-dashboard.json
  - 服务概览面板
  - JVM 内存监控
  - 数据库连接池监控

### Spring Boot Actuator 集成
- pom.xml: 添加 spring-boot-starter-actuator 和 micrometer-registry-prometheus
- application-docker.yml: Prometheus 端点配置

## 服务端口规划
- Gateway: 8000
- fund-sys: 8100
- fund-cust: 8200
- fund-proj: 8300
- fund-req: 8400
- fund-exp: 8500
- fund-receipt: 8600
- fund-report: 8700
- fund-file: 8800
- Prometheus: 9090
- Grafana: 3000
- Nacos: 8848
2026-02-19 18:48:15 +08:00

81 lines
2.2 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 资金服务平台 - 统一 Dockerfile
# 多阶段构建Maven 构建 + JRE 运行
# ==================== 构建阶段 ====================
FROM maven:3.9-eclipse-temurin-21-alpine AS builder
WORKDIR /build
# 复制 Maven 配置文件(利用缓存加速构建)
COPY pom.xml .
COPY fund-common/pom.xml fund-common/
COPY fund-gateway/pom.xml fund-gateway/
COPY fund-sys/pom.xml fund-sys/
COPY fund-cust/pom.xml fund-cust/
COPY fund-proj/pom.xml fund-proj/
COPY fund-req/pom.xml fund-req/
COPY fund-exp/pom.xml fund-exp/
COPY fund-receipt/pom.xml fund-receipt/
COPY fund-report/pom.xml fund-report/
COPY fund-file/pom.xml fund-file/
# 下载依赖(利用 Docker 缓存)
RUN mvn dependency:go-offline -B || true
# 复制源代码
COPY fund-common/ fund-common/
COPY fund-gateway/ fund-gateway/
COPY fund-sys/ fund-sys/
COPY fund-cust/ fund-cust/
COPY fund-proj/ fund-proj/
COPY fund-req/ fund-req/
COPY fund-exp/ fund-exp/
COPY fund-receipt/ fund-receipt/
COPY fund-report/ fund-report/
COPY fund-file/ fund-file/
# 构建参数:指定要构建的模块
ARG MODULE=fund-sys
RUN mvn clean package -pl ${MODULE} -am -DskipTests -B
# ==================== 运行阶段 ====================
FROM eclipse-temurin:21-jre-alpine
# 安装必要工具
RUN apk add --no-cache curl tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
apk del tzdata
# 创建非 root 用户
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
# 构建参数
ARG MODULE=fund-sys
ARG VERSION=0.0.1-SNAPSHOT
# 从构建阶段复制 JAR 包
COPY --from=builder /build/${MODULE}/target/${MODULE}-${VERSION}.jar app.jar
# 设置权限
RUN chown -R appuser:appgroup /app
# 切换非 root 用户
USER appuser
# JVM 参数
ENV JAVA_OPTS="-Xms256m -Xmx512m -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError"
ENV SPRING_PROFILES_ACTIVE="docker"
# 暴露端口(默认 8080实际端口由服务决定
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:${SERVER_PORT:-8080}/actuator/health || exit 1
# 启动命令
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar"]