-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDockerfile.test
More file actions
68 lines (55 loc) · 1.79 KB
/
Dockerfile.test
File metadata and controls
68 lines (55 loc) · 1.79 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
# Use an official Python runtime as a parent image
FROM python:3.12-slim
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set the working directory inside the image
WORKDIR /usr/src/app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create phlox user
RUN useradd -m -u 1000 phlox
# First copy dependency files to leverage Docker cache
COPY server/pyproject.toml server/uv.lock /usr/src/app/server/
# Install Python dependencies
RUN uv pip install --system --no-cache /usr/src/app/server[docker] pytest pytest-asyncio pytest-cov
# Then copy the rest of the application
COPY server/ /usr/src/app/server/
# Set environment variables
ENV PYTHONPATH=/usr/src/app
ENV TESTING=true
ENV DB_ENCRYPTION_KEY=test_key_12345
ENV DOCKER_CONTAINER=true
# Create directories and set ownership
RUN mkdir -p /usr/src/app/build /usr/src/app/data && \
echo "<html><body>Test</body></html>" > /usr/src/app/build/index.html && \
chown -R phlox:phlox /usr/src/app
# Create the run_tests.sh script
RUN echo '#!/bin/bash\n\
# Delete test database if it exists\n\
rm -f /usr/src/app/data/test_phlox_database.sqlite\n\
\n\
PYTHONPATH=/usr/src/app pytest \
--verbose \
--cov=server \
--cov-report=xml \
--cov-report=lcov \
--asyncio-mode=strict \
/usr/src/app/server/tests/\n\
\n\
test_exit_code=$?\n\
\n\
# Delete test database after tests\n\
rm -f /usr/src/app/data/test_phlox_database.sqlite\n\
\n\
exit $test_exit_code' > /usr/src/app/run_tests.sh && \
chmod +x /usr/src/app/run_tests.sh
# Change permissions
RUN chown -R phlox:phlox /usr/src/app
# Switch to phlox user
USER phlox
# Run tests using the script
ENTRYPOINT ["/usr/src/app/run_tests.sh"]
CMD ["/usr/src/app/run_tests.sh"]