Dockerfile.test 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 30: the test host's worker count. Not -n auto (with psutil installed
  41. # that counts physical cores only, 16) nor -n logical (the Docker host's 32
  42. # CPUs, more than this machine is meant to use).
  43. CMD ["pytest", "backend/tests/", "--tb=short", "-p", "no:cacheprovider", "-n", "30"]
  44. # -------------------------------------------
  45. # Frontend test stage
  46. FROM node:22-bookworm-slim AS frontend-test
  47. WORKDIR /app/frontend
  48. # Copy package files and install
  49. COPY frontend/package*.json ./
  50. RUN npm ci
  51. # Copy frontend source
  52. COPY frontend/ ./
  53. # Default command runs tests
  54. CMD ["npm", "test", "--", "--run"]