test
This commit is contained in:
118
Dockerfile
118
Dockerfile
@@ -9,45 +9,109 @@ WORKDIR /build
|
||||
COPY settings.xml /root/.m2/
|
||||
COPY pom.xml .
|
||||
|
||||
# 设置Maven仓库权限
|
||||
RUN mkdir -p /root/.m2/repository && \
|
||||
chown -R root:root /root/.m2
|
||||
# 复制本地JAR文件到Maven仓库
|
||||
RUN mkdir -p /root/.m2/repository
|
||||
|
||||
# 下载依赖(利用Docker缓存层和国内镜像)
|
||||
RUN mvn dependency:go-offline -B -s /root/.m2/settings.xml
|
||||
# 复制本地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
|
||||
|
||||
# 复制源代码
|
||||
COPY src ./src
|
||||
|
||||
# 构建应用(使用国内镜像加速)
|
||||
RUN mvn clean package -DskipTests -B -s /root/.m2/settings.xml
|
||||
# 构建应用
|
||||
RUN mvn clean package -DskipTests -B -s /root/.m2/settings.xml -e
|
||||
|
||||
# 检查构建结果
|
||||
RUN echo "=== 检查构建结果 ===" && \
|
||||
ls -la /build/target/ && \
|
||||
echo "=== 查找所有 JAR 文件 ===" && \
|
||||
find /build/target -name "*.jar" -type f && \
|
||||
echo "=== 复制正确的 JAR 文件 ===" && \
|
||||
cp /build/target/*.jar /build/app.jar && \
|
||||
ls -la /build/app.jar && \
|
||||
echo "JAR 文件大小: $(du -h /build/app.jar | cut -f1)"
|
||||
|
||||
# ===== 运行阶段 =====
|
||||
# 使用OpenJDK 8作为基础镜像
|
||||
FROM openjdk:8-jre-alpine AS runtime
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 设置维护者信息
|
||||
LABEL maintainer="digital-archive-team"
|
||||
|
||||
# 添加Alpine国内镜像源
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||||
sed -i 's/https\:\/\/dl-cdn.alpinelinux.org/https:\/\/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
# 使用阿里云Alpine镜像源
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
# 更新包索引并安装必要的系统依赖和Tesseract OCR
|
||||
RUN apk update && \
|
||||
# 更新包索引并安装基础包(包含字体支持)
|
||||
RUN apk update --no-cache && \
|
||||
apk add --no-cache \
|
||||
tesseract \
|
||||
tesseract-data-chi_sim \
|
||||
tesseract-data-chi_tra \
|
||||
tesseract-data-eng \
|
||||
tesseract-ocr \
|
||||
tini \
|
||||
curl \
|
||||
bash \
|
||||
ca-certificates \
|
||||
curl \
|
||||
bash \
|
||||
tini \
|
||||
fontconfig \
|
||||
ttf-dejavu \
|
||||
ttf-liberation \
|
||||
ttf-droid \
|
||||
ttf-freefont \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# 设置环境变量
|
||||
ENV JAVA_OPTS="-Xmx2g -Xms1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
|
||||
ENV JAVA_OPTS="-Xmx2g -Xms1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Djava.awt.headless=true"
|
||||
ENV SPRING_PROFILES_ACTIVE=prod
|
||||
|
||||
# 创建应用用户和目录
|
||||
@@ -58,6 +122,7 @@ RUN addgroup -g 1001 app \
|
||||
&& 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
|
||||
|
||||
@@ -65,14 +130,17 @@ RUN addgroup -g 1001 app \
|
||||
WORKDIR /app
|
||||
|
||||
# 从构建阶段复制jar文件
|
||||
COPY --from=builder /build/target/point-strategy-*.jar app.jar
|
||||
COPY --from=builder /build/app.jar app.jar
|
||||
|
||||
# 复制配置文件(如果需要覆盖默认配置)
|
||||
# COPY application-prod.yml application-prod.yml
|
||||
# 验证JAR文件是否正确复制
|
||||
RUN ls -la app.jar && echo "JAR 文件大小: $(du -h app.jar | cut -f1)"
|
||||
|
||||
# 切换到非root用户
|
||||
USER app
|
||||
|
||||
# 确保日志目录存在且有正确权限
|
||||
RUN mkdir -p /app/logs
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD curl -f http://localhost:9081/point-strategy/actuator/health || exit 1
|
||||
|
||||
Reference in New Issue
Block a user