Files
quick-share/docker/Dockerfile

58 lines
2.1 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.
# ========== 阶段一:构建前端 dist ==========
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
# 配置 npm 使用淘宝镜像源
RUN npm config set registry https://registry.npmmirror.com
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci --ignore-scripts || npm install --legacy-peer-deps
COPY frontend/ ./
RUN npm run build
# ========== 阶段二:构建后端 JAR含 dist 到 static ==========
FROM eclipse-temurin:17-jdk-alpine AS backend-builder
WORKDIR /app
# 安装 Maven
RUN apk add --no-cache maven
# 配置 Maven 使用阿里云镜像源
RUN mkdir -p /root/.m2 && \
echo '<?xml version="1.0" encoding="UTF-8"?>' > /root/.m2/settings.xml && \
echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"' >> /root/.m2/settings.xml && \
echo ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' >> /root/.m2/settings.xml && \
echo ' xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">' >> /root/.m2/settings.xml && \
echo ' <mirrors>' >> /root/.m2/settings.xml && \
echo ' <mirror>' >> /root/.m2/settings.xml && \
echo ' <id>aliyunmaven</id>' >> /root/.m2/settings.xml && \
echo ' <mirrorOf>*</mirrorOf>' >> /root/.m2/settings.xml && \
echo ' <name>阿里云公共仓库</name>' >> /root/.m2/settings.xml && \
echo ' <url>https://maven.aliyun.com/repository/public</url>' >> /root/.m2/settings.xml && \
echo ' </mirror>' >> /root/.m2/settings.xml && \
echo ' </mirrors>' >> /root/.m2/settings.xml && \
echo '</settings>' >> /root/.m2/settings.xml
COPY backend/ ./backend/
COPY --from=frontend-builder /app/frontend/dist ./backend/src/main/resources/static
WORKDIR /app/backend
RUN mvn package -DskipTests -q -B
# ========== 阶段三:运行 ==========
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
# 上传目录与数据持久化
RUN mkdir -p /app/data/uploads
COPY --from=backend-builder /app/backend/target/datatool-backend-*.jar ./app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]