Skip to content

Commit

Permalink
Updated Dockerfile, updated to run uvicorn in main
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadam14 committed Jul 29, 2024
1 parent 4df03d7 commit 11515e1
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 173 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ WORKDIR /usr/app

RUN pip install poetry

COPY poetry.lock pyproject.toml alembic.ini ./
COPY --chown=sbl:sbl poetry.lock pyproject.toml alembic.ini README.md ./

RUN poetry config virtualenvs.create false
RUN poetry install --no-root
COPY --chown=sbl:sbl ./src ./src
COPY --chown=sbl:sbl ./db_revisions ./db_revisions

COPY ./src ./src
COPY ./db_revisions ./db_revisions
RUN poetry config virtualenvs.create false
RUN poetry install --only main

WORKDIR /usr/app/src

EXPOSE 8888

USER sbl

CMD ["uvicorn", "regtech_user_fi_management.main:app", "--host", "0.0.0.0", "--port", "8888", "--log-config", "log-config.yml"]
CMD ["python", "regtech_user_fi_management/main.py"]
197 changes: 33 additions & 164 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ env = [
"TOKEN_URL=http://localhost",
"CERTS_URL=http://localhost",
"AUTH_CLIENT=",
"ENV=Test",
]

[tool.black]
Expand Down
3 changes: 2 additions & 1 deletion src/regtech_user_fi_management/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ INST_DB_SCHEMA=public
JWT_OPTS_VERIFY_AT_HASH="false"
JWT_OPTS_VERIFY_AUD="false"
JWT_OPTS_VERIFY_ISS="false"
ADMIN_SCOPES=["query-groups","manage-users"]
ADMIN_SCOPES=["query-groups","manage-users"]
SERVER_CONFIG__RELOAD="true"
15 changes: 14 additions & 1 deletion src/regtech_user_fi_management/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Set
from urllib import parse

from pydantic import field_validator, PostgresDsn, ValidationInfo
from pydantic import field_validator, PostgresDsn, ValidationInfo, BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict

from regtech_api_commons.oauth2.config import KeycloakSettings
Expand All @@ -16,6 +16,17 @@
if os.getenv("ENV", "LOCAL") == "LOCAL":
env_files_to_load.append(".env.local")

class ServerConfig(BaseModel):
host: str = "0.0.0.0"
"""
"workers" and "reload" are mutually exclusive, "workers" flag is ignored when reloading is enabled.
"""
workers: int = 4
reload: bool = False
time_out: int = 65
port: int = 8888
log_config: str = "log-config.yml"


class Settings(BaseSettings):
inst_db_schema: str = "public"
Expand All @@ -27,6 +38,8 @@ class Settings(BaseSettings):
inst_conn: str | None = None
admin_scopes: Set[str] = set(["query-groups", "manage-users"])
db_logging: bool = True

server_config: ServerConfig = ServerConfig()

def __init__(self, **data):
super().__init__(**data)
Expand Down
15 changes: 14 additions & 1 deletion src/regtech_user_fi_management/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from contextlib import asynccontextmanager
import os
import logging
import uvicorn

from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from fastapi.security import OAuth2AuthorizationCodeBearer
Expand All @@ -20,7 +22,7 @@
general_exception_handler,
)

from regtech_user_fi_management.config import kc_settings
from regtech_user_fi_management.config import settings, kc_settings
from regtech_user_fi_management.entities.listeners import setup_dao_listeners
from regtech_user_fi_management.routers import admin_router, institutions_router

Expand Down Expand Up @@ -69,3 +71,14 @@ async def lifespan(app_: FastAPI):

app.include_router(admin_router, prefix="/v1/admin")
app.include_router(institutions_router, prefix="/v1/institutions")

if __name__ == "__main__":
uvicorn.run(
"regtech_user_fi_management.main:app",
host=settings.server_config.host,
port=settings.server_config.port,
timeout_keep_alive=settings.server_config.time_out,
workers=settings.server_config.workers,
reload=settings.server_config.reload,
log_config=settings.server_config.log_config,
)
9 changes: 9 additions & 0 deletions tests/app/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def test_postgres_dsn_building():
}
settings = Settings(**mock_config)
assert str(settings.inst_conn) == "postgresql+asyncpg://user:%5Cz9-%2Ftgb76%23%40@test:5432/test"


def test_default_server_configs():
settings = Settings()
assert settings.server_config.host == "0.0.0.0"
assert settings.server_config.workers == 4
assert settings.server_config.reload is False
assert settings.server_config.time_out == 65
assert settings.server_config.port == 8888

0 comments on commit 11515e1

Please sign in to comment.