From 53f54fe05d0e0cdfd8942d0b02a55ad710503629 Mon Sep 17 00:00:00 2001 From: matevip Date: Sat, 25 Apr 2026 10:32:23 +0800 Subject: [PATCH] build(docker): pass MAVEN_FLAGS build-arg to support aliyun-first profile in CN builds --- .env.example | 5 +++++ docker-compose.yml | 2 ++ mateclaw-server/Dockerfile | 25 ++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 9561c692..dbe2a616 100644 --- a/.env.example +++ b/.env.example @@ -49,3 +49,8 @@ SEARXNG_SECRET= MATECLAW_BROWSER_CDP_URL= MATECLAW_BROWSER_CHROME_PATH= MATECLAW_BROWSER_CHANNEL= + +# ── Maven 镜像(国内加速)───────────────────────────────────────── +# 在中国大陆构建时取消注释,将 Aliyun 仓库优先级提前,大幅提速 mvn 拉包。 +# 空值(默认)使用 US Maven Central → Google CDN → Aliyun 的顺序。 +#MAVEN_FLAGS=-Paliyun-first diff --git a/docker-compose.yml b/docker-compose.yml index b9ce2daf..05fea015 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,6 +61,8 @@ services: build: context: . dockerfile: mateclaw-server/Dockerfile + args: + MAVEN_FLAGS: ${MAVEN_FLAGS:-} container_name: mateclaw-server restart: unless-stopped depends_on: diff --git a/mateclaw-server/Dockerfile b/mateclaw-server/Dockerfile index e3220acb..f927d68b 100644 --- a/mateclaw-server/Dockerfile +++ b/mateclaw-server/Dockerfile @@ -21,6 +21,11 @@ RUN pnpm exec vite build --outDir /static --emptyOutDir # Stage 2 — Backend (Maven) FROM maven:3.9-eclipse-temurin-21 AS builder +# Optional Maven extra flags passed at build time. +# Set MAVEN_FLAGS=-Paliyun-first in .env (or via --build-arg) to put Aliyun +# repos first — speeds up builds dramatically inside mainland China. +ARG MAVEN_FLAGS="" + # Inject mirror settings to avoid Maven Central timeouts in restricted networks COPY mateclaw-server/settings.xml /root/.m2/settings.xml @@ -28,18 +33,18 @@ COPY mateclaw-server/settings.xml /root/.m2/settings.xml WORKDIR /plugin-api COPY mateclaw-plugin-api/pom.xml ./pom.xml COPY mateclaw-plugin-api/src ./src -RUN mvn install -DskipTests -q +RUN mvn install -DskipTests -q ${MAVEN_FLAGS} # Pre-fetch mateclaw-server dependencies (uses mirror, so this won't hang) WORKDIR /build COPY mateclaw-server/pom.xml . -RUN mvn dependency:go-offline -q +RUN mvn dependency:go-offline -q ${MAVEN_FLAGS} # Copy backend source and inject pre-built frontend into the right classpath location COPY mateclaw-server/src ./src COPY --from=frontend-builder /static ./src/main/resources/static -RUN mvn package -DskipTests -q +RUN mvn package -DskipTests -q ${MAVEN_FLAGS} # Stage 3 — Runtime # @@ -58,12 +63,26 @@ WORKDIR /app # JDK 21 is NOT part of the base image (it ships Node for the JS driver). # Install openjdk-21 explicitly and add CJK fonts so Chinese pages render # correctly in screenshots and snapshots. +# +# PDF extraction toolchain — DocumentExtractTool tries pdftotext first, then +# Python pdfplumber/pypdf, then falls through to a naive Java parser that +# reads bytes as ISO_8859_1 (mojibake for CJK). Without poppler-utils and +# python3, Docker always hits the naive path and feeds garbled text to the +# Wiki pipeline. Installing these puts the Docker runtime on the same +# extraction path as local Mac (brew poppler + pyenv pdfplumber). +# Tesseract + chi-sim is the final OCR fallback for scanned PDFs. RUN apt-get update \ && apt-get install -y --no-install-recommends \ openjdk-21-jre-headless \ fonts-noto-cjk \ fonts-noto-color-emoji \ + poppler-utils \ + python3 \ + python3-pip \ + tesseract-ocr \ + tesseract-ocr-chi-sim \ tzdata \ + && pip3 install --no-cache-dir --break-system-packages pdfplumber pypdf \ && rm -rf /var/lib/apt/lists/* # Tell Playwright Java where Microsoft's image stored the browsers.