From e1e2d6d9039d4aa7e02f5fe2371a0ba6968ed8c9 Mon Sep 17 00:00:00 2001 From: ZdenekSrotyr Date: Tue, 31 Mar 2026 09:48:12 +0200 Subject: [PATCH] feat: add SEED_ADMIN_EMAIL for Docker test environments app/main.py: seed admin user on startup when SEED_ADMIN_EMAIL is set. docker-compose.test.yml: expose port 8000, add seed env var. --- app/main.py | 16 ++++++++++++++++ docker-compose.test.yml | 20 +++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/main.py b/app/main.py index 025dbcb..b529a0d 100644 --- a/app/main.py +++ b/app/main.py @@ -58,6 +58,22 @@ def create_app() -> FastAPI: except Exception as e: logger.warning(f"Could not load instance config: {e}") + # Seed admin user for testing/CI (when SEED_ADMIN_EMAIL is set) + seed_email = os.environ.get("SEED_ADMIN_EMAIL") + if seed_email: + try: + from src.db import get_system_db + from src.repositories.users import UserRepository + conn = get_system_db() + repo = UserRepository(conn) + if not repo.get_by_email(seed_email): + import uuid + repo.create(id=str(uuid.uuid4()), email=seed_email, name="Admin", role="admin") + logger.info("Seeded admin user: %s", seed_email) + conn.close() + except Exception as e: + logger.warning(f"Could not seed admin: {e}") + # Static files static_dir = Path(__file__).parent / "web" / "static" if static_dir.exists(): diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c66f97b..d916a75 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -2,30 +2,20 @@ services: app: build: . command: uvicorn app.main:app --host 0.0.0.0 --port 8000 + ports: + - "8000:8000" environment: - DATA_DIR=/data - - JWT_SECRET_KEY=test-secret-for-ci + - JWT_SECRET_KEY=test-secret-for-ci-32chars!!! - TESTING=true + - SEED_ADMIN_EMAIL=admin@test.com volumes: - test-data:/data healthcheck: test: ["CMD", "python", "-c", "import httpx; r=httpx.get('http://localhost:8000/api/health'); exit(0 if r.status_code==200 else 1)"] interval: 5s timeout: 3s - retries: 10 - - test-runner: - build: . - command: python -m pytest tests/test_db.py tests/test_repositories.py tests/test_migration.py tests/test_api.py -v - environment: - - DATA_DIR=/data - - JWT_SECRET_KEY=test-secret-for-ci - - API_URL=http://app:8000 - volumes: - - test-data:/data - depends_on: - app: - condition: service_healthy + retries: 15 volumes: test-data: