This commit is contained in:
2025-06-15 20:12:48 +08:00
parent 3f1c7250bd
commit 8a2fa11afc

View File

@@ -1,36 +1,58 @@
# 构建阶段
FROM python:3.12.2-alpine AS builder
FROM python:3.12.2-slim AS builder
ARG TARGETARCH
ARG TARGETVARIANT
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
# 使用中科大源加速
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
WORKDIR /build
COPY ./deploy/requirements.txt /build/
RUN --mount=type=cache,target=/etc/apk/cache,id=apk-cahce-$TARGETARCH$TARGETVARIANT-builder \
--mount=type=cache,target=/root/.cache/pip,id=pip-cahce-$TARGETARCH$TARGETVARIANT-builder \
RUN --mount=type=cache,target=/var/cache/apt,id=apt-cache-$TARGETARCH$TARGETVARIANT-builder \
--mount=type=cache,target=/root/.cache/pip,id=pip-cache-$TARGETARCH$TARGETVARIANT-builder \
<<EOS
set -ex
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
apk add gcc libc-dev python3-dev libpq-dev libjpeg-turbo-dev zlib-dev freetype-dev
pip install --no-cache-dir -r requirements.txt
apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
python3-dev \
libpq-dev \
libjpeg-dev \
zlib1g-dev \
libfreetype6-dev && \
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple && \
pip install --no-cache-dir -r requirements.txt && \
apt-get purge -y gcc python3-dev && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
EOS
# 运行阶段
FROM python:3.12.2-alpine
FROM python:3.12.2-slim
ARG TARGETARCH
ARG TARGETVARIANT
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
ENV OJ_ENV production
WORKDIR /app
RUN --mount=type=cache,target=/etc/apk/cache,id=apk-cahce-$TARGETARCH$TARGETVARIANT-final \
RUN --mount=type=cache,target=/var/cache/apt,id=apt-cache-$TARGETARCH$TARGETVARIANT-final \
<<EOS
set -ex
apk add --no-cache libpq libjpeg-turbo zlib freetype supervisor openssl nginx curl unzip
apt-get update && \
apt-get install -y --no-install-recommends \
libpq5 \
libjpeg62-turbo \
zlib1g \
libfreetype6 \
supervisor \
openssl \
nginx \
curl \
unzip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
EOS
COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/