-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.test.yml
More file actions
46 lines (44 loc) · 1.55 KB
/
Copy pathdocker-compose.test.yml
File metadata and controls
46 lines (44 loc) · 1.55 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
# docker-compose.test.yml
services:
survey_api_test:
build:
context: ./api
dockerfile: Dockerfile
container_name: survey_api_test
volumes:
- ./api:/root
working_dir: /root
environment:
- MONGO_URL=mongodb://mongodb_test:27019
- DATABASE_NAME=survey_db_test
- SESSION_SECRET_KEY=a_secure_test_secret_for_sessions
depends_on:
- mongodb_test
command: >
sh -c "
echo 'Waiting for MongoDB (mongodb_test:27017 for DB $${DATABASE_NAME}) using mongosh...' &&
# Loop until mongosh can connect and ping the server.
# The --quiet flag suppresses mongosh startup messages.
# The eval script explicitly quits with 0 on success, 1 on failure for the until loop.
# Output is redirected to /dev/null once confirmed working to keep logs clean.
until mongosh mongodb_test:27017/$${DATABASE_NAME} --quiet --eval 'if(db.runCommand({ ping: 1 }).ok) { quit(0); } else { quit(1); }' > /dev/null 2>&1; do
echo 'MongoDB not ready yet... Retrying in 1s.' && sleep 1;
done &&
echo 'MongoDB is ready.' &&
echo 'Running Pytest tests from /root/tests/ ...' &&
pytest -n 0 -vv --color=yes tests/
"
stop_grace_period: 0s
mongodb_test:
image: mongo:latest
container_name: mongodb_test
ports:
- "127.0.0.1:27019:27019"
volumes:
- mongodb_test_data:/data/db
restart: unless-stopped
stop_grace_period: 0s
command: ["mongod", "--port", "27019"]
volumes:
mongodb_test_data:
driver: local