FROM python:3.12-slim AS base RUN apt-get update && apt-get install -y --no-install-recommends \ libmagic1 \ postgresql-client \ gnupg \ gzip \ gosu \ tesseract-ocr \ tesseract-ocr-eng \ poppler-utils \ && rm -rf /var/lib/apt/lists/* RUN pip install --no-cache-dir uv WORKDIR /app COPY pyproject.toml ./ FROM base AS deps RUN uv pip install --system --no-cache -e . FROM deps AS test COPY app/ ./app/ COPY alembic/ ./alembic/ COPY alembic.ini ./ COPY tests/ ./tests/ RUN uv pip install --system --no-cache "pytest>=8" "pytest-asyncio>=0.20" "fakeredis[aioredis]" "httpx>=0.27" CMD ["python", "-m", "pytest", "tests/", "-v", "--tb=short"] FROM deps AS production COPY app/ ./app/ COPY alembic/ ./alembic/ COPY alembic.ini ./ COPY scripts/ ./scripts/ RUN useradd -r -s /bin/false -u 1001 appuser \ && chown -R appuser /app \ && mkdir -p /app/uploads /app/backups \ && chown appuser /app/uploads /app/backups COPY scripts/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh EXPOSE 8000 ENTRYPOINT ["/entrypoint.sh"] CMD ["sh", "-c", "python -m alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2 --proxy-headers"]