Dockerfile.test 2.2 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. # Embedded GCode viewer assets — required so the @app.get("/gcode-viewer/...")
  22. # packaging-regression test in tests/integration/test_gcode_viewer.py actually
  23. # runs instead of pytest-skipping with "index.html not present". Path matches
  24. # the production Dockerfile (static_dir.parent / "gcode_viewer" = /app/gcode_viewer/).
  25. COPY gcode_viewer/ ./gcode_viewer/
  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. # Default command runs pytest (excluding docker integration tests).
  33. # -v dropped: 5300+ "PASSED foo::bar" lines per worker eat noticeable
  34. # stdout I/O time and clutter test_docker.sh output. --tb=short still
  35. # gives full failure tracebacks when something breaks.
  36. # -n auto adapts to the host's vCPU count instead of hard-coding 30 —
  37. # on a 2-vCPU CI / VM runner, -n 30 spawns 30 Python processes fighting
  38. # for 2 cores, which is mostly IPC + import-thrash overhead.
  39. CMD ["pytest", "backend/tests/", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"]
  40. # -------------------------------------------
  41. # Frontend test stage
  42. FROM node:22-bookworm-slim AS frontend-test
  43. WORKDIR /app/frontend
  44. # Copy package files and install
  45. COPY frontend/package*.json ./
  46. RUN npm ci
  47. # Copy frontend source
  48. COPY frontend/ ./
  49. # Default command runs tests
  50. CMD ["npm", "test", "--", "--run"]