From d7ec82ca0a548c1b07850ea85c0fcf0c28d14938 Mon Sep 17 00:00:00 2001 From: grillazz Date: Mon, 19 Apr 2021 13:04:37 +0200 Subject: [PATCH] docker improvements --- .secrets | 1 + docker-compose.yml | 5 +++-- the_app/config.py | 2 +- the_app/database.py | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .secrets diff --git a/.secrets b/.secrets new file mode 100644 index 0000000..cea6783 --- /dev/null +++ b/.secrets @@ -0,0 +1 @@ +POSTGRES_PASSWORD=secret diff --git a/docker-compose.yml b/docker-compose.yml index ffd2153..6494598 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: build: . env_file: - .env + - .secrets command: bash -c " uvicorn the_app.main:app --host 0.0.0.0 --port 8080 @@ -27,15 +28,15 @@ services: - postgres_data:/var/lib/postgresql/data env_file: - .env + - .secrets ports: - 5432:5432 environment: - POSTGRES_USER=${SQL_USER} - - POSTGRES_PASSWORD=${SQL_PASS} healthcheck: test: [ - "CMD-SHELL", "pg_isready -d $POSTGRES_DB -U $POSTGRES_USER" + "CMD-SHELL", "pg_isready -d $SQL_DB -U $SQL_USER" ] interval: 5s timeout: 5s diff --git a/the_app/config.py b/the_app/config.py index 466cfed..3c9526c 100644 --- a/the_app/config.py +++ b/the_app/config.py @@ -27,7 +27,7 @@ class Settings(BaseSettings): """ pg_user: str = os.getenv("SQL_USER", "") - pg_pass: str = os.getenv("SQL_PASS", "") + pg_pass: str = os.getenv("POSTGRES_PASSWORD", "") pg_host: str = os.getenv("SQL_HOST", "") pg_database: str = os.getenv("SQL_DB", "") pg_test_database: str = os.getenv("SQL_TEST_DB", "") diff --git a/the_app/database.py b/the_app/database.py index 4476436..635209c 100644 --- a/the_app/database.py +++ b/the_app/database.py @@ -1,4 +1,5 @@ -from typing import Generator +from typing import AsyncGenerator + from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker @@ -19,7 +20,7 @@ async_session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession # Dependency -async def get_db() -> Generator: +async def get_db() -> AsyncGenerator: session = async_session() try: yield session