Switch backend Docker image to Alpine multi-stage
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ psql "$DATABASE_URL" -f scripts/init_schema.sql
|
||||
```
|
||||
|
||||
## Docker (VPS / Production)
|
||||
> 目前 Dockerfile 為 Alpine 多階段建置(較小體積)。
|
||||
|
||||
Build image:
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user