update:
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
FROM python:3.12-slim
|
||||
# Stage 1: Builder
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY main.py config.py docker_ops.py schemas.py config.yaml ./
|
||||
# Simply downloads the pre-compiled wheels from PyPI without needing a compiler
|
||||
RUN pip wheel --no-cache-dir --wheel-dir=/app/wheels -r requirements.txt
|
||||
|
||||
RUN groupadd -g 998 docker || true
|
||||
RUN useradd -m -u 998 -g docker appuser
|
||||
|
||||
# Stage 2: Final Runtime
|
||||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 1. Setup system user first (Cached forever because it doesn't rely on files)
|
||||
RUN groupadd -g 998 docker || true \
|
||||
&& useradd -l -m -u 998 -g docker appuser
|
||||
|
||||
# 2. Bring in the wheels
|
||||
COPY --from=builder /app/wheels /app/wheels
|
||||
|
||||
# 3. Install dependencies (Only runs if requirements.txt changed)
|
||||
RUN pip install --no-cache-dir --no-index --find-links=/app/wheels /app/wheels/*.whl \
|
||||
&& rm -rf /app/wheels
|
||||
|
||||
# 4. Copy code files
|
||||
COPY --chown=appuser:docker main.py config.py docker_ops.py schemas.py config.yaml ./
|
||||
|
||||
USER appuser
|
||||
|
||||
EXPOSE 3333
|
||||
|
||||
CMD ["python", "main.py"]
|
||||
CMD ["python", "main.py"]
|
||||
Reference in New Issue
Block a user