90 lines
2.8 KiB
Plaintext
90 lines
2.8 KiB
Plaintext
# =====================================
|
||
# BUILD STAGE (Temurin JDK + Maven)
|
||
# =====================================
|
||
|
||
FROM eclipse-temurin:21-jdk-jammy AS builder
|
||
|
||
# ===== 使用国内 apt 镜像(阿里云) =====
|
||
RUN sed -i 's@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g' /etc/apt/sources.list && \
|
||
sed -i 's@http://security.ubuntu.com@http://mirrors.aliyun.com@g' /etc/apt/sources.list
|
||
|
||
# 安装构建工具(带自动重试)
|
||
RUN apt-get update -o Acquire::Retries=5 && \
|
||
apt-get install -y --no-install-recommends \
|
||
maven wget unzip curl \
|
||
-o Acquire::Retries=5 && \
|
||
rm -rf /var/lib/apt/lists/*
|
||
|
||
# ===== Maven 使用阿里云镜像 =====
|
||
RUN mkdir -p /root/.m2 && \
|
||
cat > /root/.m2/settings.xml << 'EOF'
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
|
||
http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||
<mirrors>
|
||
<mirror>
|
||
<id>aliyun-maven</id>
|
||
<mirrorOf>central</mirrorOf>
|
||
<name>Aliyun Maven</name>
|
||
<url>https://maven.aliyun.com/repository/public</url>
|
||
</mirror>
|
||
</mirrors>
|
||
</settings>
|
||
EOF
|
||
|
||
WORKDIR /build
|
||
|
||
# 复制项目源代码
|
||
COPY ./src ./src
|
||
COPY ./db ./db
|
||
COPY pom.xml ./
|
||
|
||
# 构建 jar 包
|
||
RUN mvn -Dmaven.repo.local=/root/.m2/repository package -DskipTests
|
||
|
||
# 提取版本号
|
||
RUN APP_VERSION=$(grep -A1 "<artifactId>xiaozhi.server</artifactId>" pom.xml | grep "<version>" | sed -e 's/<version>//' -e 's/<\/version>//' -e 's/[[:space:]]//g') && \
|
||
echo "APP_VERSION=${APP_VERSION}" > /build/app_version.env
|
||
|
||
RUN mkdir -p /build/models
|
||
COPY ./models/silero_vad.onnx /build/models/
|
||
|
||
|
||
|
||
# =====================================
|
||
# RUNTIME STAGE (Temurin JRE)
|
||
# =====================================
|
||
|
||
FROM eclipse-temurin:21-jre-jammy
|
||
|
||
# ===== 使用国内 apt 源(阿里云) =====
|
||
RUN sed -i 's@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g' /etc/apt/sources.list && \
|
||
sed -i 's@http://security.ubuntu.com@http://mirrors.aliyun.com@g' /etc/apt/sources.list
|
||
|
||
# 安装 ffmpeg(带自动重试)
|
||
RUN apt-get update -o Acquire::Retries=5 && \
|
||
apt-get install -y --no-install-recommends \
|
||
ffmpeg \
|
||
-o Acquire::Retries=5 && \
|
||
rm -rf /var/lib/apt/lists/*
|
||
|
||
WORKDIR /app
|
||
|
||
# 复制运行文件
|
||
COPY --from=builder /build/target/xiaozhi.server-*.jar /app/
|
||
COPY --from=builder /build/app_version.env /app/
|
||
COPY --from=builder /build/models /app/models
|
||
|
||
# 启动脚本
|
||
RUN echo '#!/bin/bash\n\
|
||
if [ -f /app/app_version.env ]; then\n\
|
||
. /app/app_version.env\n\
|
||
fi\n\
|
||
echo "Starting Xiaozhi server version: ${APP_VERSION}"\n\
|
||
java -Xms512m -Xmx1024m -jar /app/xiaozhi.server-${APP_VERSION}.jar\n\
|
||
' > /app/start.sh && chmod +x /app/start.sh
|
||
|
||
CMD ["/bin/bash", "/app/start.sh"]
|