Skip to content

Commit 31e9b5a

Browse files
committed
feat: split compose into multiple files
1 parent 6437d3b commit 31e9b5a

27 files changed

+494
-247
lines changed

src/pytest_databases/docker/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import subprocess # noqa: S404
3030
import sys
3131
import timeit
32-
from pathlib import Path
3332
from typing import TYPE_CHECKING, Any, Callable
3433

3534
import pytest
@@ -38,6 +37,7 @@
3837

3938
if TYPE_CHECKING:
4039
from collections.abc import Awaitable, Generator
40+
from pathlib import Path
4141

4242

4343
async def wait_until_responsive(
@@ -76,9 +76,9 @@ def __init__(self, worker_id: str, compose_project_name: str = COMPOSE_PROJECT_N
7676
self._running_services: set[str] = set()
7777
self.docker_ip = self._get_docker_ip()
7878
self._base_command = ["docker-compose"] if USE_LEGACY_DOCKER_COMPOSE else ["docker", "compose"]
79+
self._compose_files: list[str] = []
7980
self._base_command.extend(
8081
[
81-
f"--file={Path(__file__).parent / 'docker-compose.yml'}",
8282
f"--project-name={compose_project_name}-{worker_id}",
8383
],
8484
)
@@ -96,12 +96,13 @@ def _get_docker_ip() -> str:
9696
raise ValueError(msg)
9797

9898
def run_command(self, *args: str) -> None:
99-
command = [*self._base_command, *args]
99+
command = [*self._base_command, *self._compose_files, *args]
100100
subprocess.run(command, check=True, capture_output=True)
101101

102102
async def start(
103103
self,
104104
name: str,
105+
docker_compose_files: list[Path],
105106
*,
106107
check: Callable[..., Any],
107108
timeout: float = 30,
@@ -111,6 +112,7 @@ async def start(
111112
if SKIP_DOCKER_COMPOSE:
112113
self._running_services.add(name)
113114
if name not in self._running_services:
115+
self._compose_files = [f"--file={compose_file}" for compose_file in docker_compose_files]
114116
self.run_command("up", "--force-recreate", "-d", name)
115117
self._running_services.add(name)
116118

src/pytest_databases/docker/cockroachdb.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from __future__ import annotations
2424

2525
import os
26+
from pathlib import Path
2627
from typing import TYPE_CHECKING
2728

2829
import psycopg
@@ -58,17 +59,30 @@ def cockroachdb_driver_opts() -> dict[str, str]:
5859
return {"sslmode": "disable"}
5960

6061

62+
@pytest.fixture(scope="session")
63+
def docker_compose_files() -> list[Path]:
64+
return [Path(Path(__file__).parent / "docker-compose.cockroachdb.yml")]
65+
66+
67+
@pytest.fixture(scope="session")
68+
def default_cockroachdb_service_name() -> str:
69+
return "cockroachdb"
70+
71+
6172
@pytest.fixture(autouse=False)
6273
async def cockroachdb_service(
6374
docker_services: DockerServiceRegistry,
75+
default_cockroachdb_service_name: str,
76+
docker_compose_files: list[Path],
6477
cockroachdb_port: int,
6578
cockroachdb_database: str,
6679
cockroachdb_driver_opts: dict[str, str],
6780
) -> None:
6881
os.environ["COCKROACHDB_DATABASE"] = cockroachdb_database
6982
os.environ["COCKROACHDB_PORT"] = str(cockroachdb_port)
7083
await docker_services.start(
71-
"cockroachdb",
84+
name=default_cockroachdb_service_name,
85+
docker_compose_files=docker_compose_files,
7286
timeout=60,
7387
pause=1,
7488
check=cockroachdb_responsive,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
cockroachdb:
3+
image: cockroachdb/cockroach:latest-v23.1
4+
command: start-single-node --insecure
5+
restart: "no"
6+
expose:
7+
- "8080"
8+
- "${COCKROACHDB_PORT:-26257}"
9+
ports:
10+
- "${COCKROACHDB_PORT:-26257}:26257"
11+
- "8880:8080"
12+
healthcheck:
13+
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
14+
interval: 3s
15+
timeout: 3s
16+
retries: 5
17+
networks:
18+
default:
19+
driver: bridge
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
dragonfly:
3+
image: "docker.dragonflydb.io/dragonflydb/dragonfly"
4+
ulimits:
5+
memlock: -1
6+
ports:
7+
- "${DRAGONFLY_PORT:-6398}:6379"
8+
# For better performance, consider `host` mode instead `port` to avoid docker NAT.
9+
# `host` mode is NOT currently supported in Swarm Mode.
10+
# https://docs.docker.com/compose/compose-file/compose-file-v3/#network_mode
11+
# network_mode: "host"
12+
volumes:
13+
- dragonflydata:/data
14+
networks:
15+
default:
16+
driver: bridge
17+
volumes:
18+
dragonflydata:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
elasticsearch7:
3+
image: elasticsearch:7.17.19
4+
ports:
5+
- 9200:9200
6+
- 9301:9300
7+
environment:
8+
- discovery.type=single-node
9+
- xpack.security.enabled=false
10+
healthcheck:
11+
test: curl -s http://localhost:9200 >/dev/null || exit 1
12+
interval: 30s
13+
timeout: 10s
14+
retries: 50
15+
elasticsearch8:
16+
image: elasticsearch:8.13.0
17+
ports:
18+
- 9201:9200
19+
- 9300:9300
20+
environment:
21+
- discovery.type=single-node
22+
- xpack.security.enabled=false
23+
healthcheck:
24+
test: curl -s http://localhost:9200 >/dev/null || exit 1
25+
interval: 30s
26+
timeout: 10s
27+
retries: 50
28+
networks:
29+
default:
30+
driver: bridge
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
keydb:
3+
image: eqalpha/keydb
4+
ports:
5+
- "${KEYDB_PORT:-6396}:6379"
6+
networks:
7+
default:
8+
driver: bridge
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
mariadb113:
3+
networks:
4+
- default
5+
image: mariadb:11.3
6+
ports:
7+
- "${MARIADB113_PORT:-3359}:3306" # use a non-standard port here
8+
environment:
9+
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-super-secret}
10+
MARIADB_PASSWORD: ${MARIADB_PASSWORD:-super-secret}
11+
MARIADB_USER: ${MARIADB_USER:-app}
12+
MARIADB_DATABASE: ${MARIADB_DATABASE:-db}
13+
MARIADB_ROOT_HOST: "%"
14+
LANG: C.UTF-8
15+
networks:
16+
default:
17+
driver: bridge
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
mssql2022:
3+
networks:
4+
- default
5+
image: mcr.microsoft.com/mssql/server:2022-latest
6+
ports:
7+
- "${MSSQL2022_PORT:-4133}:1433" # use a non-standard port here
8+
environment:
9+
SA_PASSWORD: ${MSSQL_PASSWORD:-Super-secret1}
10+
MSSQL_PID: Developer
11+
ACCEPT_EULA: Accepted
12+
MSSQL_TCP_PORT: 1433
13+
networks:
14+
default:
15+
driver: bridge
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
mysql8:
3+
networks:
4+
- default
5+
image: mysql:latest
6+
ports:
7+
- "${MYSQL8_PORT:-3360}:3306" # use a non-standard port here
8+
environment:
9+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-super-secret}
10+
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-super-secret}
11+
MYSQL_USER: ${MYSQL_USER:-app}
12+
MYSQL_DATABASE: ${MYSQL_DATABASE:-db}
13+
MYSQL_ROOT_HOST: "%"
14+
LANG: C.UTF-8
15+
mysql57:
16+
networks:
17+
- default
18+
image: mysql:5.7
19+
ports:
20+
- "${MYSQL57_PORT:-3362}:3306" # use a non-standard port here
21+
environment:
22+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-super-secret}
23+
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-super-secret}
24+
MYSQL_USER: ${MYSQL_USER:-app}
25+
MYSQL_DATABASE: ${MYSQL_DATABASE:-db}
26+
MYSQL_ROOT_HOST: "%"
27+
LANG: C.UTF-8
28+
mysql56:
29+
networks:
30+
- default
31+
image: mysql:5.6
32+
ports:
33+
- "${MYSQL56_PORT:-3363}:3306" # use a non-standard port here
34+
environment:
35+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-super-secret}
36+
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-super-secret}
37+
MYSQL_USER: ${MYSQL_USER:-app}
38+
MYSQL_DATABASE: ${MYSQL_DATABASE:-db}
39+
MYSQL_ROOT_HOST: "%"
40+
LANG: C.UTF-8
41+
networks:
42+
default:
43+
driver: bridge
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
oracle18c:
3+
networks:
4+
- default
5+
image: gvenzl/oracle-xe:18-slim-faststart
6+
ports:
7+
- "${ORACLE18C_PORT:-1514}:1521" # use a non-standard port here
8+
environment:
9+
ORACLE_PASSWORD: ${ORACLE_SYSTEM_PASSWORD:-super-secret}
10+
APP_USER_PASSWORD: ${ORACLE_PASSWORD:-super-secret}
11+
APP_USER: ${ORACLE_USER:-app}
12+
oracle23c:
13+
networks:
14+
- default
15+
image: gvenzl/oracle-free:23-slim-faststart
16+
ports:
17+
- "${ORACLE23C_PORT:-1513}:1521" # use a non-standard port here
18+
environment:
19+
ORACLE_PASSWORD: ${ORACLE_SYSTEM_PASSWORD:-super-secret}
20+
APP_USER_PASSWORD: ${ORACLE_PASSWORD:-super-secret}
21+
APP_USER: ${ORACLE_USER:-app}
22+
networks:
23+
default:
24+
driver: bridge

0 commit comments

Comments
 (0)