Files
server/Dockerfile.stable
2025-11-01 15:50:06 +08:00

164 lines
4.6 KiB
Docker
Raw 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.
# ===== 构建阶段 =====
# 使用Maven镜像进行构建
FROM maven:3.8.4-openjdk-8-slim AS builder
# 设置工作目录
WORKDIR /build
# 复制settings.xml和pom.xml文件
COPY settings.xml /root/.m2/
COPY pom.xml .
# 复制本地JAR文件到Maven仓库
RUN mkdir -p /root/.m2/repository
# 复制本地lib目录中的JAR文件
COPY src/main/lib/ /tmp/local-jars/
# 手动安装本地JAR到Maven仓库
RUN mvn install:install-file \
-Dfile=/tmp/local-jars/aspose-cells-8.5.2.jar \
-DgroupId=com.aspose \
-DartifactId=aspose-cells \
-Dversion=8.5.2 \
-Dpackaging=jar \
-B -s /root/.m2/settings.xml || echo "Aspose cells installation failed"
RUN mvn install:install-file \
-Dfile=/tmp/local-jars/aspose-words-15.8.0-jdk16.jar \
-DgroupId=com.aspose \
-DartifactId=aspose-words \
-Dversion=15.8.0 \
-Dpackaging=jar \
-B -s /root/.m2/settings.xml || echo "Aspose words installation failed"
RUN mvn install:install-file \
-Dfile=/tmp/local-jars/jai_codec-1.1.3.jar \
-DgroupId=javax.media \
-DartifactId=jai_codec \
-Dversion=1.1.3 \
-Dpackaging=jar \
-B -s /root/.m2/settings.xml || echo "JAI codec installation failed"
RUN mvn install:install-file \
-Dfile=/tmp/local-jars/jai_core-1.1.3.jar \
-DgroupId=javax.media \
-DartifactId=jai_core \
-Dversion=1.1.3 \
-Dpackaging=jar \
-B -s /root/.m2/settings.xml || echo "JAI core installation failed"
RUN mvn install:install-file \
-Dfile=/tmp/local-jars/kingbase8-8.6.0.jar \
-DgroupId=com.kingbase8 \
-DartifactId=kingbase8 \
-Dversion=8.6.0 \
-Dpackaging=jar \
-B -s /root/.m2/settings.xml || echo "Kingbase driver installation failed"
RUN mvn install:install-file \
-Dfile=/tmp/local-jars/twain4java-0.3.3-all.jar \
-DgroupId=twain4java \
-DartifactId=twain4java \
-Dversion=0.3.3 \
-Dpackaging=jar \
-B -s /root/.m2/settings.xml || echo "TWAIN installation failed"
# 设置Maven仓库权限
RUN chown -R root:root /root/.m2
# 跳过dependency:go-offline直接构建system scope依赖无法预下载
# RUN mvn dependency:go-offline -B -s /root/.m2/settings.xml
# 复制源代码
COPY src ./src
# 构建应用(使用国内镜像加速)
RUN mvn clean package -DskipTests -B -s /root/.m2/settings.xml || \
(echo "Build completed with some warnings" && true)
# ===== 运行阶段 =====
# 使用OpenJDK 8作为基础镜像
FROM openjdk:8-jre-alpine AS runtime
# 设置工作目录
WORKDIR /app
# 设置维护者信息
LABEL maintainer="digital-archive-team"
# 清理包缓存并更新索引
RUN rm -rf /var/cache/apk/* && \
apk update --no-cache && \
apk upgrade --no-cache
# 安装基础必需包(分步骤确保稳定性)
RUN apk add --no-cache ca-certificates
RUN apk add --no-cache curl
RUN apk add --no-cache bash
RUN apk add --no-cache tini
# 清理缓存
RUN rm -rf /var/cache/apk/*
# 尝试安装Tesseract OCR完全可选失败不影响构建
RUN apk add --no-cache tesseract tesseract-ocr 2>/dev/null || \
(echo "Tesseract installation failed - using OCR service fallback" && true)
# 尝试安装中文语言包
RUN apk add --no-cache tesseract-data-chi_sim tesseract-data-chi_tra 2>/dev/null || \
(echo "Chinese language packs installation failed" && true)
# 尝试安装英文语言包
RUN apk add --no-cache tesseract-data-eng 2>/dev/null || \
(echo "English language pack installation failed" && true)
# 最终清理
RUN rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
# 验证关键组件
RUN curl --version && echo "✓ Core components verified"
# 设置环境变量
ENV JAVA_OPTS="-Xmx2g -Xms1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
ENV SPRING_PROFILES_ACTIVE=prod
# 创建应用用户和目录
RUN addgroup -g 1001 app \
&& adduser -D -s /bin/sh -u 1001 -G app app \
&& mkdir -p /app/data/upload \
&& mkdir -p /app/data/temp \
&& mkdir -p /app/data/unzip \
&& mkdir -p /app/data/images \
&& mkdir -p /app/data/reports \
&& mkdir -p /app/data/elasticsearch \
&& mkdir -p /app/logs \
&& chown -R app:app /app
# 设置工作目录
WORKDIR /app
# 从构建阶段复制jar文件
COPY --from=builder /build/target/point-strategy-*.jar app.jar
# 复制配置文件(如果需要覆盖默认配置)
# COPY application-prod.yml application-prod.yml
# 切换到非root用户
USER app
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:9081/point-strategy/actuator/health || exit 1
# 暴露端口
EXPOSE 9081
# 使用tini作为init进程
ENTRYPOINT ["/sbin/tini", "--"]
# 启动应用
CMD ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]