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.
This commit is contained in:
parent
617e724d21
commit
e1e2d6d903
2 changed files with 21 additions and 15 deletions
16
app/main.py
16
app/main.py
|
|
@ -58,6 +58,22 @@ def create_app() -> FastAPI:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Could not load instance config: {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 files
|
||||||
static_dir = Path(__file__).parent / "web" / "static"
|
static_dir = Path(__file__).parent / "web" / "static"
|
||||||
if static_dir.exists():
|
if static_dir.exists():
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,20 @@ services:
|
||||||
app:
|
app:
|
||||||
build: .
|
build: .
|
||||||
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
|
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
environment:
|
environment:
|
||||||
- DATA_DIR=/data
|
- DATA_DIR=/data
|
||||||
- JWT_SECRET_KEY=test-secret-for-ci
|
- JWT_SECRET_KEY=test-secret-for-ci-32chars!!!
|
||||||
- TESTING=true
|
- TESTING=true
|
||||||
|
- SEED_ADMIN_EMAIL=admin@test.com
|
||||||
volumes:
|
volumes:
|
||||||
- test-data:/data
|
- test-data:/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "python", "-c", "import httpx; r=httpx.get('http://localhost:8000/api/health'); exit(0 if r.status_code==200 else 1)"]
|
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
|
interval: 5s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 10
|
retries: 15
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
test-data:
|
test-data:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue