Просмотр исходного кода

📦 build(docker): 优化 Docker 镜像构建流程

- 将基础镜像更换为阿里云镜像仓库的版本
- 重构 APT 源配置,清除旧配置并完全禁用 GPG 验证以解决构建问题
- 简化 PostgreSQL 客户端工具的安装步骤
- 调整项目文件复制逻辑,统一复制 packages 目录
- 移除构建过程中不必要的 .npmrc 文件复制
yourname 2 недель назад
Родитель
Сommit
bcc2028b33
1 измененных файлов с 19 добавлено и 18 удалено
  1. 19 18
      Dockerfile

+ 19 - 18
Dockerfile

@@ -1,13 +1,17 @@
-# 使用指定基础镜像
-FROM docker.1ms.run/node:20.19.4
-
-# 设置软件源为清华大学镜像源
-RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free contrib" > /etc/apt/sources.list && \
-    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list && \
-    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main non-free contrib" >> /etc/apt/sources.list && \
-    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main non-free contrib" >> /etc/apt/sources.list
-
-RUN apt update  --fix-missing && \
+FROM registry.cn-beijing.aliyuncs.com/d8dcloud/node:20.19.4-bookworm
+
+# 清除所有现有的APT源配置
+RUN rm -rf /etc/apt/sources.list.d/* && \
+    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
+    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
+    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
+    echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
+# 完全禁用APT的GPG验证
+RUN echo 'APT::Get::AllowUnauthenticated "true";' > /etc/apt/apt.conf.d/99allow-unauthenticated && \
+    echo 'Acquire::AllowInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99allow-unauthenticated && \
+    echo 'Acquire::AllowDowngradeToInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99allow-unauthenticated
+# 现在可以无验证更新和安装
+RUN apt update --fix-missing && \
     apt install -y curl wget
     apt install -y curl wget
 
 
 # 安装 pnpm
 # 安装 pnpm
@@ -17,15 +21,13 @@ RUN npm install -g pnpm
 RUN pnpm config set registry https://registry.npmmirror.com/
 RUN pnpm config set registry https://registry.npmmirror.com/
 RUN pnpm config set @jsr:registry https://npm.jsr.io
 RUN pnpm config set @jsr:registry https://npm.jsr.io
 
 
-# 添加PostgreSQL 17的官方仓库
+# 添加PostgreSQL 17的官方仓库(同样禁用验证)
 RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
 RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
     echo "deb http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list
     echo "deb http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list
 
 
-# 更新包列表并安装PostgreSQL 17客户端工具及其他常用工具(已添加jq)
+# 更新包列表并安装PostgreSQL 17客户端工具
 RUN apt update && \
 RUN apt update && \
-    apt install -y \
-    # PostgreSQL 17客户端工具
-    postgresql-client-17
+    apt install -y postgresql-client-17
 
 
 # 确认版本
 # 确认版本
 RUN pg_dump --version
 RUN pg_dump --version
@@ -37,11 +39,11 @@ WORKDIR /workspace
 ENV BACKUP_DIR=/app/backups-prd/
 ENV BACKUP_DIR=/app/backups-prd/
 
 
 # 复制根目录配置文件
 # 复制根目录配置文件
-COPY package.json pnpm-workspace.yaml pnpm-lock.yaml .npmrc ./
+COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
 
 
 # 复制各项目 package.json
 # 复制各项目 package.json
 COPY web/package.json ./web/
 COPY web/package.json ./web/
-COPY packages/server/package.json ./packages/server/
+COPY packages/ ./packages/
 
 
 # 安装依赖
 # 安装依赖
 RUN pnpm install --frozen-lockfile
 RUN pnpm install --frozen-lockfile
@@ -49,7 +51,6 @@ RUN pnpm install --frozen-lockfile
 # 复制项目文件
 # 复制项目文件
 COPY . .
 COPY . .
 
 
-
 # 构建 web 应用
 # 构建 web 应用
 RUN cd web && pnpm run build
 RUN cd web && pnpm run build