This commit is contained in:
jinql
2025-09-01 23:38:52 +08:00
parent 4236de43a9
commit a5290c5e03
4 changed files with 52 additions and 12 deletions

View File

@@ -1,16 +1,33 @@
FROM python:3.12-slim
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
COPY . .
RUN python -m compileall -b .
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt .
RUN pip install --no-cache /wheels/*
COPY --from=builder /app /app
RUN find . -type d -name "__pycache__" | while read -r dir; do \
module_dir=$(dirname "$dir"); \
mv "$dir"/*.pyc "$module_dir/"; \
rmdir "$dir"; \
done
RUN find . -name "*.py" -delete
EXPOSE 8000
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# CMD ["gunicorn", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000", "main:app"]
CMD ["gunicorn", "--config", "gunicorn.conf.py", "main:app"]
CMD ["gunicorn", "--config", "gunicorn.conf.pyc", "main:app"]