forked from bloodworks-io/phlox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.test
More file actions
58 lines (47 loc) · 1.53 KB
/
Copy pathDockerfile.test
File metadata and controls
58 lines (47 loc) · 1.53 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
# Use an official Python runtime as a parent image
FROM python:3.12.2-slim
# 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/*
# First copy requirements to leverage Docker cache
COPY server/requirements.txt /usr/src/app/server/
RUN pip install --no-cache-dir -r server/requirements.txt
RUN pip install --no-cache-dir 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
# Create required directories
RUN mkdir -p /usr/src/app/build /usr/src/app/data
RUN echo "<html><body>Test</body></html>" > /usr/src/app/build/index.html
# 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
RUN chmod +x /usr/src/app/run_tests.sh
# Run tests using the script
ENTRYPOINT ["/usr/src/app/run_tests.sh"]
RUN chmod +x /usr/src/app/run_tests.sh
# Run tests using the script
CMD ["/usr/src/app/run_tests.sh"]