From ade60bdbaa7adefdb19056bc4224445af6b4964d Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 3 Apr 2026 03:12:19 +0800 Subject: [PATCH] Switch backend Docker image to Alpine multi-stage --- Dockerfile | 23 +++++++++++++++++------ README.md | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 09af022..fa5dc09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,29 @@ -FROM python:3.12-slim - -ENV PYTHONDONTWRITEBYTECODE=1 \ - PYTHONUNBUFFERED=1 +FROM python:3.12-alpine AS builder WORKDIR /app -# Install runtime dependencies from local package metadata. +RUN apk add --no-cache build-base libffi-dev openssl-dev cargo + COPY pyproject.toml /app/pyproject.toml COPY app /app/app COPY scripts /app/scripts COPY README.md /app/README.md RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir . + pip wheel --no-cache-dir --wheel-dir /wheels . + +FROM python:3.12-alpine + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +RUN apk add --no-cache libstdc++ libffi openssl + +COPY --from=builder /wheels /wheels +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir /wheels/* EXPOSE 8000 diff --git a/README.md b/README.md index 671ed23..b0a35b9 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ psql "$DATABASE_URL" -f scripts/init_schema.sql ``` ## Docker (VPS / Production) +> 目前 Dockerfile 為 Alpine 多階段建置(較小體積)。 Build image: ```bash