From fc9663d50cfd9792a4993da543fe5ce30ddb7c17 Mon Sep 17 00:00:00 2001 From: Wizerd Date: Thu, 4 Jan 2024 16:35:06 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E5=B0=9D=E8=AF=95=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A4=9A=E5=B9=B3=E5=8F=B0=E9=95=9C=E5=83=8F=E7=9A=84=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-deploy.yml | 4 ++++ Dockerfile | 37 ++++++++++++++++------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker-deploy.yml b/.github/workflows/docker-deploy.yml index ecca836..ca25cb0 100644 --- a/.github/workflows/docker-deploy.yml +++ b/.github/workflows/docker-deploy.yml @@ -44,3 +44,7 @@ jobs: wizerd/pandora-to-api:${{ steps.tag_name.outputs.tag }} wizerd/pandora-to-api:latest platforms: linux/amd64,linux/arm64,linux/arm/v7 + build-args: | + TARGETPLATFORM=linux/amd64 + TARGETPLATFORM=linux/arm64 + TARGETPLATFORM=linux/arm/v7 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 455ac37..82ca47d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,35 @@ -# 使用官方 Python 运行时作为父镜像 -FROM python:3.9-slim +# 基础阶段,适用于所有平台 +FROM python:3.9-slim AS base -# 设置工作目录为 /app WORKDIR /app -# 将当前目录内容复制到位于 /app 的容器中 COPY . /app -# 设置环境变量 ENV PYTHONUNBUFFERED=1 RUN chmod +x /app/start.sh -RUN apt update && apt install -y \ - jq \ - zlib1g-dev \ - libjpeg-dev \ - gcc \ - curl \ - && curl https://sh.rustup.rs -sSf | sh -s -- -y +RUN apt update && apt install -y jq -# 安装 Rust 编译器 -ENV PATH="/root/.cargo/bin:${PATH}" - -# 设置 pip 源为清华大学镜像 RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple -# 安装任何所需的依赖项 +# 针对 linux/amd64 和 linux/arm64 的阶段 +FROM base AS amd64_arm64 + +# 针对 linux/arm/v7 的阶段 +FROM base AS armv7 + +RUN apt install -y zlib1g-dev libjpeg-dev gcc curl + +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y + +ENV PATH="/root/.cargo/bin:${PATH}" + +# 最终阶段,根据构建的平台选择正确的阶段 +# 注意:这里的平台名称要与 buildx 的 --platform 参数一致 +FROM ${TARGETPLATFORM} IN (linux/amd64, linux/arm64) ? amd64_arm64 : armv7 + +# 安装通用的 Python 依赖 RUN pip install --no-cache-dir flask gunicorn requests Pillow flask-cors tiktoken # 在容器启动时运行 Flask 应用