Dockerfile.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Test image for running backend and frontend tests
  2. # syntax=docker/dockerfile:1.7
  3. FROM python:3.13-slim AS backend-test
  4. WORKDIR /app
  5. # Install system dependencies for testing
  6. RUN apt-get update && apt-get install -y --no-install-recommends \
  7. curl \
  8. && rm -rf /var/lib/apt/lists/*
  9. # Install Python dependencies including test dependencies.
  10. # BuildKit cache mount makes subsequent builds re-use the pip download
  11. # cache so the second build only does install work — the slow ~60-90s
  12. # fetch step from the first build becomes ~5s. Requires DOCKER_BUILDKIT=1
  13. # (already set in test_docker.sh).
  14. COPY requirements.txt requirements.lock ./
  15. COPY requirements-dev.txt ./
  16. # Two installs, as in CI: the lock pins the newest ruff (requirements.txt only
  17. # has a floor) and requirements-dev.txt pins the one CI enforces, so a single
  18. # install would have two exact pins for ruff and fail. The second one wins.
  19. RUN --mount=type=cache,target=/root/.cache/pip \
  20. pip install -r requirements.lock && pip install -r requirements-dev.txt
  21. # Copy backend code
  22. COPY backend/ ./backend/
  23. COPY pyproject.toml ./
  24. # Create necessary directories
  25. RUN mkdir -p /app/data /app/logs /app/archive
  26. # Environment variables for testing
  27. ENV PYTHONUNBUFFERED=1
  28. ENV DATA_DIR=/app/data
  29. ENV TESTING=1
  30. # Test image runs pytest and exits — there is no long-running service
  31. # to probe. HEALTHCHECK NONE is the documented Docker opt-out and
  32. # silences Trivy DS-0026 without adding meaningless probe logic.
  33. HEALTHCHECK NONE
  34. # Default command runs pytest (excluding docker integration tests).
  35. # -v dropped: 5300+ "PASSED foo::bar" lines per worker eat noticeable
  36. # stdout I/O time and clutter test_docker.sh output. --tb=short still
  37. # gives full failure tracebacks when something breaks.
  38. # -n auto adapts to the host's vCPU count instead of hard-coding 30 —
  39. # on a 2-vCPU CI / VM runner, -n 30 spawns 30 Python processes fighting
  40. # for 2 cores, which is mostly IPC + import-thrash overhead.
  41. CMD ["pytest", "backend/tests/", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"]
  42. # -------------------------------------------
  43. # Frontend test stage
  44. FROM node:22-bookworm-slim AS frontend-test
  45. WORKDIR /app/frontend
  46. # Copy package files and install
  47. COPY frontend/package*.json ./
  48. RUN npm ci
  49. # Copy frontend source
  50. COPY frontend/ ./
  51. # Default command runs tests
  52. CMD ["npm", "test", "--", "--run"]