fix: 修復 ARM64 上 endesive 編譯問題

- 添加 python3-dev, gcc, libffi-dev 編譯依賴
- 編譯完成後自動移除以減小體積
This commit is contained in:
Your Name 2026-01-24 15:51:13 +08:00
parent 1b8cae30a0
commit 73f2bfd890

View file

@ -45,29 +45,29 @@ WORKDIR /app
# 配置 APT 重試機制(解決 Multi-Arch Build 時的網路不穩定問題) # 配置 APT 重試機制(解決 Multi-Arch Build 時的網路不穩定問題)
RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/80-retries \ RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/80-retries \
&& echo 'Acquire::http::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'Acquire::http::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'Acquire::https::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'Acquire::https::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'Acquire::ftp::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'Acquire::ftp::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'DPkg::Lock::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries && echo 'DPkg::Lock::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries
# install bun # install bun
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
curl \ curl \
unzip \ unzip \
ca-certificates \ ca-certificates \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# if architecture is arm64, use the arm64 version of bun # if architecture is arm64, use the arm64 version of bun
RUN ARCH=$(uname -m) && \ RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \ if [ "$ARCH" = "aarch64" ]; then \
curl -fsSL -o bun-linux-aarch64.zip https://github.com/oven-sh/bun/releases/download/bun-v1.3.6/bun-linux-aarch64.zip; \ curl -fsSL -o bun-linux-aarch64.zip https://github.com/oven-sh/bun/releases/download/bun-v1.3.6/bun-linux-aarch64.zip; \
else \ else \
curl -fsSL -o bun-linux-x64-baseline.zip https://github.com/oven-sh/bun/releases/download/bun-v1.3.6/bun-linux-x64-baseline.zip; \ curl -fsSL -o bun-linux-x64-baseline.zip https://github.com/oven-sh/bun/releases/download/bun-v1.3.6/bun-linux-x64-baseline.zip; \
fi fi
RUN unzip -j bun-linux-*.zip -d /usr/local/bin && \ RUN unzip -j bun-linux-*.zip -d /usr/local/bin && \
rm bun-linux-*.zip && \ rm bun-linux-*.zip && \
chmod +x /usr/local/bin/bun chmod +x /usr/local/bin/bun
# install dependencies into temp directory # install dependencies into temp directory
# this will cache them and speed up future builds # this will cache them and speed up future builds
@ -121,113 +121,113 @@ FROM base AS release
# 配置 APT 重試機制 # 配置 APT 重試機制
RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/80-retries \ RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/80-retries \
&& echo 'Acquire::http::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'Acquire::http::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'Acquire::https::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'Acquire::https::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'Acquire::ftp::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'Acquire::ftp::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'APT::Get::Assume-Yes "true";' >> /etc/apt/apt.conf.d/80-retries \ && echo 'APT::Get::Assume-Yes "true";' >> /etc/apt/apt.conf.d/80-retries \
&& echo 'DPkg::Lock::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries && echo 'DPkg::Lock::Timeout "120";' >> /etc/apt/apt.conf.d/80-retries
# 階段 1基礎系統工具 # 階段 1基礎系統工具
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "📦 階段 1/7安裝基礎系統工具" && \ echo "📦 階段 1/7安裝基礎系統工具" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
locales \ locales \
ca-certificates \ ca-certificates \
curl \ curl \
openssl \ openssl \
&& rm -rf /var/lib/apt/lists/* && \ && rm -rf /var/lib/apt/lists/* && \
echo "✅ 階段 1/7 完成:基礎系統工具已安裝" echo "✅ 階段 1/7 完成:基礎系統工具已安裝"
# 階段 2核心轉換工具 # 階段 2核心轉換工具
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "📦 階段 2/6安裝核心轉換工具" && \ echo "📦 階段 2/6安裝核心轉換工具" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
ghostscript \ ghostscript \
graphicsmagick \ graphicsmagick \
poppler-utils \ poppler-utils \
potrace \ potrace \
qpdf \ qpdf \
&& rm -rf /var/lib/apt/lists/* && \ && rm -rf /var/lib/apt/lists/* && \
echo "✅ 階段 2/6 完成:核心轉換工具已安裝" echo "✅ 階段 2/6 完成:核心轉換工具已安裝"
# 階段 2.1:安裝 dasel從 GitHub 下載二進位檔案) # 階段 2.1:安裝 dasel從 GitHub 下載二進位檔案)
RUN echo "" && \ RUN echo "" && \
echo " 🔧 階段 2.1:安裝 dasel..." && \ echo " 🔧 階段 2.1:安裝 dasel..." && \
ARCH=$(uname -m) && \ ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \ if [ "$ARCH" = "aarch64" ]; then \
DASEL_ARCH="linux_arm64"; \ DASEL_ARCH="linux_arm64"; \
else \ else \
DASEL_ARCH="linux_amd64"; \ DASEL_ARCH="linux_amd64"; \
fi && \ fi && \
curl -sSLf "https://github.com/TomWright/dasel/releases/download/v2.8.1/dasel_${DASEL_ARCH}" -o /usr/local/bin/dasel && \ curl -sSLf "https://github.com/TomWright/dasel/releases/download/v2.8.1/dasel_${DASEL_ARCH}" -o /usr/local/bin/dasel && \
chmod +x /usr/local/bin/dasel && \ chmod +x /usr/local/bin/dasel && \
echo " ✅ dasel 安裝完成" echo " ✅ dasel 安裝完成"
# 階段 2.2:安裝 resvg從 GitHub 下載二進位檔案) # 階段 2.2:安裝 resvg從 GitHub 下載二進位檔案)
RUN echo "" && \ RUN echo "" && \
echo " 🔧 階段 2.2:安裝 resvg..." && \ echo " 🔧 階段 2.2:安裝 resvg..." && \
ARCH=$(uname -m) && \ ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \ if [ "$ARCH" = "aarch64" ]; then \
echo " ⚠️ resvg 沒有 ARM64 預編譯版本,跳過安裝"; \ echo " ⚠️ resvg 沒有 ARM64 預編譯版本,跳過安裝"; \
else \ else \
curl -sSLf "https://github.com/linebender/resvg/releases/download/v0.44.0/resvg-linux-x86_64.tar.gz" -o /tmp/resvg.tar.gz && \ curl -sSLf "https://github.com/linebender/resvg/releases/download/v0.44.0/resvg-linux-x86_64.tar.gz" -o /tmp/resvg.tar.gz && \
tar -xzf /tmp/resvg.tar.gz -C /tmp/ && \ tar -xzf /tmp/resvg.tar.gz -C /tmp/ && \
mv /tmp/resvg /usr/local/bin/resvg && \ mv /tmp/resvg /usr/local/bin/resvg && \
chmod +x /usr/local/bin/resvg && \ chmod +x /usr/local/bin/resvg && \
rm -rf /tmp/resvg.tar.gz && \ rm -rf /tmp/resvg.tar.gz && \
echo " ✅ resvg 安裝完成"; \ echo " ✅ resvg 安裝完成"; \
fi fi
# 階段 3影音處理工具FFmpeg 精簡版) # 階段 3影音處理工具FFmpeg 精簡版)
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "📦 階段 3/7安裝影音處理工具精簡版" && \ echo "📦 階段 3/7安裝影音處理工具精簡版" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
ffmpeg \ ffmpeg \
&& rm -rf /var/lib/apt/lists/* && \ && rm -rf /var/lib/apt/lists/* && \
echo "✅ 階段 3/7 完成FFmpeg 已安裝" echo "✅ 階段 3/7 完成FFmpeg 已安裝"
# 階段 4Headless 支援LibreOffice 需要) # 階段 4Headless 支援LibreOffice 需要)
# 注意Lite 版移除 Inkscape 和 VIPS 以減少體積 # 注意Lite 版移除 Inkscape 和 VIPS 以減少體積
# GraphicsMagick 已在階段 2 安裝 # GraphicsMagick 已在階段 2 安裝
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "📦 階段 4/6安裝 Headless 支援" && \ echo "📦 階段 4/6安裝 Headless 支援" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
xauth \ xauth \
xvfb \ xvfb \
&& rm -rf /var/lib/apt/lists/* && \ && rm -rf /var/lib/apt/lists/* && \
echo "✅ 階段 4/6 完成Headless 支援已安裝" echo "✅ 階段 4/6 完成Headless 支援已安裝"
# 階段 5文件處理工具Pandoc # 階段 5文件處理工具Pandoc
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "📦 階段 5/6安裝文件處理工具" && \ echo "📦 階段 5/6安裝文件處理工具" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
libemail-outlook-message-perl \ libemail-outlook-message-perl \
pandoc \ pandoc \
&& rm -rf /var/lib/apt/lists/* && \ && rm -rf /var/lib/apt/lists/* && \
echo "✅ 階段 5/6 完成Pandoc 已安裝" echo "✅ 階段 5/6 完成Pandoc 已安裝"
# 階段 6LibreOffice核心文件轉檔引擎 + 基本字型) # 階段 6LibreOffice核心文件轉檔引擎 + 基本字型)
# 使用完整 libreoffice 以確保所有轉檔功能正常 # 使用完整 libreoffice 以確保所有轉檔功能正常
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "📦 階段 6/6安裝 LibreOffice + 字型" && \ echo "📦 階段 6/6安裝 LibreOffice + 字型" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
libreoffice \ libreoffice \
fonts-noto-cjk \ fonts-noto-cjk \
fonts-liberation \ fonts-liberation \
&& rm -rf /var/lib/apt/lists/* && \ && rm -rf /var/lib/apt/lists/* && \
echo "✅ 階段 6/6 完成LibreOffice + 字型已安裝" echo "✅ 階段 6/6 完成LibreOffice + 字型已安裝"
# ============================================================================== # ==============================================================================
# ✅ APT 套件安裝完成 # ✅ APT 套件安裝完成
@ -245,37 +245,41 @@ ENV PDF_SIGN_LOCATION="Taiwan"
ENV PDF_SIGN_CONTACT="convertx-cn@localhost" ENV PDF_SIGN_CONTACT="convertx-cn@localhost"
RUN echo "" && \ RUN echo "" && \
echo "========================================" && \ echo "========================================" && \
echo "🔐 安裝 Python + 產生簽章憑證" && \ echo "🔐 安裝 Python + 產生簽章憑證" && \
echo "========================================" && \ echo "========================================" && \
apt-get update --fix-missing && apt-get install -y --no-install-recommends \ apt-get update --fix-missing && apt-get install -y --no-install-recommends \
python3 \ python3 \
python3-pip \ python3-pip \
&& rm -rf /var/lib/apt/lists/* && \ python3-dev \
pip3 install --no-cache-dir --break-system-packages endesive && \ gcc \
mkdir -p /app/certs && \ libffi-dev \
openssl req -x509 -newkey rsa:2048 \ && rm -rf /var/lib/apt/lists/* && \
-keyout /tmp/key.pem -out /tmp/cert.pem \ pip3 install --no-cache-dir --break-system-packages endesive && \
-days 3650 -nodes \ mkdir -p /app/certs && \
-subj "/CN=PDF Packager Default/O=ConvertX-CN Lite/C=TW" && \ openssl req -x509 -newkey rsa:2048 \
openssl pkcs12 -export \ -keyout /tmp/key.pem -out /tmp/cert.pem \
-inkey /tmp/key.pem -in /tmp/cert.pem \ -days 3650 -nodes \
-out /app/certs/default.p12 \ -subj "/CN=PDF Packager Default/O=ConvertX-CN Lite/C=TW" && \
-passout pass: && \ openssl pkcs12 -export \
rm -f /tmp/key.pem /tmp/cert.pem && \ -inkey /tmp/key.pem -in /tmp/cert.pem \
chmod 644 /app/certs/default.p12 && \ -out /app/certs/default.p12 \
echo "✅ Python + PDF 簽章已安裝" -passout pass: && \
rm -f /tmp/key.pem /tmp/cert.pem && \
chmod 644 /app/certs/default.p12 && \
apt-get purge -y --auto-remove gcc python3-dev libffi-dev && \
echo "✅ Python + PDF 簽章已安裝"
# ============================================================================== # ==============================================================================
# 最終清理 + Locale 設定 + 自訂字型(合併以減少 layer # 最終清理 + Locale 設定 + 自訂字型(合併以減少 layer
# ============================================================================== # ==============================================================================
RUN rm -rf /usr/share/doc/* \ RUN rm -rf /usr/share/doc/* \
&& rm -rf /usr/share/man/* \ && rm -rf /usr/share/man/* \
&& rm -rf /usr/share/info/* \ && rm -rf /usr/share/info/* \
&& sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \ && sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& sed -i 's/# zh_TW.UTF-8 UTF-8/zh_TW.UTF-8 UTF-8/' /etc/locale.gen \ && sed -i 's/# zh_TW.UTF-8 UTF-8/zh_TW.UTF-8 UTF-8/' /etc/locale.gen \
&& sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen \ && sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen \
&& locale-gen && locale-gen
# 安裝自訂字型(標楷體等台灣常用字型) # 安裝自訂字型(標楷體等台灣常用字型)
RUN mkdir -p /usr/share/fonts/truetype/custom RUN mkdir -p /usr/share/fonts/truetype/custom
@ -286,16 +290,16 @@ RUN fc-cache -fv
# Install VTracer binary向量追蹤工具 # Install VTracer binary向量追蹤工具
# ============================================================================== # ==============================================================================
RUN ARCH=$(uname -m) && \ RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \ if [ "$ARCH" = "aarch64" ]; then \
VTRACER_ASSET="vtracer-aarch64-unknown-linux-musl.tar.gz"; \ VTRACER_ASSET="vtracer-aarch64-unknown-linux-musl.tar.gz"; \
else \ else \
VTRACER_ASSET="vtracer-x86_64-unknown-linux-musl.tar.gz"; \ VTRACER_ASSET="vtracer-x86_64-unknown-linux-musl.tar.gz"; \
fi && \ fi && \
curl -L -o /tmp/vtracer.tar.gz "https://github.com/visioncortex/vtracer/releases/download/0.6.4/${VTRACER_ASSET}" && \ curl -L -o /tmp/vtracer.tar.gz "https://github.com/visioncortex/vtracer/releases/download/0.6.4/${VTRACER_ASSET}" && \
tar -xzf /tmp/vtracer.tar.gz -C /tmp/ && \ tar -xzf /tmp/vtracer.tar.gz -C /tmp/ && \
mv /tmp/vtracer /usr/local/bin/vtracer && \ mv /tmp/vtracer /usr/local/bin/vtracer && \
chmod +x /usr/local/bin/vtracer && \ chmod +x /usr/local/bin/vtracer && \
rm /tmp/vtracer.tar.gz rm /tmp/vtracer.tar.gz
COPY --from=install /temp/prod/node_modules node_modules COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /app/public/ /app/public/ COPY --from=prerelease /app/public/ /app/public/