[fix] 尝试优化多平台镜像的镜像大小

This commit is contained in:
Wizerd
2024-01-04 16:35:06 +08:00
parent 68f48afb69
commit fc9663d50c
2 changed files with 24 additions and 17 deletions

View File

@@ -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

View File

@@ -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 应用