Dockerfile.test 2.5 KB

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