improve: use alibaba mirror for maven and npmmirror for pnpm

This commit is contained in:
2026-09-21 13:07:50 +08:00
parent a23e2f600a
commit 931d3ee1b7
3 changed files with 80 additions and 7 deletions

View File

@@ -3,12 +3,22 @@
# 构建:docker build -t lab-backend .
# 运行:docker run -p 8080:8080 -e SPRING_PROFILES_ACTIVE=mariadb \
# -e DB_HOST=host.docker.internal -e DB_USER=lab -e DB_PASSWORD=lab123456 lab-backend
#
# 国内加速:构建阶段使用阿里云 Maven 镜像(docker/maven-settings.xml)
# 如需走官方中央仓库:docker build --build-arg MAVEN_MIRROR=false -t lab-backend .
# =====================================================================
# ---------- 构建阶段 ----------
FROM docker.io/library/maven:3.9-eclipse-temurin-21 AS build
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /build
# MAVEN_MIRROR=false 时跳过阿里云镜像配置,使用默认中央仓库
ARG MAVEN_MIRROR=true
COPY docker/maven-settings.xml /tmp/maven-settings.xml
RUN if [ "$MAVEN_MIRROR" = "true" ]; then \
mkdir -p /root/.m2 && cp /tmp/maven-settings.xml /root/.m2/settings.xml; \
fi
# 先只复制 pom,利用 Docker 层缓存预热依赖
COPY pom.xml .
RUN mvn -B -q -Dmaven.test.skip=true dependency:go-offline
@@ -19,7 +29,7 @@ RUN mvn -B -q -Dmaven.test.skip=true package \
&& cp target/*.jar /build/app.jar
# ---------- 运行阶段 ----------
FROM docker.io/library/eclipse-temurin:21-jre
FROM eclipse-temurin:21-jre
WORKDIR /opt/app
# 以非 root 用户运行