Dockerfile.test 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ./
  15. COPY requirements-dev.txt ./
  16. RUN --mount=type=cache,target=/root/.cache/pip \
  17. pip install -r requirements.txt -r requirements-dev.txt
  18. # Copy backend code
  19. COPY backend/ ./backend/
  20. COPY pyproject.toml ./
  21. # Create necessary directories
  22. RUN mkdir -p /app/data /app/logs /app/archive
  23. # Environment variables for testing
  24. ENV PYTHONUNBUFFERED=1
  25. ENV DATA_DIR=/app/data
  26. ENV TESTING=1
  27. # Test image runs pytest and exits — there is no long-running service
  28. # to probe. HEALTHCHECK NONE is the documented Docker opt-out and
  29. # silences Trivy DS-0026 without adding meaningless probe logic.
  30. HEALTHCHECK NONE
  31. # Default command runs pytest (excluding docker integration tests).
  32. # -v dropped: 5300+ "PASSED foo::bar" lines per worker eat noticeable
  33. # stdout I/O time and clutter test_docker.sh output. --tb=short still
  34. # gives full failure tracebacks when something breaks.
  35. # -n auto adapts to the host's vCPU count instead of hard-coding 30 —
  36. # on a 2-vCPU CI / VM runner, -n 30 spawns 30 Python processes fighting
  37. # for 2 cores, which is mostly IPC + import-thrash overhead.
  38. CMD ["pytest", "backend/tests/", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"]
  39. # -------------------------------------------
  40. # Frontend test stage
  41. FROM node:22-bookworm-slim AS frontend-test
  42. WORKDIR /app/frontend
  43. # Copy package files and install
  44. COPY frontend/package*.json ./
  45. RUN npm ci
  46. # Copy frontend source
  47. COPY frontend/ ./
  48. # Default command runs tests
  49. CMD ["npm", "test", "--", "--run"]