-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
115 lines (110 loc) · 4.71 KB
/
docker-compose.yml
File metadata and controls
115 lines (110 loc) · 4.71 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
services:
app:
# Use the container image built in the "development" stage of the Dockerfile.
build: { context: ".", dockerfile: Dockerfile, target: development }
restart: unless-stopped
# Propagate environment variables from the host into the container.
# Note: The `:?` suffix makes it so Docker Compose displays an error if the
# environment variable is either (a) undefined, or (b) empty, in the
# host environment.
# Docs: https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/#additional-information
environment:
MONGO_HOST: mongo
MONGO_PORT: 27017
MONGO_USERNAME: ${MONGO_USERNAME:?}
MONGO_PASSWORD: ${MONGO_PASSWORD:?}
MONGO_DATABASE: ${MONGO_DATABASE:?}
ports:
# Map a host port (by default, 8000, but it can be overridden via an
# environment variable) to port 8000 of the container; the latter being
# the port on which the FastAPI development server listens by default.
#
# The environment variable can be specified either via an `.env` file,
# or by defining it when invoking `docker compose`, like this:
# ```
# $ WEB_PORT=1234 docker compose up
# ```
#
- "${WEB_PORT:-8000}:8000"
volumes:
# Mount the root directory of the repository, at `/app` within the container.
- ".:/app"
# Create an anonymous volume to mask the host's Python virtual environment when mounting.
# That way, the host's Python virtual environment does not interfere with the container's
# and vice versa, and the container does not have to customize `VIRTUAL_ENV`.
# TODO: Consider using this approach for other services that use a Python virtual environment.
# Sharing the `.venv` directory between host and container can be problematic.
- "/app/.venv"
mongo:
image: mongo:8.0.11
ports:
# The environment variable can be specified either via an `.env` file,
# or by defining it when invoking `docker compose`, like this:
# ```
# $ MONGO_PORT=12345 docker compose up
# ```
- "${MONGO_PORT:-27017}:27017"
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: "${MONGO_USERNAME:?}"
MONGO_INITDB_ROOT_PASSWORD: "${MONGO_PASSWORD:?}"
volumes:
- mongo_data:/data/db
ingest:
# Use the same container image as the app service for consistency
build: { context: ".", dockerfile: Dockerfile, target: test }
# This service should not start automatically - only run on demand
profiles: ["tools"]
environment:
# Note: We use `VIRTUAL_ENV` to customize the path at which `uv` looks for and,
# if necessary, creates a Python virtual environment. By using a path
# outside of `/app`, we avoid interfering with—and using—any Python
# virtual environment the host might have created at `/app/.venv`.
# Reference: https://docs.astral.sh/uv/pip/environments/#using-arbitrary-python-environments
VIRTUAL_ENV: /app_venv
volumes:
- ".:/app" # Need to mount current directory to pick up uv install files
- "${INGEST_DATA_PATH:-./tests/data}:/test_data" # to access the test data files
# Ignore the host's `.venv` directory, in an attempt to avoid conflicts.
- "/app/.venv"
depends_on:
- mongo
# Run ingest with data dir mounted to /test_data
command:
- uv
- run
- --active
- python
- /app/src/ingest_data.py
- --mongo-uri
- mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@mongo:27017
- --input
- /test_data
- --schema-path
- ${INGEST_SCHEMA_PATH:-https://raw.githubusercontent.com/ber-data/bertron-schema/main/src/schema/jsonschema/bertron_schema.json}
- ${INGEST_CLEAN}
test:
# Use the same container image as the app service for consistency
build: { context: ".", dockerfile: Dockerfile, target: test }
# This service should not start automatically - only run on demand
profiles: ["tools"]
volumes:
# Mount the root directory to access the ingest script and data files
- ".:/app"
# Ignore the host's `.venv` directory, in an attempt to avoid conflicts.
- "/app/.venv"
environment:
MONGO_HOST: mongo
MONGO_PORT: 27017
MONGO_USERNAME: ${MONGO_USERNAME:?}
MONGO_PASSWORD: ${MONGO_PASSWORD:?}
MONGO_DATABASE: ${MONGO_DATABASE:?} # reminder: the test suite patches this value
VIRTUAL_ENV: /app_venv
depends_on:
- app
- mongo
command: ["uv", "run", "--active", "pytest", "-v"]
volumes:
# Define a named volume that will contain MongoDB data.
# Note: We use this to persist data across container restarts.
mongo_data: {}