-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile.test
More file actions
150 lines (131 loc) · 4.29 KB
/
Dockerfile.test
File metadata and controls
150 lines (131 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Testing Dockerfile optimized for CI/CD pipelines
# Based on testing patterns from GitHub Actions workflows
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG PYTHON_VERSION=3.11
FROM --platform=$TARGETPLATFORM python:${PYTHON_VERSION}-slim-bookworm AS test-base
# Set environment variables for testing
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DEBIAN_FRONTEND=noninteractive \
TESTING=1 \
LOG_LEVEL=DEBUG \
COVERAGE_CORE=sysmon
# Install system dependencies for testing
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
wget \
ca-certificates \
gnupg2 \
software-properties-common \
valgrind \
strace \
hwloc \
libhwloc-dev \
mesa-opencl-icd \
ocl-icd-opencl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create test user
RUN groupadd -r testuser && \
useradd -r -g testuser -m -s /bin/bash testuser && \
mkdir -p /app && \
chown testuser:testuser /app
WORKDIR /app
# Install Python testing tools
RUN pip install --upgrade pip setuptools wheel
# Install comprehensive testing stack
RUN pip install \
pytest \
pytest-cov \
pytest-xdist \
pytest-mock \
pytest-benchmark \
pytest-timeout \
pytest-html \
pytest-json-report \
pytest-metadata \
pytest-rerunfailures \
pytest-sugar \
pytest-clarity \
pytest-anyio \
pytest-memray \
hypothesis \
factory-boy \
freezegun \
responses \
httpx \
mock \
coverage[toml] \
codecov \
bandit \
safety \
mypy \
flake8 \
black \
isort \
memory-profiler \
line-profiler \
py-spy
# Copy requirements files
COPY requirements*.txt ./
# Install project dependencies
RUN pip install -r requirements.txt || true
RUN pip install -r requirements-dev.txt || true
RUN pip install -r requirements-test.txt || true
# Copy source code
COPY --chown=testuser:testuser . .
# Install package in editable mode
RUN pip install -e ".[dev,test]" || pip install -e .
# Create test directories
RUN mkdir -p \
/app/test-results \
/app/coverage-reports \
/app/benchmark-results \
/app/security-reports \
/app/type-check-reports \
&& chown -R testuser:testuser /app
# Set up coverage configuration
RUN echo '[run]' > .coveragerc && \
echo 'source = ipfs_kit_py' >> .coveragerc && \
echo 'omit = */tests/*, */test_*, setup.py, */migrations/*' >> .coveragerc && \
echo '[report]' >> .coveragerc && \
echo 'exclude_lines = pragma: no cover, def __repr__, raise AssertionError, raise NotImplementedError' >> .coveragerc && \
echo 'show_missing = True' >> .coveragerc && \
echo 'precision = 2' >> .coveragerc
# Switch to test user
USER testuser
# Verify installation
RUN python -c "import ipfs_kit_py; print('Package imported successfully')" || echo "Package import failed - will test installation"
# Health check for testing environment
HEALTHCHECK --interval=30s --timeout=15s --start-period=30s --retries=2 \
CMD python -c "import pytest; import coverage; print('Testing environment OK')" || exit 1
# Default command runs comprehensive test suite
CMD ["pytest", \
"tests/", \
"--verbose", \
"--tb=short", \
"--strict-markers", \
"--strict-config", \
"--cov=ipfs_kit_py", \
"--cov-report=term-missing", \
"--cov-report=html:/app/coverage-reports/", \
"--cov-report=xml:/app/coverage-reports/coverage.xml", \
"--junit-xml=/app/test-results/junit.xml", \
"--json-report", \
"--json-report-file=/app/test-results/report.json", \
"--benchmark-json=/app/benchmark-results/benchmarks.json", \
"--durations=10", \
"--maxfail=5", \
"--timeout=300"]
# Alternative commands for different test types
LABEL test.unit="pytest tests/unit/ --verbose --cov=ipfs_kit_py"
LABEL test.integration="pytest tests/integration/ --verbose --timeout=600"
LABEL test.benchmark="pytest tests/benchmarks/ --benchmark-only"
LABEL test.security="bandit -r ipfs_kit_py/ -f json -o /app/security-reports/bandit.json"
LABEL test.safety="safety check --json --output /app/security-reports/safety.json"
LABEL test.types="mypy ipfs_kit_py/ --html-report /app/type-check-reports/"
LABEL test.style="flake8 ipfs_kit_py/ --format=json --output-file=/app/test-results/flake8.json"