build: add docker-compose test stack with ephemeral postgres
This commit is contained in:
parent
6da6dcd33a
commit
c215b8e45f
@ -10,6 +10,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
COPY src/ src/
|
||||
COPY alembic/ alembic/
|
||||
COPY alembic.ini .
|
||||
COPY README.md .
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync --frozen --no-dev
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
||||
|
||||
WORKDIR /app
|
||||
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
|
||||
ENV PATH="/app/.venv/bin:$PATH"
|
||||
|
||||
COPY pyproject.toml uv.lock ./
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
@ -11,6 +12,7 @@ COPY src/ src/
|
||||
COPY tests/ tests/
|
||||
COPY alembic/ alembic/
|
||||
COPY alembic.ini .
|
||||
COPY README.md .
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync --frozen
|
||||
|
||||
|
||||
26
docker-compose.test.yml
Normal file
26
docker-compose.test.yml
Normal file
@ -0,0 +1,26 @@
|
||||
services:
|
||||
postgres:
|
||||
tmpfs: /var/lib/postgresql/data
|
||||
ports: []
|
||||
volumes: []
|
||||
|
||||
redis:
|
||||
ports: []
|
||||
|
||||
test:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.test
|
||||
command: >
|
||||
sh -c "alembic upgrade head &&
|
||||
pytest tests/ -x -v --tb=short --timeout=30"
|
||||
environment:
|
||||
DB_URL: "postgresql+asyncpg://proxypool:proxypool@postgres:5432/proxypool"
|
||||
REDIS_URL: "redis://redis:6379/1"
|
||||
SECRET_KEY: "test-secret-key"
|
||||
LOG_LEVEL: "WARNING"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
@ -40,8 +40,6 @@ services:
|
||||
POSTGRES_PASSWORD: proxypool
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U proxypool"]
|
||||
interval: 2s
|
||||
@ -56,7 +54,4 @@ services:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 2s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
volumes:
|
||||
pg_data:
|
||||
retries: 10
|
||||
@ -17,11 +17,19 @@ def event_loop():
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def test_settings() -> Settings:
|
||||
import os
|
||||
return Settings(
|
||||
secret_key="test-secret",
|
||||
log_level="DEBUG",
|
||||
db=DatabaseSettings(url="postgresql+asyncpg://proxypool:proxypool@localhost:5432/proxypool"),
|
||||
redis=RedisSettings(url="redis://localhost:6379"),
|
||||
secret_key=os.environ.get("SECRET_KEY", "test-secret"),
|
||||
log_level=os.environ.get("LOG_LEVEL", "DEBUG"),
|
||||
db=DatabaseSettings(
|
||||
url=os.environ.get(
|
||||
"DB_URL",
|
||||
"postgresql+asyncpg://proxypool:proxypool@localhost:5432/proxypool",
|
||||
),
|
||||
),
|
||||
redis=RedisSettings(
|
||||
url=os.environ.get("REDIS_URL", "redis://localhost:6379/1"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user