Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove the named bridge adapter in docker-compose #5

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/db.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import sys
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from typing import Annotated

from fastapi import Depends
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlmodel import text
from sqlmodel.ext.asyncio.session import AsyncSession

from app import settings
Expand All @@ -25,3 +27,11 @@ async def get_db_session() -> AsyncIterator[AsyncSession]:


DBSession = Annotated[AsyncSession, Depends(get_db_session)]


async def verify_db_connection():
async with asynccontextmanager(get_db_session)() as session:
result = await session.exec(text("SELECT 1"))

if result.one()[0] != 1:
raise Exception("Could not verify database connection")
14 changes: 14 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import logging
from contextlib import asynccontextmanager

import fastapi_pagination
from fastapi import FastAPI

from app import settings
from app.db import verify_db_connection
from app.routers import entitlements

logger = logging.getLogger(__name__)


@asynccontextmanager
async def lifespan(app: FastAPI):
await verify_db_connection()
yield


tags_metadata = [
{
"name": "Entitlements",
Expand All @@ -18,6 +31,7 @@
openapi_tags=tags_metadata,
root_path="/v1",
debug=settings.debug,
lifespan=lifespan,
)

fastapi_pagination.add_pagination(app)
Expand Down
12 changes: 0 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
networks:
docker_network:
driver: bridge

services:
app:
build:
context: .
dockerfile: dev.Dockerfile
working_dir: /app
restart: always
networks:
- docker_network
depends_on:
db:
condition: "service_healthy"
Expand All @@ -29,12 +23,8 @@ services:
POSTGRES_DB: "${FFC_OPERATIONS_POSTGRES_DB}"
POSTGRES_USER: "${FFC_OPERATIONS_POSTGRES_USER}"
POSTGRES_PASSWORD: "${FFC_OPERATIONS_POSTGRES_PASSWORD}"
POSTGRES_HOST: "${FFC_OPERATIONS_POSTGRES_HOST}"
POSTGRES_PORT: "${FFC_OPERATIONS_POSTGRES_PORT}"
ports:
- "${FFC_OPERATIONS_POSTGRES_PORT}:5432"
networks:
- docker_network
healthcheck:
test: ["CMD-SHELL", "pg_isready --dbname=$${POSTGRES_DB} --username=$${POSTRGRES_USER}"]
interval: 10s
Expand All @@ -48,8 +38,6 @@ services:
depends_on:
db:
condition: "service_healthy"
networks:
- docker_network
command: >
bash -c "
set -e
Expand Down
Loading