Switch backend Docker image to Alpine multi-stage

This commit is contained in:
Chris
2026-04-03 03:12:19 +08:00
parent 75cf22f7e5
commit ade60bdbaa
2 changed files with 18 additions and 6 deletions

View File

@@ -1,18 +1,29 @@
FROM python:3.12-slim FROM python:3.12-alpine AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app 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 pyproject.toml /app/pyproject.toml
COPY app /app/app COPY app /app/app
COPY scripts /app/scripts COPY scripts /app/scripts
COPY README.md /app/README.md COPY README.md /app/README.md
RUN pip install --no-cache-dir --upgrade pip && \ 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 EXPOSE 8000

View File

@@ -13,6 +13,7 @@ psql "$DATABASE_URL" -f scripts/init_schema.sql
``` ```
## Docker (VPS / Production) ## Docker (VPS / Production)
> 目前 Dockerfile 為 Alpine 多階段建置(較小體積)。
Build image: Build image:
```bash ```bash