diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4afc5ff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim +LABEL maintainer="Dmitry Titenkov " +LABEL version="1.0" +LABEL description="API for miniCRM" +RUN mkdir /app +COPY requirements.txt /app +RUN pip3 install -r /app/requirements.txt --no-cache-dir -vvv +COPY . /app +WORKDIR /app +CMD [ "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload" ] \ No newline at end of file diff --git a/app/core/config.py b/app/core/config.py index 28f5690..98ce597 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -11,8 +11,10 @@ class Settings(BaseSettings): first_superuser_password: str | None = None first_superuser_role: str | None = None - class Config: - env_file = ".env" + model_config = { + "env_file": ".env", + "extra": "ignore", + } settings = Settings() diff --git a/app/main.py b/app/main.py index 7825a6e..fed0052 100644 --- a/app/main.py +++ b/app/main.py @@ -1,11 +1,9 @@ import logging from contextlib import asynccontextmanager -import uvicorn from fastapi import FastAPI from app.core.config import settings -from app.core.init_db import create_first_superuser from app.core.logging import setup_logging from app.routers.clients import client_router from app.routers.comments import comment_router @@ -20,7 +18,6 @@ @asynccontextmanager async def lifespan(app: FastAPI): logging.info("Приложение miniCRM запущено") - await create_first_superuser() yield logging.info("Приложение miniCRM остановлено") @@ -31,7 +28,3 @@ async def lifespan(app: FastAPI): app.include_router(client_router) app.include_router(deal_router) app.include_router(comment_router) - - -if __name__ == "__main__": - uvicorn.run("app.main:app", reload=True) diff --git a/create_superuser.py b/create_superuser.py new file mode 100644 index 0000000..1373de8 --- /dev/null +++ b/create_superuser.py @@ -0,0 +1,11 @@ +import asyncio + +from app.core.init_db import create_first_superuser + + +async def main(): + await create_first_superuser() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5476eef --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + db: + image: postgres:15.0-alpine + volumes: + - postgres_data:/var/lib/postgresql/data/ + ports: + - "5432:5432" + env_file: + - ./.env + backend: + build: . + restart: always + depends_on: + - db + env_file: + - ./.env + ports: + - "8000:8000" + command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload + +volumes: + postgres_data: