- Add four-layer modular structure (domain, application, infrastructure, api) - Implement complete CRUD example with Order entity - Add ArchUnit architecture compliance tests - Add Maven configuration with proper dependency management - Add Dockerfile for containerization - Add Kustomize deployment templates - Add initialization script (init.sh) - Add CI/CD workflow configuration - Add comprehensive documentation and configuration files Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
50 lines
1.2 KiB
Docker
50 lines
1.2 KiB
Docker
# 多阶段构建 Dockerfile
|
|
FROM maven:3.9.6-eclipse-temurin-21 AS builder
|
|
|
|
WORKDIR /app
|
|
COPY pom.xml .
|
|
COPY tmpl-domain/pom.xml ./tmpl-domain/pom.xml
|
|
COPY tmpl-application/pom.xml ./tmpl-application/pom.xml
|
|
COPY tmpl-infrastructure/pom.xml ./tmpl-infrastructure/pom.xml
|
|
COPY tmpl-api/pom.xml ./tmpl-api/pom.xml
|
|
|
|
# 预下载依赖
|
|
RUN mvn dependency:go-offline -B
|
|
|
|
# 复制源代码
|
|
COPY tmpl-domain/src ./tmpl-domain/src
|
|
COPY tmpl-application/src ./tmpl-application/src
|
|
COPY tmpl-infrastructure/src ./tmpl-infrastructure/src
|
|
COPY tmpl-api/src ./tmpl-api/src
|
|
|
|
# 编译打包
|
|
RUN mvn clean package -DskipTests -B
|
|
RUN ls -la tmpl-api/target/
|
|
|
|
# 运行时镜像
|
|
FROM eclipse-temurin:21-jre-alpine
|
|
|
|
LABEL maintainer="Development Team"
|
|
LABEL version="1.0.0"
|
|
LABEL description="Java 21 Service Template - Clean Architecture"
|
|
|
|
WORKDIR /app
|
|
|
|
# 创建非 root 用户
|
|
RUN addgroup -g 1001 -S appgroup && \
|
|
adduser -u 1001 -S appuser -G appgroup
|
|
|
|
# 从构建阶段复制 jar 文件
|
|
COPY --from=builder /app/tmpl-api/target/tmpl-api-*.jar app.jar
|
|
|
|
# 更改文件所有权
|
|
RUN chown appuser:appgroup app.jar
|
|
|
|
# 暴露端口
|
|
EXPOSE 8080
|
|
|
|
# 切换到非 root 用户
|
|
USER appuser
|
|
|
|
# 启动应用
|
|
ENTRYPOINT ["java", "-jar", "app.jar"] |